Trim savegame names

This commit is contained in:
tobspr 2020-09-19 18:32:39 +02:00
parent 1cd52f6dbd
commit d0aa6db630
1 changed files with 4 additions and 2 deletions

View File

@ -17,6 +17,8 @@ import { getApplicationSettingById } from "../profile/application_settings";
import { FormElementInput } from "../core/modal_dialog_forms"; import { FormElementInput } from "../core/modal_dialog_forms";
import { DialogWithForm } from "../core/modal_dialog_elements"; import { DialogWithForm } from "../core/modal_dialog_elements";
const trim = require("trim");
/** /**
* @typedef {import("../savegame/savegame_typedefs").SavegameMetadata} SavegameMetadata * @typedef {import("../savegame/savegame_typedefs").SavegameMetadata} SavegameMetadata
* @typedef {import("../profile/setting_types").EnumSetting} EnumSetting * @typedef {import("../profile/setting_types").EnumSetting} EnumSetting
@ -436,7 +438,7 @@ export class MainMenuState extends GameState {
label: null, label: null,
placeholder: "", placeholder: "",
defaultValue: game.name || "", defaultValue: game.name || "",
validator: val => val.match(regex), validator: val => val.match(regex) && trim(val).length > 0,
}); });
const dialog = new DialogWithForm({ const dialog = new DialogWithForm({
app: this.app, app: this.app,
@ -449,7 +451,7 @@ export class MainMenuState extends GameState {
// When confirmed, save the name // When confirmed, save the name
dialog.buttonSignals.ok.add(() => { dialog.buttonSignals.ok.add(() => {
game.name = nameInput.getValue(); game.name = trim(nameInput.getValue());
this.app.savegameMgr.writeAsync(); this.app.savegameMgr.writeAsync();
this.renderSavegames(); this.renderSavegames();
}); });