Skip to content

Commit

Permalink
ModSettings export jsons buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Aug 27, 2021
1 parent 8970ecb commit 425b59a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 8 deletions.
1 change: 0 additions & 1 deletion BTD Mod Helper Core/Api/Towers/ModTowerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ internal static TowerModel CreateTowerModel(ModTower modTower, int[] tiers)
}
}

//FileIOUtil.SaveObject($"Towers\\{towerModel.name}.json", towerModel);
return towerModel;
}

Expand Down
2 changes: 0 additions & 2 deletions BTD Mod Helper Core/Api/Towers/ModUpgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions BTD Mod Helper Core/ModHelperData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
public static class ModHelperData
{
public const string currentVersion = "2.0.4";

public const string currentVersion = "2.0.5";
}
}
78 changes: 75 additions & 3 deletions BloonsTD6 Mod Helper/MelonMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 425b59a

Please sign in to comment.