fix: make sure only valid keys are in plates

This commit is contained in:
Anna 2021-11-21 01:38:36 -05:00
parent 9fe71f20aa
commit 672cc49e14
3 changed files with 15 additions and 4 deletions

View File

@ -11,6 +11,17 @@ namespace Glamaholic {
public List<SavedPlate> Plates { get; init; } = new();
public bool ShowEditorMenu = true;
public bool ShowExamineMenu = true;
internal void AddPlate(SavedPlate plate) {
var valid = Enum.GetValues<PlateSlot>();
foreach (var slot in plate.Items.Keys.ToArray()) {
if (!valid.Contains(slot)) {
plate.Items.Remove(slot);
}
}
this.Plates.Add(plate);
}
}
[Serializable]

View File

@ -71,7 +71,7 @@ namespace Glamaholic.Ui.Helpers {
};
}
this.Ui.Plugin.Config.Plates.Add(plate);
this.Ui.Plugin.Config.AddPlate(plate);
this.Ui.Plugin.SaveConfig();
this.Ui.OpenMainInterface();
this.Ui.SwitchPlate(this.Ui.Plugin.Config.Plates.Count - 1, true);

View File

@ -96,7 +96,7 @@ namespace Glamaholic.Ui {
if (ImGui.BeginMenu("Plates")) {
if (ImGui.MenuItem("New")) {
this.Ui.Plugin.Config.Plates.Add(new SavedPlate("Untitled Plate"));
this.Ui.Plugin.Config.AddPlate(new SavedPlate("Untitled Plate"));
this.Ui.Plugin.SaveConfig();
this.SwitchPlate(this.Ui.Plugin.Config.Plates.Count - 1, true);
}
@ -109,7 +109,7 @@ namespace Glamaholic.Ui {
Items = current,
};
this.Ui.Plugin.Config.Plates.Add(plate);
this.Ui.Plugin.Config.AddPlate(plate);
this._plateName = string.Empty;
this.Ui.Plugin.SaveConfig();
@ -129,7 +129,7 @@ namespace Glamaholic.Ui {
var plate = JsonConvert.DeserializeObject<SavedPlate>(this._importInput);
this._importError = null;
if (plate != null) {
this.Ui.Plugin.Config.Plates.Add(plate);
this.Ui.Plugin.Config.AddPlate(plate);
this.Ui.Plugin.SaveConfig();
}
} catch (Exception ex) {