diff --git a/BTD Mod Helper Core/Api/Towers/ModTowerHandler.cs b/BTD Mod Helper Core/Api/Towers/ModTowerHandler.cs index 7061c248e..36fc25ca5 100644 --- a/BTD Mod Helper Core/Api/Towers/ModTowerHandler.cs +++ b/BTD Mod Helper Core/Api/Towers/ModTowerHandler.cs @@ -241,7 +241,6 @@ internal static TowerModel CreateTowerModel(ModTower modTower, int[] tiers) } } - //FileIOUtil.SaveObject($"Towers\\{towerModel.name}.json", towerModel); return towerModel; } diff --git a/BTD Mod Helper Core/Api/Towers/ModUpgrade.cs b/BTD Mod Helper Core/Api/Towers/ModUpgrade.cs index 65e45d47f..75daaa743 100644 --- a/BTD Mod Helper Core/Api/Towers/ModUpgrade.cs +++ b/BTD Mod Helper Core/Api/Towers/ModUpgrade.cs @@ -117,8 +117,6 @@ public virtual UpgradeModel GetUpgradeModel() { upgradeModel = new UpgradeModel(Id, Cost, 0, IconReference ?? DefaultIcon, Path, Tier - 1, 0, "", ""); - - FileIOUtil.SaveObject($"Upgrades\\{upgradeModel.name}.json", upgradeModel); } return upgradeModel; diff --git a/BTD Mod Helper Core/ModHelperData.cs b/BTD Mod Helper Core/ModHelperData.cs index 3b9262056..65beb59c0 100644 --- a/BTD Mod Helper Core/ModHelperData.cs +++ b/BTD Mod Helper Core/ModHelperData.cs @@ -2,7 +2,6 @@ { public static class ModHelperData { - public const string currentVersion = "2.0.4"; - + public const string currentVersion = "2.0.5"; } } diff --git a/BloonsTD6 Mod Helper/MelonMain.cs b/BloonsTD6 Mod Helper/MelonMain.cs index 95eb9396d..1b80cd9b0 100644 --- a/BloonsTD6 Mod Helper/MelonMain.cs +++ b/BloonsTD6 Mod Helper/MelonMain.cs @@ -65,11 +65,23 @@ public override void OnGameModelLoaded(GameModel model) */ } - public override void OnMainMenu() + private static ModSettingBool OpenLocalDirectory = new ModSettingBool(false) { - AutoSave.InitAutosave(this.GetModSettingsDir(true)); - } + displayName = "Open Local Files Directory", + IsButton = true + }; + private static ModSettingBool ExportTowerJSONs = new ModSettingBool(false) + { + displayName = "Export Tower JSONs", + IsButton = true + }; + + private static ModSettingBool ExportUpgradeJSONs = new ModSettingBool(false) + { + displayName = "Export Upgrade JSONs", + IsButton = true + }; internal static ShowModOptions_Button modsButton; @@ -131,6 +143,66 @@ public override void OnTitleScreen() if (!scheduledInGamePatch) Schedule_InGame_Loaded(); + + AutoSave.InitAutosave(this.GetModSettingsDir(true)); + + OpenLocalDirectory.OnInitialized.Add(option => + { + var buttonOption = (ButtonOption)option; + buttonOption.ButtonText.text = "Open"; + buttonOption.Button.AddOnClick(() => Process.Start(FileIOUtil.sandboxRoot)); + }); + + ExportTowerJSONs.OnInitialized.Add(option => + { + var buttonOption = (ButtonOption)option; + buttonOption.ButtonText.text = "Export"; + buttonOption.Button.AddOnClick(() => + { + MelonLogger.Msg("Dumping Towers to local files"); + foreach (var tower in Game.instance.model.towers) + { + var path = "Towers/" + tower.baseId + "/" + tower.name + ".json"; + try + { + FileIOUtil.SaveObject(path, tower); + MelonLogger.Msg("Saving " + FileIOUtil.sandboxRoot + path); + } + catch (Exception) + { + MelonLogger.Error("Failed to save " + FileIOUtil.sandboxRoot + path); + } + } + + PopupScreen.instance.ShowOkPopup($"Finished exporting towers to {FileIOUtil.sandboxRoot + "Towers"}"); + }); + }); + + ExportUpgradeJSONs.OnInitialized.Add(option => + { + var buttonOption = (ButtonOption)option; + buttonOption.ButtonText.text = "Export"; + buttonOption.Button.AddOnClick(() => + { + MelonLogger.Msg("Exporting Upgrades to local files"); + foreach (var upgrade in Game.instance.model.upgrades) + { + var path = "Upgrades/" + upgrade.name + ".json"; + try + { + FileIOUtil.SaveObject(path, upgrade); + MelonLogger.Msg("Saving " + FileIOUtil.sandboxRoot + path); + } + catch (Exception) + { + MelonLogger.Error("Failed to save " + FileIOUtil.sandboxRoot + path); + } + } + + PopupScreen.instance.ShowOkPopup( + $"Finished exporting upgrades to {FileIOUtil.sandboxRoot + "Upgrades"}"); + }); + }); } private void Schedule_GameModel_Loaded()