Skip to content

Commit

Permalink
make travel music play when anyone is flying the ship
Browse files Browse the repository at this point in the history
  • Loading branch information
misternebula committed Jan 27, 2024
1 parent 936a277 commit d1f40ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
23 changes: 23 additions & 0 deletions QSB/ShipSync/Patches/ShipAudioPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,27 @@ public static bool ShipThrusterAudio_Update(ShipThrusterAudio __instance)
return true;
}
}

[HarmonyPrefix]
[HarmonyPatch(typeof(TravelMusicController), nameof(TravelMusicController.Update))]
public static bool TravelMusicController_Update(TravelMusicController instance)
{
// only this line is changed
instance._isTraveling = PlayerState.IsInsideShip()
&& ShipManager.Instance.CurrentFlyer != uint.MaxValue
&& Locator.GetPlayerRulesetDetector().AllowTravelMusic();

if (instance._isTraveling && !instance._wasTraveling)
{
instance._audioSource.FadeIn(5f, false, false, 1f);
}
else if (!instance._isTraveling && instance._wasTraveling)
{
instance._audioSource.FadeOut(5f, OWAudioSource.FadeOutCompleteAction.PAUSE, 0f);
}

instance._wasTraveling = instance._isTraveling;

return false;
}
}
4 changes: 4 additions & 0 deletions QSB/ShipSync/ShipManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class ShipManager : WorldObjectManager
public ShipElectricalComponent ShipElectricalComponent;
public ShipCockpitUI ShipCockpitUI;
private GameObject _shipCustomAttach;

/// <summary>
/// PlayerID of the person who is flying the ship. If no one is flying, this is <see cref="uint.MaxValue"/>.
/// </summary>
public uint CurrentFlyer
{
get => _currentFlyer;
Expand Down

0 comments on commit d1f40ef

Please sign in to comment.