fixed merge conflict

This commit is contained in:
FreezeDriedMangoes 2022-06-27 17:21:33 -04:00
commit 63383ef6d3
4 changed files with 408 additions and 396 deletions

View File

@ -446,15 +446,15 @@ namespace NewHorizons
if (!foundFile) Logger.LogWarning($"{mod.ModHelper.Manifest.Name} has a folder for translations but none were loaded"); if (!foundFile) Logger.LogWarning($"{mod.ModHelper.Manifest.Name} has a folder for translations but none were loaded");
} }
public NewHorizonsBody LoadConfig(IModBehaviour mod, string relativeDirectory) public NewHorizonsBody LoadConfig(IModBehaviour mod, string relativePath)
{ {
NewHorizonsBody body = null; NewHorizonsBody body = null;
try try
{ {
var config = mod.ModHelper.Storage.Load<PlanetConfig>(relativeDirectory); var config = mod.ModHelper.Storage.Load<PlanetConfig>(relativePath);
if (config == null) if (config == null)
{ {
Logger.LogError($"Couldn't load {relativeDirectory}. Is your Json formatted correctly?"); Logger.LogError($"Couldn't load {relativePath}. Is your Json formatted correctly?");
return null; return null;
} }
@ -479,11 +479,11 @@ namespace NewHorizons
// Has to happen after we make sure theres a system config // Has to happen after we make sure theres a system config
config.MigrateAndValidate(); config.MigrateAndValidate();
body = new NewHorizonsBody(config, mod, relativeDirectory); body = new NewHorizonsBody(config, mod, relativePath);
} }
catch (Exception e) catch (Exception e)
{ {
Logger.LogError($"Error encounter when loading {relativeDirectory}: {e.Message} {e.StackTrace}"); Logger.LogError($"Error encounter when loading {relativePath}: {e.Message} {e.StackTrace}");
} }
return body; return body;

View File

@ -28,17 +28,16 @@ namespace NewHorizons.Utility.DebugMenu
static bool openMenuOnPause; static bool openMenuOnPause;
static bool staticInitialized; static bool staticInitialized;
// menu params // Menu params
internal static IModBehaviour loadedMod = null; internal static IModBehaviour loadedMod = null;
internal Dictionary<string, PlanetConfig> loadedConfigFiles = new Dictionary<string, PlanetConfig>(); internal Dictionary<string, PlanetConfig> loadedConfigFiles = new Dictionary<string, PlanetConfig>();
private bool saveButtonUnlocked = false; private bool saveButtonUnlocked = false;
private Vector2 recentModListScrollPosition = Vector2.zero; private Vector2 recentModListScrollPosition = Vector2.zero;
// submenus // Submenus
private List<DebugSubmenu> submenus; private List<DebugSubmenu> submenus;
private int activeSubmenu = 0; private int activeSubmenu = 0;
private static JsonSerializerSettings jsonSettings = new JsonSerializerSettings private static JsonSerializerSettings jsonSettings = new JsonSerializerSettings
{ {
NullValueHandling = NullValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore,
@ -55,7 +54,6 @@ namespace NewHorizons.Utility.DebugMenu
new DebugMenuNomaiText() new DebugMenuNomaiText()
}; };
submenus.ForEach((submenu) => submenu.OnAwake(this)); submenus.ForEach((submenu) => submenu.OnAwake(this));
} }
@ -89,6 +87,7 @@ namespace NewHorizons.Utility.DebugMenu
pauseMenuButton = Main.Instance.ModHelper.Menus.PauseMenu.OptionsButton.Duplicate(TranslationHandler.GetTranslation("Toggle Dev Tools Menu", TranslationHandler.TextType.UI).ToUpper()); pauseMenuButton = Main.Instance.ModHelper.Menus.PauseMenu.OptionsButton.Duplicate(TranslationHandler.GetTranslation("Toggle Dev Tools Menu", TranslationHandler.TextType.UI).ToUpper());
InitMenu(); InitMenu();
} }
public static void UpdatePauseMenuButton() public static void UpdatePauseMenuButton()
{ {
if (pauseMenuButton != null) if (pauseMenuButton != null)
@ -99,11 +98,11 @@ namespace NewHorizons.Utility.DebugMenu
} }
private void RestoreMenuOpennessState() { menuOpen = openMenuOnPause; } private void RestoreMenuOpennessState() { menuOpen = openMenuOnPause; }
private void ToggleMenu() { menuOpen = !menuOpen; openMenuOnPause = !openMenuOnPause; } private void ToggleMenu() { menuOpen = !menuOpen; openMenuOnPause = !openMenuOnPause; }
private void CloseMenu() { menuOpen = false; } private void CloseMenu() { menuOpen = false; }
private void OnGUI() private void OnGUI()
{ {
if (!menuOpen) return; if (!menuOpen) return;
@ -113,8 +112,7 @@ namespace NewHorizons.Utility.DebugMenu
GUILayout.BeginArea(new Rect(menuPosition.x, menuPosition.y, EditorMenuSize.x, EditorMenuSize.y), _editorMenuStyle); GUILayout.BeginArea(new Rect(menuPosition.x, menuPosition.y, EditorMenuSize.x, EditorMenuSize.y), _editorMenuStyle);
// continue working on existing mod // Continue working on existing mod
GUILayout.Label("Name of your mod"); GUILayout.Label("Name of your mod");
if (loadedMod == null) if (loadedMod == null)
{ {
@ -138,9 +136,9 @@ namespace NewHorizons.Utility.DebugMenu
GUILayout.Space(5); GUILayout.Space(5);
// save your work // Save your work
if (loadedMod != null)
if (loadedMod != null) { {
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
if (GUILayout.Button(saveButtonUnlocked ? " O " : " | ", GUILayout.ExpandWidth(false))) if (GUILayout.Button(saveButtonUnlocked ? " O " : " | ", GUILayout.ExpandWidth(false)))
{ {
@ -158,7 +156,7 @@ namespace NewHorizons.Utility.DebugMenu
GUILayout.Space(20); GUILayout.Space(20);
// draw submenu stuff // Draw submenu stuff
if (loadedMod != null) if (loadedMod != null)
{ {
GUILayout.BeginHorizontal(_tabBarStyle); GUILayout.BeginHorizontal(_tabBarStyle);
@ -187,7 +185,6 @@ namespace NewHorizons.Utility.DebugMenu
GUILayout.EndVertical(); GUILayout.EndVertical();
} }
GUILayout.EndArea(); GUILayout.EndArea();
} }
@ -198,15 +195,16 @@ namespace NewHorizons.Utility.DebugMenu
var folder = loadedMod.ModHelper.Manifest.ModFolderPath; var folder = loadedMod.ModHelper.Manifest.ModFolderPath;
List<NewHorizonsBody> bodiesForThisMod = Main.BodyDict.Values.SelectMany(x => x).Where(x => x.Mod == loadedMod).ToList(); var bodiesForThisMod = Main.BodyDict.Values.SelectMany(x => x).Where(x => x.Mod == loadedMod).ToList();
foreach (NewHorizonsBody body in bodiesForThisMod) foreach (var body in bodiesForThisMod)
{ {
if (body.RelativePath == null) if (body.RelativePath == null)
{ {
Logger.Log("Error loading config for " + body.Config.name + " in " + body.Config.starSystem); Logger.Log($"Error loading config for {body.Config.name} in {body.Config.starSystem}");
continue;
} }
loadedConfigFiles[folder + body.RelativePath] = (body.Config as PlanetConfig); loadedConfigFiles[folder + body.RelativePath] = body.Config;
submenus.ForEach(submenu => submenu.LoadConfigFile(this, body.Config)); submenus.ForEach(submenu => submenu.LoadConfigFile(this, body.Config));
} }
} }
@ -215,12 +213,14 @@ namespace NewHorizons.Utility.DebugMenu
{ {
submenus.ForEach(submenu => submenu.PreSave(this)); submenus.ForEach(submenu => submenu.PreSave(this));
string backupFolderName = "configBackups\\" + DateTime.Now.ToString("yyyyMMddTHHmmss") + "\\"; var backupFolderName = $"configBackups\\{DateTime.Now.ToString("yyyyMMddTHHmmss")}\\";
Logger.Log($"Potentially saving {loadedConfigFiles.Keys.Count} files"); Logger.Log($"Potentially saving {loadedConfigFiles.Keys.Count} files");
foreach (var filePath in loadedConfigFiles.Keys) foreach (var filePath in loadedConfigFiles.Keys)
{ {
Logger.Log("Possibly Saving... " + loadedConfigFiles[filePath].name + " @ " + filePath); Logger.Log($"Possibly Saving... {loadedConfigFiles[filePath].name} @ {filePath}");
if (loadedConfigFiles[filePath].starSystem != Main.Instance.CurrentStarSystem) continue; if (loadedConfigFiles[filePath].starSystem != Main.Instance.CurrentStarSystem) continue;
var relativePath = filePath.Replace(loadedMod.ModHelper.Manifest.ModFolderPath, ""); var relativePath = filePath.Replace(loadedMod.ModHelper.Manifest.ModFolderPath, "");
@ -231,14 +231,17 @@ namespace NewHorizons.Utility.DebugMenu
try try
{ {
Logger.Log("Saving... " + relativePath + " to " + filePath); Logger.Log($"Saving... {relativePath} to {filePath}");
var path = loadedMod.ModHelper.Manifest.ModFolderPath + relativePath; var path = loadedMod.ModHelper.Manifest.ModFolderPath + relativePath;
var directoryName = Path.GetDirectoryName(path); var directoryName = Path.GetDirectoryName(path);
Directory.CreateDirectory(directoryName); Directory.CreateDirectory(directoryName);
File.WriteAllText(path, json); File.WriteAllText(path, json);
} }
catch (Exception e) { Logger.LogError("Failed to save file " + backupFolderName + relativePath); Logger.LogError(e.Message + "\n" + e.StackTrace); } catch (Exception e)
{
Logger.LogError($"Failed to save file {relativePath}:\n{e.Message}\n{e.StackTrace}");
}
try try
{ {
@ -248,7 +251,10 @@ namespace NewHorizons.Utility.DebugMenu
File.WriteAllText(path, json); File.WriteAllText(path, json);
} }
catch (Exception e) { Logger.LogError("Failed to save backup file " + backupFolderName + relativePath); Logger.LogError(e.Message + "\n" + e.StackTrace); } catch (Exception e)
{
Logger.LogError($"Failed to save backup file {backupFolderName}{relativePath}:\n{e.Message}\n{e.StackTrace}");
}
} }
} }
@ -263,7 +269,6 @@ namespace NewHorizons.Utility.DebugMenu
submenus.ForEach(submenu => submenu.OnInit(this)); submenus.ForEach(submenu => submenu.OnInit(this));
_editorMenuStyle = new GUIStyle _editorMenuStyle = new GUIStyle
{ {
normal = normal =

View File

@ -226,6 +226,7 @@ namespace NewHorizons.Utility.DebugMenu
if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) deltaX -= dx; if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) deltaX -= dx;
dx = float.Parse(GUILayout.TextField(dx + "", GUILayout.Width(100))); dx = float.Parse(GUILayout.TextField(dx + "", GUILayout.Width(100)));
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
// y // y
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
GUILayout.Label(labelY + ": ", GUILayout.Width(50)); GUILayout.Label(labelY + ": ", GUILayout.Width(50));
@ -237,6 +238,7 @@ namespace NewHorizons.Utility.DebugMenu
if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) deltaY -= dy; if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) deltaY -= dy;
dy = float.Parse(GUILayout.TextField(dy + "", GUILayout.Width(100))); dy = float.Parse(GUILayout.TextField(dy + "", GUILayout.Width(100)));
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
// z // z
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
GUILayout.Label(labelZ + ": ", GUILayout.Width(50)); GUILayout.Label(labelZ + ": ", GUILayout.Width(50));
@ -301,29 +303,34 @@ namespace NewHorizons.Utility.DebugMenu
{ {
var newDetails = _dpp.GetPropsConfigByBody(); var newDetails = _dpp.GetPropsConfigByBody();
Logger.Log("Updating config files. New Details Counts by planet: " + string.Join(", ", newDetails.Keys.Select(x => $"{x.name} ({newDetails[x].Length})"))); var newDetailsCountsByPlanet = string.Join(", ", newDetails.Keys.Select(x => $"{x.name} ({newDetails[x].Length})"));
Logger.Log($"Updating config files. New Details Counts by planet: {newDetailsCountsByPlanet}");
Dictionary<AstroObject, string> planetToConfigPath = new Dictionary<AstroObject, string>(); var planetToConfigPath = new Dictionary<AstroObject, string>();
// Get all configs // Get all configs
foreach (var filePath in menu.loadedConfigFiles.Keys) foreach (var filePath in menu.loadedConfigFiles.Keys)
{ {
Logger.Log("potentially updating copy of config at " + filePath); Logger.Log($"Potentially updating copy of config at {filePath}");
Logger.Log($"{menu.loadedConfigFiles[filePath].name} {AstroObjectLocator.GetAstroObject(menu.loadedConfigFiles[filePath].name)?.name}"); Logger.Log($"{menu.loadedConfigFiles[filePath].name} {AstroObjectLocator.GetAstroObject(menu.loadedConfigFiles[filePath].name)?.name}");
Logger.Log($"{menu.loadedConfigFiles[filePath]}") ; Logger.Log($"{menu.loadedConfigFiles[filePath].name}");
if (menu.loadedConfigFiles[filePath].starSystem != Main.Instance.CurrentStarSystem) return; if (menu.loadedConfigFiles[filePath].starSystem != Main.Instance.CurrentStarSystem) return;
if (menu.loadedConfigFiles[filePath].name == null || AstroObjectLocator.GetAstroObject(menu.loadedConfigFiles[filePath].name) == null) { Logger.Log("Failed to update copy of config at " + filePath); continue; } if (menu.loadedConfigFiles[filePath].name == null || AstroObjectLocator.GetAstroObject(menu.loadedConfigFiles[filePath].name) == null)
{
Logger.Log("Failed to update copy of config at " + filePath);
continue;
}
var astroObject = AstroObjectLocator.GetAstroObject(menu.loadedConfigFiles[filePath].name); var astroObject = AstroObjectLocator.GetAstroObject(menu.loadedConfigFiles[filePath].name);
planetToConfigPath[astroObject] = filePath; planetToConfigPath[astroObject] = filePath;
if (!newDetails.ContainsKey(astroObject)) continue; if (!newDetails.ContainsKey(astroObject)) continue;
if (menu.loadedConfigFiles[filePath].Props == null) menu.loadedConfigFiles[filePath].Props = new External.Modules.PropModule(); if (menu.loadedConfigFiles[filePath].Props == null) menu.loadedConfigFiles[filePath].Props = new PropModule();
menu.loadedConfigFiles[filePath].Props.details = newDetails[astroObject]; menu.loadedConfigFiles[filePath].Props.details = newDetails[astroObject];
Logger.Log($"successfully updated copy of config file for {astroObject.name}"); Logger.Log($"Successfully updated copy of config file for {astroObject.name}");
} }
// find all new planets that do not yet have config paths // find all new planets that do not yet have config paths
@ -332,14 +339,15 @@ namespace NewHorizons.Utility.DebugMenu
{ {
Logger.Log("Fabricating new config file for " + astroObject.name); Logger.Log("Fabricating new config file for " + astroObject.name);
var filepath = "planets/" + Main.Instance.CurrentStarSystem + "/" + astroObject.name + ".json"; var filepath = $"planets/{Main.Instance.CurrentStarSystem}/{astroObject.name}.json";
PlanetConfig c = new PlanetConfig();
c.starSystem = Main.Instance.CurrentStarSystem;
c.name = astroObject._name == AstroObject.Name.CustomString ? astroObject.GetCustomName() : astroObject._name.ToString();
c.Props = new PropModule();
c.Props.details = newDetails[astroObject];
menu.loadedConfigFiles[filepath] = c; var config = new PlanetConfig();
config.starSystem = Main.Instance.CurrentStarSystem;
config.name = astroObject._name == AstroObject.Name.CustomString ? astroObject.GetCustomName() : astroObject._name.ToString();
config.Props = new PropModule();
config.Props.details = newDetails[astroObject];
menu.loadedConfigFiles[filepath] = config;
} }
} }
} }

View File

@ -196,7 +196,6 @@ namespace NewHorizons.Utility.DebugUtilities
// TOOD: make this prop an item // TOOD: make this prop an item
} }
//var body = AstroObjectLocator.GetAstroObject(bodyGameObjectName); //var body = AstroObjectLocator.GetAstroObject(bodyGameObjectName);
Logger.Log($"Adding prop to {Main.Instance.CurrentStarSystem}::{body.name}"); Logger.Log($"Adding prop to {Main.Instance.CurrentStarSystem}::{body.name}");