From 672cc49e146bbed718211cf1187eceae1673f77d Mon Sep 17 00:00:00 2001 From: Anna Date: Sun, 21 Nov 2021 01:38:36 -0500 Subject: [PATCH] fix: make sure only valid keys are in plates --- Glamaholic/Configuration.cs | 11 +++++++++++ Glamaholic/Ui/Helpers/ExamineHelper.cs | 2 +- Glamaholic/Ui/MainInterface.cs | 6 +++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Glamaholic/Configuration.cs b/Glamaholic/Configuration.cs index cc2f1ae..2430284 100755 --- a/Glamaholic/Configuration.cs +++ b/Glamaholic/Configuration.cs @@ -11,6 +11,17 @@ namespace Glamaholic { public List Plates { get; init; } = new(); public bool ShowEditorMenu = true; public bool ShowExamineMenu = true; + + internal void AddPlate(SavedPlate plate) { + var valid = Enum.GetValues(); + foreach (var slot in plate.Items.Keys.ToArray()) { + if (!valid.Contains(slot)) { + plate.Items.Remove(slot); + } + } + + this.Plates.Add(plate); + } } [Serializable] diff --git a/Glamaholic/Ui/Helpers/ExamineHelper.cs b/Glamaholic/Ui/Helpers/ExamineHelper.cs index 8836ca3..5730270 100755 --- a/Glamaholic/Ui/Helpers/ExamineHelper.cs +++ b/Glamaholic/Ui/Helpers/ExamineHelper.cs @@ -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); diff --git a/Glamaholic/Ui/MainInterface.cs b/Glamaholic/Ui/MainInterface.cs index f9c36f7..ccc932f 100755 --- a/Glamaholic/Ui/MainInterface.cs +++ b/Glamaholic/Ui/MainInterface.cs @@ -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(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) {