mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Fixed it so it actually works
This commit is contained in:
parent
93c427b5e6
commit
803d2d6e2d
@ -7,6 +7,7 @@ using OWML.Common;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Components
|
||||
@ -115,8 +116,6 @@ namespace NewHorizons.Components
|
||||
{
|
||||
NHLogger.LogVerbose($"Load credits {gameOver.creditsType}");
|
||||
|
||||
|
||||
|
||||
switch (gameOver.creditsType)
|
||||
{
|
||||
case NHCreditsType.Fast:
|
||||
@ -132,28 +131,10 @@ namespace NewHorizons.Components
|
||||
case NHCreditsType.Custom:
|
||||
// We can't load in custom music if an IModBehaviour cannot be provided. This should only happen if called via TryHijackDeathSequence().
|
||||
if (mod is null)
|
||||
NHLogger.LogWarning("Credits called using TryHijackDeathSequence(), custom credits audio cannot not be loaded.");
|
||||
|
||||
LoadManager.LoadScene(OWScene.Credits_Fast, LoadManager.FadeType.ToBlack);
|
||||
|
||||
// Patch new music
|
||||
var musicSource = Locator.FindObjectsOfType<OWAudioSource>().Where(x => x.name == "AudioSource").Single();
|
||||
musicSource.Stop();
|
||||
if (mod is not null)
|
||||
{
|
||||
AudioUtilities.SetAudioClip(musicSource, gameOver.audio, mod);
|
||||
NHLogger.LogWarning("Credits called using TryHijackDeathSequence(), custom credits audio cannot not be loaded.");
|
||||
}
|
||||
musicSource.SetMaxVolume(gameOver.audioVolume);
|
||||
musicSource.loop = gameOver.audioLooping;
|
||||
|
||||
// Patch scroll duration
|
||||
var creditsScroll = Locator.FindObjectOfType<CreditsScrollSection>();
|
||||
creditsScroll._scrollDuration = gameOver.scrollDuration;
|
||||
|
||||
// Restart credits scroll
|
||||
creditsScroll.Start();
|
||||
musicSource.FadeIn(gameOver.audioFadeInLength);
|
||||
|
||||
LoadCustomCreditsScene(gameOver, mod);
|
||||
break;
|
||||
default:
|
||||
// GameOverController disables post processing
|
||||
@ -164,5 +145,51 @@ namespace NewHorizons.Components
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadCustomCreditsScene(GameOverModule gameOver, IModBehaviour mod)
|
||||
{
|
||||
var fromScene = LoadManager.GetCurrentScene();
|
||||
var toScene = OWScene.Credits_Fast;
|
||||
|
||||
LoadManager.LoadScene(toScene, LoadManager.FadeType.ToBlack);
|
||||
|
||||
// We need to do this so we can unsubscribe from within the lambda.
|
||||
LoadManager.SceneLoadEvent completeCreditsLoad = null;
|
||||
|
||||
completeCreditsLoad = (fromScene, toScene) =>
|
||||
{
|
||||
// Patch new music
|
||||
var musicSource = Locator.FindObjectsOfType<OWAudioSource>().Where(x => x.name == "AudioSource").Single();
|
||||
musicSource.Stop();
|
||||
if (mod is not null)
|
||||
{
|
||||
AudioUtilities.SetAudioClip(musicSource, gameOver.audio, mod);
|
||||
}
|
||||
musicSource.SetMaxVolume(gameOver.audioVolume);
|
||||
musicSource.loop = gameOver.audioLooping;
|
||||
musicSource.FadeIn(gameOver.audioFadeInLength);
|
||||
|
||||
// Janky wait until credits are built
|
||||
Task.Run( () =>
|
||||
{
|
||||
var startTime = Time.time;
|
||||
while (Locator.FindObjectsOfType<CreditsScrollSection>().Length == 0) {
|
||||
if (Time.time > startTime + 0.1f)
|
||||
{
|
||||
NHLogger.LogError("Timeout while waiting for credits to be built. Scroll duration couldn't be changed.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Patch scroll duration
|
||||
var creditsScroll = Locator.FindObjectOfType<CreditsScrollSection>();
|
||||
creditsScroll._scrollDuration = gameOver.scrollDuration;
|
||||
});
|
||||
|
||||
LoadManager.OnCompleteSceneLoad -= completeCreditsLoad;
|
||||
};
|
||||
|
||||
LoadManager.OnCompleteSceneLoad += completeCreditsLoad;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ namespace NewHorizons.External.Modules
|
||||
/// Condition that must be true for this game over to trigger. If this is on a LoadCreditsVolume, leave empty to always trigger this game over.
|
||||
/// Note this is a regular dialogue condition, not a persistent condition.
|
||||
/// </summary>
|
||||
public string condition;
|
||||
public string condition;
|
||||
|
||||
/// <summary>
|
||||
/// Path to the audio file to use as custom music for the credits.
|
||||
@ -46,7 +46,7 @@ namespace NewHorizons.External.Modules
|
||||
public bool audioLooping;
|
||||
|
||||
/// <summary>
|
||||
/// The length of the fade in for the credits music.
|
||||
/// Whether the credits music should fade in.
|
||||
/// Note: only applies when creditsType is set to "custom".
|
||||
/// </summary>
|
||||
[DefaultValue(0f)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user