From e5b964d7c7452a7e717812ddd6ceb6afe0e87ece Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 25 Jan 2025 22:18:58 -0500 Subject: [PATCH] shenanigans --- NewHorizons/Handlers/AudioTypeHandler.cs | 24 +++++++------- NewHorizons/Handlers/TitleSceneHandler.cs | 39 +++++++++++++++++------ NewHorizons/Main.cs | 1 - 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/NewHorizons/Handlers/AudioTypeHandler.cs b/NewHorizons/Handlers/AudioTypeHandler.cs index dbbc9681..ef6e71f3 100644 --- a/NewHorizons/Handlers/AudioTypeHandler.cs +++ b/NewHorizons/Handlers/AudioTypeHandler.cs @@ -15,28 +15,28 @@ namespace NewHorizons.Handlers { private static Dictionary _customAudioTypes; private static List _audioEntries; + private static bool _postInitialized = false; - public static void Init(bool titleScreen = false) + public static void Init() { _customAudioTypes = new Dictionary(); _audioEntries = new List(); + _postInitialized = false; - if (titleScreen) - Delay.RunWhenAndInNUpdates( - PostInit, - () => Locator.GetAudioManager()?._libraryAsset != null, - 1 - ); - else - Delay.RunWhen(() => Locator.GetAudioManager()?._libraryAsset != null, - PostInit - ); + Delay.RunWhen(() => Locator.GetAudioManager()?._libraryAsset != null && Locator.GetAudioManager()?._audioLibraryDict != null, + PostInit + ); } private static void PostInit() { NHLogger.LogVerbose($"Adding all custom AudioTypes to the library"); + _postInitialized = true; + ModifyAudioLibrary(); + } + private static void ModifyAudioLibrary() + { var library = Locator.GetAudioManager()._libraryAsset; var audioEntries = library.audioEntries; // store previous array library.audioEntries = library.audioEntries.Concat(_audioEntries).ToArray(); // concat custom entries @@ -94,6 +94,8 @@ namespace NewHorizons.Handlers _audioEntries.Add(new AudioLibrary.AudioEntry(audioType, audioClips)); _customAudioTypes.Add(id, audioType); + if (_postInitialized) ModifyAudioLibrary(); + return audioType; } } diff --git a/NewHorizons/Handlers/TitleSceneHandler.cs b/NewHorizons/Handlers/TitleSceneHandler.cs index f120342e..c503a44f 100644 --- a/NewHorizons/Handlers/TitleSceneHandler.cs +++ b/NewHorizons/Handlers/TitleSceneHandler.cs @@ -1,3 +1,4 @@ +using Epic.OnlineServices; using Epic.OnlineServices.Presence; using NewHorizons.Builder.Body; using NewHorizons.Builder.Props; @@ -28,11 +29,24 @@ namespace NewHorizons.Handlers var ambientLight = SearchUtilities.Find("Scene/Background/PlanetPivot/AmbientLight_CaveTwin"); ambientLight.transform.SetParent(planetRoot.transform, true); - TitleSceneHandler.InitSubtitles(); + InitSubtitles(); + AudioTypeHandler.Init(); + + // Load player data for fact and persistent condition checking + var profileManager = StandaloneProfileManager.SharedInstance; + profileManager.PreInitialize(); + profileManager.Initialize(); + PlayerData.Init(profileManager.currentProfileGameSave, + profileManager.currentProfileGameSettings, + profileManager.currentProfileGraphicsSettings, + profileManager.currentProfileInputJSON); // TODO: Select one title screen and if it has shareTitleScreen set to true do all the other ones that have it true too. var (mod, config) = Main.TitleScreenConfigs.FirstOrDefault(kvp => kvp.Value.KnowsFact() && kvp.Value.HasCondition()); - TitleSceneHandler.SetUp(mod, config); + if (config != null) + SetUp(mod, config); + else + DisplayBodiesOnTitleScreen(); } public static void InitSubtitles() @@ -53,14 +67,7 @@ namespace NewHorizons.Handlers { if (!config.disableNHPlanets) { - try - { - TitleSceneHandler.DisplayBodyOnTitleScreen(Main.BodyDict.Values.ToList().SelectMany(x => x).ToList()); - } - catch (Exception e) - { - NHLogger.LogError($"Failed to make title screen bodies: {e}"); - } + DisplayBodiesOnTitleScreen(); } if (config.menuTextTint != null) @@ -154,6 +161,18 @@ namespace NewHorizons.Handlers } } + public static void DisplayBodiesOnTitleScreen() + { + try + { + TitleSceneHandler.DisplayBodyOnTitleScreen(Main.BodyDict.Values.ToList().SelectMany(x => x).ToList()); + } + catch (Exception e) + { + NHLogger.LogError($"Failed to make title screen bodies: {e}"); + } + } + public static void DisplayBodyOnTitleScreen(List bodies) { // Try loading one planet why not diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 7ad0851c..c4cc2377 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -422,7 +422,6 @@ namespace NewHorizons if (isTitleScreen && CustomTitleScreen) { - AudioTypeHandler.Init(true); TitleSceneHandler.Init(); }