diff --git a/NewHorizons/Builder/Body/CloakBuilder.cs b/NewHorizons/Builder/Body/CloakBuilder.cs index ddb60013..239c1809 100644 --- a/NewHorizons/Builder/Body/CloakBuilder.cs +++ b/NewHorizons/Builder/Body/CloakBuilder.cs @@ -11,30 +11,6 @@ namespace NewHorizons.Builder.Body { var radius = module.radius; - AudioClip clip = null; - if (!string.IsNullOrEmpty(module.audioClip)) - { - clip = SearchUtilities.FindResourceOfTypeAndName(module.audioClip); - - if (clip == null) - { - Utility.Logger.LogError($"Couldn't get audio from clip [{module.audioClip}]"); - } - } - else if (!string.IsNullOrEmpty(module.audioFilePath)) - { - try - { - clip = AudioUtilities.LoadAudio(mod.ModHelper.Manifest.ModFolderPath + "/" + module.audioFilePath); - } - catch { } - - if (clip == null) - { - Utility.Logger.LogError($"Couldn't get audio from file [{module.audioFilePath}]"); - } - } - var cloak = SearchUtilities.Find("RingWorld_Body/CloakingField_IP"); var newCloak = GameObject.Instantiate(cloak, sector?.transform ?? planetGO.transform); @@ -59,12 +35,9 @@ namespace NewHorizons.Builder.Body var cloakAudioSource = newCloak.GetComponentInChildren(); cloakAudioSource._audioSource = cloakAudioSource.GetComponent(); - cloakAudioSource._audioLibraryClip = AudioType.None; - cloakAudioSource._clipArrayIndex = 0; - cloakAudioSource._clipArrayLength = 0; - cloakAudioSource._clipSelectionOnPlay = OWAudioSource.ClipSelectionOnPlay.MANUAL; - cloakAudioSource.clip = clip; - + bool hasCustomAudio = !string.IsNullOrEmpty(module.audio); + if (hasCustomAudio) AudioUtilities.SetAudioClip(cloakAudioSource, module.audio, mod); + newCloak.SetActive(true); cloakFieldController.enabled = true; @@ -72,7 +45,7 @@ namespace NewHorizons.Builder.Body // To cloak from the start Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(cloakSectorController.OnPlayerExit); - Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(clip != null ? cloakSectorController.TurnOnMusic : cloakSectorController.TurnOffMusic); + Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(hasCustomAudio ? cloakSectorController.TurnOnMusic : cloakSectorController.TurnOffMusic); Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(keepReferenceFrame ? cloakSectorController.EnableReferenceFrameVolume : cloakSectorController.DisableReferenceFrameVolume); } } diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index 335228a5..12e9425d 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -351,6 +351,13 @@ namespace NewHorizons.External.Configs if (!string.IsNullOrEmpty(signal.audioFilePath)) signal.audio = signal.audioFilePath; } } + + // Cloak + if (Cloak != null) + { + if (!string.IsNullOrEmpty(Cloak.audioClip)) Cloak.audio = Cloak.audioClip; + if (!string.IsNullOrEmpty(Cloak.audioFilePath)) Cloak.audio = Cloak.audioFilePath; + } } } } \ No newline at end of file diff --git a/NewHorizons/External/Configs/StarSystemConfig.cs b/NewHorizons/External/Configs/StarSystemConfig.cs index 6f1b41bf..7cd5828c 100644 --- a/NewHorizons/External/Configs/StarSystemConfig.cs +++ b/NewHorizons/External/Configs/StarSystemConfig.cs @@ -50,16 +50,17 @@ namespace NewHorizons.External.Configs /// public bool startHere; - /// - /// Name of an existing AudioClip in the game that will play when travelling in space. - /// + [System.Obsolete("travelAudioClip is deprecated, please use travelAudio instead")] public string travelAudioClip; - /// - /// Relative filepath to the .wav file to use as the audio. Mutually exclusive with travelAudioClip. - /// + [System.Obsolete("travelAudioFilePath is deprecated, please use travelAudio instead")] public string travelAudioFilePath; + /// + /// The audio that will play when travelling in space. Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list. + /// + public string travelAudio; + /// /// Coordinates that the vessel can use to warp to your solar system. /// @@ -161,8 +162,7 @@ namespace NewHorizons.External.Configs // If current one is null take the other factRequiredForWarp = string.IsNullOrEmpty(factRequiredForWarp) ? otherConfig.factRequiredForWarp : factRequiredForWarp; skybox = skybox == null ? otherConfig.skybox : skybox; - travelAudioClip = string.IsNullOrEmpty(travelAudioClip) ? otherConfig.travelAudioClip : travelAudioClip; - travelAudioFilePath = string.IsNullOrEmpty(travelAudioFilePath) ? otherConfig.travelAudioFilePath : travelAudioFilePath; + travelAudio = string.IsNullOrEmpty(travelAudio) ? otherConfig.travelAudio : travelAudio; // False by default so if one is true go true mapRestricted = mapRestricted || otherConfig.mapRestricted; @@ -178,5 +178,14 @@ namespace NewHorizons.External.Configs { return (array1 ?? new T[0]).Concat(array2 ?? new T[0]).ToArray(); } + + public void Migrate() + { + // Backwards compatability + // Should be the only place that obsolete things are referenced +#pragma warning disable 612, 618 + if (!string.IsNullOrEmpty(travelAudioClip)) travelAudio = travelAudioClip; + if (!string.IsNullOrEmpty(travelAudioFilePath)) travelAudio = travelAudioFilePath; + } } } \ No newline at end of file diff --git a/NewHorizons/External/Modules/CloakModule.cs b/NewHorizons/External/Modules/CloakModule.cs index 55ad844c..0bb68d0d 100644 --- a/NewHorizons/External/Modules/CloakModule.cs +++ b/NewHorizons/External/Modules/CloakModule.cs @@ -16,14 +16,15 @@ namespace NewHorizons.External.Modules /// public float radius; - /// - /// Name of an existing AudioClip in the game that will play when entering the cloaking field. - /// + [Obsolete("audioClip is deprecated, please use audio instead")] public string audioClip; - /// - /// Relative filepath to the .wav file to use as the audio. Mutually exclusive with audioClip. - /// + [Obsolete("audioFilePath is deprecated, please use audio instead")] public string audioFilePath; + + /// + /// The audio that will play when entering the cloaking field. Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list. + /// + public string audio; } } \ No newline at end of file diff --git a/NewHorizons/Handlers/SystemCreationHandler.cs b/NewHorizons/Handlers/SystemCreationHandler.cs index af59fb81..39b009c2 100644 --- a/NewHorizons/Handlers/SystemCreationHandler.cs +++ b/NewHorizons/Handlers/SystemCreationHandler.cs @@ -28,41 +28,9 @@ namespace NewHorizons.Handlers timeLoopController.AddComponent(); } - AudioClip clip = null; - if (!string.IsNullOrEmpty(system.Config.travelAudioClip)) + if (!string.IsNullOrEmpty(system.Config.travelAudio)) { - clip = SearchUtilities.FindResourceOfTypeAndName(system.Config.travelAudioClip); - - if (clip == null) - { - Logger.LogError($"Couldn't get audio from clip [{system.Config.travelAudioClip}]"); - } - } - else if (!string.IsNullOrEmpty(system.Config.travelAudioFilePath)) - { - try - { - clip = AudioUtilities.LoadAudio(system.Mod.ModHelper.Manifest.ModFolderPath + "/" + system.Config.travelAudioFilePath); - } - catch { } - - if (clip == null) - { - Logger.LogError($"Couldn't get audio from file [{system.Config.travelAudioFilePath}]"); - } - } - - if (clip != null) - { - Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => - { - var travelSource = Locator.GetGlobalMusicController()._travelSource; - travelSource._audioLibraryClip = AudioType.None; - travelSource._clipArrayIndex = 0; - travelSource._clipArrayLength = 0; - travelSource._clipSelectionOnPlay = OWAudioSource.ClipSelectionOnPlay.MANUAL; - travelSource.clip = clip; - }); + Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => AudioUtilities.SetAudioClip(Locator.GetGlobalMusicController()._travelSource, system.Config.travelAudio, system.Mod)); } } } diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index e412a85a..06b8e93b 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -370,6 +370,7 @@ namespace NewHorizons var relativePath = file.Replace(folder, ""); var starSystemConfig = mod.ModHelper.Storage.Load(relativePath); + starSystemConfig.Migrate(); starSystemConfig.FixCoordinates(); if (starSystemConfig.startHere) @@ -478,6 +479,7 @@ namespace NewHorizons if (starSystemConfig == null) starSystemConfig = new StarSystemConfig(); else Logger.LogWarning($"Loaded system config for {config.starSystem}. Why wasn't this loaded earlier?"); + starSystemConfig.Migrate(); starSystemConfig.FixCoordinates(); var system = new NewHorizonsSystem(config.starSystem, starSystemConfig, mod); diff --git a/NewHorizons/Utility/AudioUtilities.cs b/NewHorizons/Utility/AudioUtilities.cs index 71d44371..d907d6a2 100644 --- a/NewHorizons/Utility/AudioUtilities.cs +++ b/NewHorizons/Utility/AudioUtilities.cs @@ -18,7 +18,12 @@ namespace NewHorizons.Utility try { var clip = LoadAudio(mod.ModHelper.Manifest.ModFolderPath + "/" + audio); + source._audioLibraryClip = AudioType.None; + source._clipArrayIndex = 0; + source._clipArrayLength = 0; + source._clipSelectionOnPlay = OWAudioSource.ClipSelectionOnPlay.MANUAL; source.clip = clip; + return; } catch {