Customizable Travel Audio (#31)

This commit is contained in:
Noah Pilarski 2022-06-01 06:37:24 -04:00
parent 3634a58bdf
commit f66829e240
3 changed files with 42 additions and 0 deletions

View File

@ -51,6 +51,16 @@ namespace NewHorizons.External.Configs
/// </summary> /// </summary>
public bool startHere; public bool startHere;
/// <summary>
/// Name of an existing AudioClip in the game that will play when travelling in space.
/// </summary>
public string travelAudioClip;
/// <summary>
/// Relative filepath to the .wav file to use as the audio. Mutually exclusive with travelAudioClip.
/// </summary>
public string travelAudioFilePath;
public class NomaiCoordinates public class NomaiCoordinates
{ {
public int[] x; public int[] x;

View File

@ -26,6 +26,30 @@ namespace NewHorizons.Handlers
var timeLoopController = new GameObject("TimeLoopController"); var timeLoopController = new GameObject("TimeLoopController");
timeLoopController.AddComponent<TimeLoopController>(); timeLoopController.AddComponent<TimeLoopController>();
} }
AudioClip clip = null;
if (system.Config.travelAudioClip != null) clip = SearchUtilities.FindResourceOfTypeAndName<AudioClip>(system.Config.travelAudioClip);
else if (system.Config.travelAudioFilePath != null)
{
try
{
clip = AudioUtilities.LoadAudio(system.Mod.ModHelper.Manifest.ModFolderPath + "/" + system.Config.travelAudioFilePath);
}
catch (System.Exception e)
{
Utility.Logger.LogError($"Couldn't load audio file {system.Config.travelAudioFilePath} : {e.Message}");
}
}
if (clip != null)
{
var travelSource = Locator.GetGlobalMusicController()._travelSource;
travelSource._audioLibraryClip = AudioType.None;
travelSource._clipArrayIndex = 0;
travelSource._clipArrayLength = 0;
travelSource._clipSelectionOnPlay = OWAudioSource.ClipSelectionOnPlay.MANUAL;
travelSource.clip = clip;
}
} }
} }
} }

View File

@ -38,6 +38,14 @@
"type": "boolean", "type": "boolean",
"description": "Set to `true` if you want to spawn here after dying, not Timber Hearth. You can still warp back to the main star\nsystem." "description": "Set to `true` if you want to spawn here after dying, not Timber Hearth. You can still warp back to the main star\nsystem."
}, },
"travelAudioClip": {
"type": "string",
"description": "Name of an existing AudioClip in the game that will play when travelling in space."
},
"travelAudioFilePath": {
"type": "string",
"description": "Relative filepath to the .wav file to use as the audio. Mutually exclusive with travelAudioClip."
},
"$schema": { "$schema": {
"type": "string", "type": "string",
"description": "The schema to validate with" "description": "The schema to validate with"