fix: make sure only valid keys are in plates
This commit is contained in:
parent
9fe71f20aa
commit
672cc49e14
|
@ -11,6 +11,17 @@ namespace Glamaholic {
|
||||||
public List<SavedPlate> Plates { get; init; } = new();
|
public List<SavedPlate> Plates { get; init; } = new();
|
||||||
public bool ShowEditorMenu = true;
|
public bool ShowEditorMenu = true;
|
||||||
public bool ShowExamineMenu = 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]
|
[Serializable]
|
||||||
|
|
|
@ -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.Plugin.SaveConfig();
|
||||||
this.Ui.OpenMainInterface();
|
this.Ui.OpenMainInterface();
|
||||||
this.Ui.SwitchPlate(this.Ui.Plugin.Config.Plates.Count - 1, true);
|
this.Ui.SwitchPlate(this.Ui.Plugin.Config.Plates.Count - 1, true);
|
||||||
|
|
|
@ -96,7 +96,7 @@ namespace Glamaholic.Ui {
|
||||||
|
|
||||||
if (ImGui.BeginMenu("Plates")) {
|
if (ImGui.BeginMenu("Plates")) {
|
||||||
if (ImGui.MenuItem("New")) {
|
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.Ui.Plugin.SaveConfig();
|
||||||
this.SwitchPlate(this.Ui.Plugin.Config.Plates.Count - 1, true);
|
this.SwitchPlate(this.Ui.Plugin.Config.Plates.Count - 1, true);
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ namespace Glamaholic.Ui {
|
||||||
Items = current,
|
Items = current,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Ui.Plugin.Config.Plates.Add(plate);
|
this.Ui.Plugin.Config.AddPlate(plate);
|
||||||
|
|
||||||
this._plateName = string.Empty;
|
this._plateName = string.Empty;
|
||||||
this.Ui.Plugin.SaveConfig();
|
this.Ui.Plugin.SaveConfig();
|
||||||
|
@ -129,7 +129,7 @@ namespace Glamaholic.Ui {
|
||||||
var plate = JsonConvert.DeserializeObject<SavedPlate>(this._importInput);
|
var plate = JsonConvert.DeserializeObject<SavedPlate>(this._importInput);
|
||||||
this._importError = null;
|
this._importError = null;
|
||||||
if (plate != null) {
|
if (plate != null) {
|
||||||
this.Ui.Plugin.Config.Plates.Add(plate);
|
this.Ui.Plugin.Config.AddPlate(plate);
|
||||||
this.Ui.Plugin.SaveConfig();
|
this.Ui.Plugin.SaveConfig();
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
Loading…
Reference in New Issue