From f0ac3a0573125215353aec3dcf0e6bb320d057e5 Mon Sep 17 00:00:00 2001 From: Ben C Date: Sun, 27 Mar 2022 15:11:42 -0400 Subject: [PATCH 01/10] Made newly revealed facts stored in NewHorizonsData --- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 12 +++--- NewHorizons/External/NewHorizonsData.cs | 39 +++++++++++++++++-- NewHorizons/Handlers/ShipLogHandler.cs | 24 +++++++++--- NewHorizons/Tools/Patches.cs | 34 ++++++++++++++++ NewHorizons/Tools/ShipLogPatches.cs | 1 + 5 files changed, 95 insertions(+), 15 deletions(-) diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index 3a4bcdfe..03eb27d2 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -305,15 +305,15 @@ namespace NewHorizons.Builder.ShipLog public List children; public MapModeObject parent; public MapModeObject lastSibling; - public void Increment_width() + public void IncrementWidth() { branch_width++; - parent?.Increment_width(); + parent?.IncrementWidth(); } - public void Increment_height() + public void IncrementHeight() { branch_height++; - parent?.Increment_height(); + parent?.IncrementHeight(); } } @@ -416,12 +416,12 @@ namespace NewHorizons.Builder.ShipLog if (even) { newY += newNode.branch_height; - parent.Increment_height(); + parent.IncrementHeight(); } else { newX += newNode.branch_width; - parent.Increment_width(); + parent.IncrementWidth(); } lastSibling = newNode; diff --git a/NewHorizons/External/NewHorizonsData.cs b/NewHorizons/External/NewHorizonsData.cs index db7a96fa..124729b2 100644 --- a/NewHorizons/External/NewHorizonsData.cs +++ b/NewHorizons/External/NewHorizonsData.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using NewHorizons.Handlers; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.External @@ -59,12 +60,14 @@ namespace NewHorizons.External { Load(); } - Logger.Log($"Reseting save data for {_activeProfileName}"); + Logger.Log($"Resetting save data for {_activeProfileName}"); _activeProfile = new NewHorizonsProfile(); _saveFile.Profiles[_activeProfileName] = _activeProfile; Save(); } + + # region Frequencies public static bool KnowsFrequency(string frequency) { @@ -81,7 +84,16 @@ namespace NewHorizons.External Save(); } } + + public static bool KnowsMultipleFrequencies() + { + return (_activeProfile != null && _activeProfile.KnownFrequencies.Count > 0); + } + + # endregion + # region Signals + public static bool KnowsSignal(string signal) { if (_activeProfile == null) return true; @@ -97,12 +109,30 @@ namespace NewHorizons.External Save(); } } + + # endregion + + # region Newly Revealed Facts - public static bool KnowsMultipleFrequencies() + public static void AddNewlyRevealedFactID(string id) { - return (_activeProfile != null && _activeProfile.KnownFrequencies.Count > 0); + _activeProfile?.NewlyRevealedFactIDs.Add(id); + Save(); } + public static List GetNewlyRevealedFactIDs() + { + return _activeProfile?.NewlyRevealedFactIDs; + } + + public static void ClearNewlyRevealedFactIDs() + { + _activeProfile?.NewlyRevealedFactIDs.Clear(); + Save(); + } + + # endregion + private class NewHorizonsSaveFile { public NewHorizonsSaveFile() @@ -119,10 +149,13 @@ namespace NewHorizons.External { KnownFrequencies = new List(); KnownSignals = new List(); + NewlyRevealedFactIDs = new List(); } public List KnownFrequencies { get; set; } public List KnownSignals { get; set; } + + public List NewlyRevealedFactIDs { get; set; } } } } diff --git a/NewHorizons/Handlers/ShipLogHandler.cs b/NewHorizons/Handlers/ShipLogHandler.cs index 114d8d75..103e6d7d 100644 --- a/NewHorizons/Handlers/ShipLogHandler.cs +++ b/NewHorizons/Handlers/ShipLogHandler.cs @@ -23,8 +23,9 @@ namespace NewHorizons.Handlers // NewHorizonsBody -> AstroID private static Dictionary _nhBodyToAstroIDs; - private static string[] vanillaBodies; - private static string[] vanillaIDs; + private static string[] _vanillaBodies; + private static string[] _vanillaBodyIDs; + private static string[] _moddedFactsIDs; public static void Init() { @@ -33,13 +34,19 @@ namespace NewHorizons.Handlers _nhBodyToAstroIDs = new Dictionary(); List gameObjects = SearchUtilities.GetAllChildren(GameObject.Find(PAN_ROOT_PATH)); - vanillaBodies = gameObjects.ConvertAll(g => g.name).ToArray(); - vanillaIDs = gameObjects.ConvertAll(g => g.GetComponent()?.GetID()).ToArray(); + _vanillaBodies = gameObjects.ConvertAll(g => g.name).ToArray(); + _vanillaBodyIDs = gameObjects.ConvertAll(g => g.GetComponent()?.GetID()).ToArray(); + } + + public static void CheckForModdedFacts(ShipLogManager manager) + { + List moddedFacts = manager._factList.Where(e => manager._entryDataDict.ContainsKey(e._entryID) == false).ToList(); + _moddedFactsIDs = moddedFacts.ConvertAll(e => e.GetID()).ToArray(); } public static bool IsVanillaAstroID(string astroId) { - return vanillaIDs.Contains(astroId); + return _vanillaBodyIDs.Contains(astroId); } public static bool IsVanillaBody(NewHorizonsBody body) @@ -48,7 +55,7 @@ namespace NewHorizons.Handlers if (existingBody != null && existingBody.GetAstroObjectName() != AstroObject.Name.CustomString) return true; - return vanillaBodies.Contains(body.Config.Name.Replace(" ", "")); + return _vanillaBodies.Contains(body.Config.Name.Replace(" ", "")); } public static string GetNameFromAstroID(string astroID) @@ -66,6 +73,11 @@ namespace NewHorizons.Handlers } } + public static bool IsModdedFact(string FactID) + { + return _moddedFactsIDs.Contains(FactID); + } + public static void AddConfig(string astroID, List entryIDs, NewHorizonsBody body) { // Nice to be able to just get the AstroID from the body diff --git a/NewHorizons/Tools/Patches.cs b/NewHorizons/Tools/Patches.cs index 97d7b54a..4fd7ad9a 100644 --- a/NewHorizons/Tools/Patches.cs +++ b/NewHorizons/Tools/Patches.cs @@ -55,6 +55,14 @@ namespace NewHorizons.Tools var playerDataResetGame = typeof(PlayerData).GetMethod("ResetGame"); Main.Instance.ModHelper.HarmonyHelper.AddPostfix(playerDataResetGame, typeof(Patches), nameof(Patches.OnPlayerDataResetGame)); + var playerDataAddNewlyRevealedFactID = typeof(PlayerData).GetMethod("AddNewlyRevealedFactID"); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataAddNewlyRevealedFactID, typeof(Patches), nameof(Patches.OnPlayerDataAddNewlyRevealedFactID)); + var playerDataGetNewlyRevealedFactIDs = typeof(PlayerData).GetMethod("GetNewlyRevealedFactIDs"); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataGetNewlyRevealedFactIDs, typeof(Patches), nameof(Patches.OnPlayerDataGetNewlyRevealedFactIDs)); + var playerDataClearNewlyRevealedFactIDs = typeof(PlayerData).GetMethod("ClearNewlyRevealedFactIDs"); + Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataClearNewlyRevealedFactIDs, typeof(Patches), nameof(Patches.OnPlayerDataClearNewlyRevealedFactIDs)); + + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Start", typeof(Patches), nameof(Patches.OnBlackHoleVolumeStart)); Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Awake", typeof(Patches), nameof(Patches.OnWhiteHoleVolumeAwake)); Main.Instance.ModHelper.HarmonyHelper.AddPrefix("UpdateOrbitalLaunchValues", typeof(Patches), nameof(Patches.OnProbeLauncherUpdateOrbitalLaunchValues)); @@ -310,6 +318,32 @@ namespace NewHorizons.Tools } return true; } + + public static bool OnPlayerDataAddNewlyRevealedFactID(string __0) + { + if (ShipLogHandler.IsModdedFact(__0)) + { + NewHorizonsData.AddNewlyRevealedFactID(__0); + return false; + } + else + { + return true; + } + } + + public static bool OnPlayerDataGetNewlyRevealedFactIDs(ref List __result) + { + __result = PlayerData._currentGameSave.newlyRevealedFactIDs.Concat(NewHorizonsData.GetNewlyRevealedFactIDs()).ToList(); + return false; + } + + public static bool OnPlayerDataClearNewlyRevealedFactIDs() + { + PlayerData._currentGameSave.newlyRevealedFactIDs.Clear(); + NewHorizonsData.ClearNewlyRevealedFactIDs(); + return false; + } public static void OnPlayerDataResetGame() { diff --git a/NewHorizons/Tools/ShipLogPatches.cs b/NewHorizons/Tools/ShipLogPatches.cs index 84966110..439073af 100644 --- a/NewHorizons/Tools/ShipLogPatches.cs +++ b/NewHorizons/Tools/ShipLogPatches.cs @@ -66,6 +66,7 @@ namespace NewHorizons.Tools public static void OnShipLogManagerAwakeComplete(ShipLogManager __instance) { + ShipLogHandler.CheckForModdedFacts(__instance); RumorModeBuilder.GenerateEntryData(__instance); for (var i = 0; i < __instance._entryList.Count; i++) { From f3d600bb0c793c38335a70f6998bf72c05316f59 Mon Sep 17 00:00:00 2001 From: Ben C Date: Sun, 27 Mar 2022 15:44:37 -0400 Subject: [PATCH 02/10] Fix focal point at center of system --- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index 03eb27d2..15a9bffa 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -488,7 +488,6 @@ namespace NewHorizons.Builder.ShipLog astroObject._imageObj.GetComponent().enabled = false; astroObject._outlineObj.GetComponent().enabled = false; astroObject._unviewedObj.GetComponent().enabled = false; - astroObject.transform.localScale = node.lastSibling.astroObject.transform.localScale; } node.astroObject = astroObject; if (node.lastSibling != null) ConnectNodeToLastSibling(node, greyScaleMaterial); From 775364170de8fac85b3d694f46b43f7f20f0691b Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 29 Mar 2022 19:23:38 -0400 Subject: [PATCH 03/10] Start volcano/meteors --- NewHorizons/Builder/Props/PropBuildManager.cs | 11 +++- NewHorizons/Builder/Props/VolcanoBuilder.cs | 53 +++++++++++++++++++ NewHorizons/External/PropModule.cs | 8 +++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 NewHorizons/Builder/Props/VolcanoBuilder.cs diff --git a/NewHorizons/Builder/Props/PropBuildManager.cs b/NewHorizons/Builder/Props/PropBuildManager.cs index fc0ad62d..3678956c 100644 --- a/NewHorizons/Builder/Props/PropBuildManager.cs +++ b/NewHorizons/Builder/Props/PropBuildManager.cs @@ -46,10 +46,17 @@ namespace NewHorizons.Builder.Props { foreach(var tornadoInfo in config.Props.Tornados) { - //TornadoBuilder.Make(go, sector, tornadoInfo, config.Atmosphere?.Cloud != null); + TornadoBuilder.Make(go, sector, tornadoInfo, config.Atmosphere?.Cloud != null); } } - if(config.Props.Dialogue != null) + if (config.Props.Volcanos != null) + { + foreach (var volcanoInfo in config.Props.Volcanos) + { + VolcanoBuilder.Make(go, sector, volcanoInfo); + } + } + if (config.Props.Dialogue != null) { foreach(var dialogueInfo in config.Props.Dialogue) { diff --git a/NewHorizons/Builder/Props/VolcanoBuilder.cs b/NewHorizons/Builder/Props/VolcanoBuilder.cs new file mode 100644 index 00000000..6526c6b3 --- /dev/null +++ b/NewHorizons/Builder/Props/VolcanoBuilder.cs @@ -0,0 +1,53 @@ +using NewHorizons.External; +using NewHorizons.Utility; +using UnityEngine; +using Logger = NewHorizons.Utility.Logger; + +namespace NewHorizons.Builder.Props +{ + public static class VolcanoBuilder + { + private static Color defaultStoneTint = new Color(0.07450981f, 0.07450981f, 0.07450981f); + private static Color defaultLavaTint = new Color(4.594794f, 0.3419145f, 0f, 1f); + + public static void Make(GameObject go, Sector sector, PropModule.VolcanoInfo info) + { + var prefab = GameObject.Find("VolcanicMoon_Body/Sector_VM/Effects_VM/VolcanoPivot (2)/MeteorLauncher"); + + var launcherGO = prefab.InstantiateInactive(); + launcherGO.transform.parent = sector.transform; + launcherGO.transform.localPosition = info.position == null ? Vector3.zero : (Vector3) info.position; + launcherGO.name = "MeteorLauncher"; + + var meteorLauncher = launcherGO.GetComponent(); + meteorLauncher._dynamicMeteorPrefab = null; + meteorLauncher._detectableFluid = null; + meteorLauncher._detectableField = null; + + meteorLauncher._launchDirection = info.position == null ? Vector3.up : ((Vector3)info.position).normalized; + + var meteorPrefab = GameObject.Instantiate(meteorLauncher._meteorPrefab); + FixMeteor(meteorPrefab, info); + + meteorLauncher._meteorPrefab = meteorPrefab; + + launcherGO.SetActive(true); + + // Kill the prefab when its done with it + Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => meteorPrefab.SetActive(false)); + } + private static void FixMeteor(GameObject meteor, PropModule.VolcanoInfo info) + { + var mat = meteor.GetComponentInChildren().material; + mat.SetColor("_Color", info.stoneTint == null ? defaultStoneTint : info.stoneTint.ToColor()); + mat.SetColor("_EmissionColor", info.lavaTint == null ? defaultLavaTint : info.lavaTint.ToColor()); + + var detectors = meteor.transform.Find("ConstantDetectors"); + GameObject.Destroy(detectors.GetComponent()); + GameObject.Destroy(detectors.GetComponent()); + + detectors.gameObject.AddComponent(); + detectors.gameObject.AddComponent(); + } + } +} diff --git a/NewHorizons/External/PropModule.cs b/NewHorizons/External/PropModule.cs index dd8f73bb..a92827ac 100644 --- a/NewHorizons/External/PropModule.cs +++ b/NewHorizons/External/PropModule.cs @@ -14,6 +14,7 @@ namespace NewHorizons.External public RaftInfo[] Rafts; public GeyserInfo[] Geysers; public TornadoInfo[] Tornados; + public VolcanoInfo[] Volcanos; public DialogueInfo[] Dialogue; public RevealInfo[] Reveal; public EntryLocationInfo[] EntryLocation; @@ -61,6 +62,13 @@ namespace NewHorizons.External public MColor tint; } + public class VolcanoInfo + { + public MVector3 position = null; + public MColor stoneTint = null; + public MColor lavaTint = null; + } + public class DialogueInfo { public MVector3 position; From d115d6afae8d81630b8755b69b5f4049cb0fad42 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 29 Mar 2022 19:31:29 -0400 Subject: [PATCH 04/10] Update SpawnPointBuilder.cs Should fix #78 --- .../Builder/General/SpawnPointBuilder.cs | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index bc8d0aba..d74923f0 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -72,33 +72,35 @@ namespace NewHorizons.Builder.General { suitUpQueued = false; if (Locator.GetPlayerController()._isWearingSuit) return; - try + + Locator.GetPlayerTransform().GetComponent().SuitUp(false, true, true); + + // Make the ship act as if the player took the suit + var spv = GameObject.Find("Ship_Body/Module_Supplies/Systems_Supplies/ExpeditionGear")?.GetComponent(); + + if (spv == null) return; + + spv._containsSuit = false; + + if (spv._allowSuitReturn) { - var spv = GameObject.Find("Ship_Body/Module_Supplies/Systems_Supplies/ExpeditionGear").GetComponent(); - spv.SetValue("_containsSuit", false); - - if (spv.GetValue("_allowSuitReturn")) - spv.GetValue("_interactVolume").ChangePrompt(UITextType.ReturnSuitPrompt, spv.GetValue("_pickupSuitCommandIndex")); - else - spv.GetValue("_interactVolume").EnableSingleInteraction(false, spv.GetValue("_pickupSuitCommandIndex")); - - Locator.GetPlayerTransform().GetComponent().SuitUp(false, true, true); - - spv.SetValue("_timer", 0f); - spv.SetValue("_index", 0); - - GameObject suitGeometry = spv.GetValue("_suitGeometry"); - if (suitGeometry != null) suitGeometry.SetActive(false); - - OWCollider suitOWCollider = spv.GetValue("_suitOWCollider"); - if (suitOWCollider != null) suitOWCollider.SetActivation(false); - - spv.enabled = true; + spv._interactVolume.ChangePrompt(UITextType.ReturnSuitPrompt, spv._pickupSuitCommandIndex); } - catch(Exception e) + else { - Logger.LogWarning($"Was unable to suit up player. {e.Message}, {e.StackTrace}"); + spv._interactVolume.EnableSingleInteraction(false, spv._pickupSuitCommandIndex); } + + spv._timer = 0f; + spv._index = 0; + + GameObject suitGeometry = spv._suitGeometry; + if (suitGeometry != null) suitGeometry.SetActive(false); + + OWCollider suitOWCollider = spv._suitOWCollider; + if (suitOWCollider != null) suitOWCollider.SetActivation(false); + + spv.enabled = true; } } } From 5898b9c52e8cbdada15b01f4200919aea859e827 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 29 Mar 2022 22:44:40 -0400 Subject: [PATCH 05/10] More API --- NewHorizons/Main.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index b50d4fa4..659bf650 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -418,6 +418,19 @@ namespace NewHorizons { return Main.Instance.OnStarSystemLoaded; } + + public bool ChangeCurrentStarSystem(string name) + { + if (!Main.SystemDict.ContainsKey(name)) return false; + + Main.Instance.ChangeCurrentStarSystem(name); + return true; + } + + public string[] GetInstalledAddons() + { + return Main.MountedAddons.ConvertAll(x => x.ModHelper.Manifest.UniqueName).ToArray(); + } } #endregion API } From ce088f499ae64cd2661bcc39381095846be125d9 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 30 Mar 2022 00:03:27 -0400 Subject: [PATCH 06/10] Make planets get destroyed a tick later for that one guy --- NewHorizons/Builder/General/PlanetDestroyer.cs | 4 ++-- NewHorizons/Handlers/PlanetCreationHandler.cs | 4 ++-- NewHorizons/Main.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/NewHorizons/Builder/General/PlanetDestroyer.cs b/NewHorizons/Builder/General/PlanetDestroyer.cs index 30f6d608..f1518c4e 100644 --- a/NewHorizons/Builder/General/PlanetDestroyer.cs +++ b/NewHorizons/Builder/General/PlanetDestroyer.cs @@ -43,11 +43,11 @@ namespace NewHorizons.Builder.General foreach(var name in _solarSystemBodies) { var ao = AstroObjectLocator.GetAstroObject(name); - if (ao != null) Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => RemoveBody(ao, false)); + if (ao != null) Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => RemoveBody(ao, false), 2); } // Bring the sun back because why not - Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => { if (Locator.GetAstroObject(AstroObject.Name.Sun).gameObject.activeInHierarchy) { sunVolumes.SetActive(true); } }, 2); + Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => { if (Locator.GetAstroObject(AstroObject.Name.Sun).gameObject.activeInHierarchy) { sunVolumes.SetActive(true); } }, 3); } public static void RemoveBody(AstroObject ao, bool delete = false, List toDestroy = null) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 9fb2d0ea..7fe0378a 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -128,8 +128,8 @@ namespace NewHorizons.Handlers if (body.Config.Destroy) { var ao = existingPlanet.GetComponent(); - if (ao != null) Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveBody(ao), 1); - else Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => existingPlanet.SetActive(false), 1); + if (ao != null) Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveBody(ao), 2); + else Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => existingPlanet.SetActive(false), 2); } else UpdateBody(body, existingPlanet); } diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 659bf650..6b17697e 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -429,7 +429,7 @@ namespace NewHorizons public string[] GetInstalledAddons() { - return Main.MountedAddons.ConvertAll(x => x.ModHelper.Manifest.UniqueName).ToArray(); + return Main.MountedAddons.Select(x => x.ModHelper.Manifest.UniqueName).ToArray(); } } #endregion API From aa7e285b279ab814b381e5d6f3be6700f85a6ca6 Mon Sep 17 00:00:00 2001 From: Ben C Date: Sat, 2 Apr 2022 00:21:34 -0400 Subject: [PATCH 07/10] Made translation support reloading --- NewHorizons/Handlers/TranslationHandler.cs | 7 +++++++ NewHorizons/Utility/DebugReload.cs | 1 + 2 files changed, 8 insertions(+) diff --git a/NewHorizons/Handlers/TranslationHandler.cs b/NewHorizons/Handlers/TranslationHandler.cs index e3f6f922..efa2fd5b 100644 --- a/NewHorizons/Handlers/TranslationHandler.cs +++ b/NewHorizons/Handlers/TranslationHandler.cs @@ -140,5 +140,12 @@ namespace NewHorizons.Handlers return key; } + + public static void ClearTables() + { + _shipLogTranslationDictionary.Clear(); + _dialogueTranslationDictionary.Clear(); + _uiTranslationDictionary.Clear(); + } } } diff --git a/NewHorizons/Utility/DebugReload.cs b/NewHorizons/Utility/DebugReload.cs index 55a55b56..8a82a7b6 100644 --- a/NewHorizons/Utility/DebugReload.cs +++ b/NewHorizons/Utility/DebugReload.cs @@ -41,6 +41,7 @@ namespace NewHorizons.Utility bundle.Unload(true); } Main.AssetBundles.Clear(); + TranslationHandler.ClearTables(); Logger.Log("Begin reload of config files...", Logger.LogType.Log); From 799ad71d0a2b04bcb2e2249f28c3fa99c39000aa Mon Sep 17 00:00:00 2001 From: Ben C Date: Sun, 3 Apr 2022 15:08:19 -0400 Subject: [PATCH 08/10] Added cached finding --- .../Builder/Atmosphere/EffectsBuilder.cs | 7 ++-- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 4 +-- NewHorizons/Main.cs | 2 ++ NewHorizons/Utility/SearchUtilities.cs | 33 +++++++++++++++++++ 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs b/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs index e3409ec6..12ad4673 100644 --- a/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs @@ -1,4 +1,5 @@ -using OWML.Utils; +using NewHorizons.Utility; +using OWML.Utils; using UnityEngine; using Logger = NewHorizons.Utility.Logger; @@ -22,7 +23,7 @@ namespace NewHorizons.Builder.Atmosphere if(hasRain) { - var rainGO = GameObject.Instantiate(GameObject.Find("/GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/Effects_GD_Rain"), effectsGO.transform); + var rainGO = GameObject.Instantiate(SearchUtilities.CachedFind("/GiantsDeep_Body/Sector_GD/Sector_GDInterior/Effects_GDInterior/Effects_GD_Rain"), effectsGO.transform); rainGO.transform.localPosition = Vector3.zero; var pvc = rainGO.GetComponent(); @@ -45,7 +46,7 @@ namespace NewHorizons.Builder.Atmosphere snowGO.transform.localPosition = Vector3.zero; for(int i = 0; i < 5; i++) { - var snowEmitter = GameObject.Instantiate(GameObject.Find("/BrittleHollow_Body/Sector_BH/Effects_BH/Effects_BH_Snowflakes"), snowGO.transform); + var snowEmitter = GameObject.Instantiate(SearchUtilities.CachedFind("/BrittleHollow_Body/Sector_BH/Effects_BH/Effects_BH_Snowflakes"), snowGO.transform); snowEmitter.name = "SnowEmitter"; snowEmitter.transform.localPosition = Vector3.zero; diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index 15a9bffa..3f8fc54e 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -102,7 +102,7 @@ namespace NewHorizons.Builder.ShipLog { const float unviewedIconOffset = 15; - GameObject unviewedReference = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/TimberHearth/UnviewedIcon"); + GameObject unviewedReference = SearchUtilities.CachedFind(ShipLogHandler.PAN_ROOT_PATH + "/TimberHearth/UnviewedIcon"); ShipLogAstroObject astroObject = gameObject.AddComponent(); astroObject._id = ShipLogHandler.GetAstroObjectId(body); @@ -244,7 +244,7 @@ namespace NewHorizons.Builder.ShipLog } else if (Main.Instance.CurrentStarSystem == "SolarSystem") { - GameObject gameObject = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + name); + GameObject gameObject = SearchUtilities.CachedFind(ShipLogHandler.PAN_ROOT_PATH + "/" + name); if (body.Config.Destroy || (body.Config.ShipLog?.mapMode?.remove ?? false)) { ShipLogAstroObject astroObject = gameObject.GetComponent(); diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 6b17697e..2b220528 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -150,6 +150,8 @@ namespace NewHorizons void OnSceneLoaded(Scene scene, LoadSceneMode mode) { Logger.Log($"Scene Loaded: {scene.name} {mode}"); + + SearchUtilities.ClearCache(); _isChangingStarSystem = false; diff --git a/NewHorizons/Utility/SearchUtilities.cs b/NewHorizons/Utility/SearchUtilities.cs index 944dfad5..f3b3017f 100644 --- a/NewHorizons/Utility/SearchUtilities.cs +++ b/NewHorizons/Utility/SearchUtilities.cs @@ -10,6 +10,30 @@ namespace NewHorizons.Utility { public static class SearchUtilities { + private static readonly Dictionary CachedGameObjects = new Dictionary(); + + public static void ClearCache() + { + CachedGameObjects.Clear(); + } + + public static GameObject CachedFind(string path) + { + if (CachedGameObjects.ContainsKey(path)) + { + return CachedGameObjects[path]; + } + else + { + GameObject foundObject = GameObject.Find(path); + if (foundObject != null) + { + CachedGameObjects.Add(path, foundObject); + } + return foundObject; + } + } + public static List FindObjectsOfTypeAndName(string name) where T : Object { T[] firstList = GameObject.FindObjectsOfType(); @@ -99,6 +123,10 @@ namespace NewHorizons.Utility public static GameObject Find(string path) { + if (CachedGameObjects.ContainsKey(path)) + { + return CachedGameObjects[path]; + } try { var go = GameObject.Find(path); @@ -155,6 +183,11 @@ namespace NewHorizons.Utility go = FindObjectOfTypeAndName(name); } + if (go != null) + { + CachedGameObjects.Add(path, go); + } + return go; } catch(Exception) From 9c178cc6e0a992e016e773800c273f24419778cf Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 3 Apr 2022 17:09:02 -0400 Subject: [PATCH 09/10] Update DetailBuilder.cs --- NewHorizons/Builder/Props/DetailBuilder.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index c48bcd8c..a25ac70f 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -73,9 +73,14 @@ namespace NewHorizons.Builder.Props foreach (var component in prop.GetComponents().Concat(prop.GetComponentsInChildren())) { // Enable all children or something - var enabledField = component.GetType().GetField("enabled"); + var enabledField = component?.GetType()?.GetField("enabled"); if (enabledField != null && enabledField.FieldType == typeof(bool)) Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => enabledField.SetValue(component, true)); + if(component is Sector) + { + (component as Sector)._parentSector = sector; + } + // TODO: Make this work or smthng if (component is GhostIK) (component as GhostIK).enabled = false; if (component is GhostEffects) (component as GhostEffects).enabled = false; @@ -99,6 +104,11 @@ namespace NewHorizons.Builder.Props { (component as SectoredMonoBehaviour).SetSector(sector); } + else + { + var sectorField = component?.GetType()?.GetField("_sector"); + if (sectorField != null && sectorField.FieldType == typeof(Sector)) Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => sectorField.SetValue(component, sector)); + } if (component is AnglerfishController) { From a186cfd03ea20ff2bceb6355a6a63e9ed5ebf901 Mon Sep 17 00:00:00 2001 From: Ben C Date: Sun, 3 Apr 2022 17:31:24 -0400 Subject: [PATCH 10/10] Update manifest.json --- NewHorizons/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index fea4befb..06ca8f68 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -3,7 +3,7 @@ "author": "xen, Idiot, & Book", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "0.10.0", + "version": "0.10.1", "owmlVersion": "2.1.0", "dependencies": [ "PacificEngine.OW_CommonResources" ], "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "Vesper.OuterWildsMMO", "Vesper.AutoResume" ],