Add multi-stop voyages, a live chart, and named port announcements
This commit is contained in:
@@ -3,7 +3,7 @@ using UnityEngine;
|
||||
|
||||
namespace Soundings
|
||||
{
|
||||
internal enum PassageAnnouncement { Departure, Dining, DiningSpecial, Bar, Show, Terrace }
|
||||
internal enum PassageAnnouncement { Departure, Dining, DiningSpecial, Bar, Show, Terrace, Approach }
|
||||
|
||||
internal sealed class PassageAudio : MonoBehaviour
|
||||
{
|
||||
@@ -20,15 +20,25 @@ namespace Soundings
|
||||
|
||||
private AudioSource wind, engine, effects, voice;
|
||||
private AudioClip step, hardStep, confirmation;
|
||||
private AudioClip departureForPort, approachForPort;
|
||||
private readonly AudioClip[] spoken = new AudioClip[Announcements.Length];
|
||||
private readonly float[] repeatAfter = new float[Announcements.Length];
|
||||
private readonly float[] repeatAfter = new float[(int)PassageAnnouncement.Approach + 1];
|
||||
private float distanceSinceStep;
|
||||
private float announcementTime, announcementGap, announcementClock;
|
||||
private bool leftFoot, crossing, voicePaused;
|
||||
private bool leftFoot, crossing, voicePaused, approachSent;
|
||||
private PassageAnnouncement? currentAnnouncement, pendingAnnouncement;
|
||||
private string nextPort;
|
||||
|
||||
internal PassageAnnouncement? CurrentAnnouncement => currentAnnouncement;
|
||||
internal string Caption => currentAnnouncement.HasValue ? Announcements[(int)currentAnnouncement.Value] : null;
|
||||
internal float ApproachSeconds => approachForPort != null ? approachForPort.length : 0;
|
||||
internal bool ApproachSent => approachSent;
|
||||
internal string Caption => currentAnnouncement switch
|
||||
{
|
||||
PassageAnnouncement.Departure when departureForPort != null => $"Welcome aboard. We are now under way, and our next port of call is {nextPort}.",
|
||||
PassageAnnouncement.Approach => $"May I have your attention, please. We are approaching {nextPort}.",
|
||||
PassageAnnouncement line => Announcements[(int)line],
|
||||
_ => null
|
||||
};
|
||||
|
||||
internal void Initialize()
|
||||
{
|
||||
@@ -59,9 +69,13 @@ namespace Soundings
|
||||
spoken[i] = Resources.Load<AudioClip>($"Audio/PA/{(PassageAnnouncement)i}");
|
||||
}
|
||||
|
||||
internal void Begin()
|
||||
internal void Begin(int destination)
|
||||
{
|
||||
crossing = true;
|
||||
approachSent = false;
|
||||
nextPort = Market.Ports[destination].Name;
|
||||
departureForPort = LoadPortClip("Departure", destination);
|
||||
approachForPort = LoadPortClip("Approach", destination);
|
||||
distanceSinceStep = 0;
|
||||
announcementClock = announcementGap = 0;
|
||||
Array.Clear(repeatAfter, 0, repeatAfter.Length);
|
||||
@@ -76,12 +90,14 @@ namespace Soundings
|
||||
voice.Stop();
|
||||
voicePaused = false;
|
||||
currentAnnouncement = pendingAnnouncement = null;
|
||||
departureForPort = approachForPort = null;
|
||||
voice.clip = null;
|
||||
}
|
||||
|
||||
internal void Announce(PassageAnnouncement line)
|
||||
{
|
||||
int index = (int)line;
|
||||
if (!crossing || spoken[index] == null || currentAnnouncement == line || pendingAnnouncement == line
|
||||
if (!crossing || ClipFor(line) == null || currentAnnouncement == line || pendingAnnouncement == line
|
||||
|| repeatAfter[index] > announcementClock)
|
||||
return;
|
||||
|
||||
@@ -91,6 +107,28 @@ namespace Soundings
|
||||
PlayAnnouncement(line);
|
||||
}
|
||||
|
||||
internal void AnnounceApproach()
|
||||
{
|
||||
if (!crossing || approachSent || approachForPort == null)
|
||||
return;
|
||||
|
||||
approachSent = true;
|
||||
pendingAnnouncement = null;
|
||||
announcementGap = 0;
|
||||
voice.Stop();
|
||||
PlayAnnouncement(PassageAnnouncement.Approach);
|
||||
}
|
||||
|
||||
internal static AudioClip LoadPortClip(string announcement, int destination) =>
|
||||
Resources.Load<AudioClip>($"Audio/PA/{announcement}Port{destination:D2}");
|
||||
|
||||
private AudioClip ClipFor(PassageAnnouncement line) => line switch
|
||||
{
|
||||
PassageAnnouncement.Departure when departureForPort != null => departureForPort,
|
||||
PassageAnnouncement.Approach => approachForPort,
|
||||
_ => spoken[(int)line]
|
||||
};
|
||||
|
||||
internal void Mix(float delta, bool active, float knots, WeatherCondition weather, bool indoors, bool engineering)
|
||||
{
|
||||
UpdateAnnouncements(delta, active);
|
||||
@@ -119,7 +157,7 @@ namespace Soundings
|
||||
{
|
||||
int index = (int)line;
|
||||
currentAnnouncement = line;
|
||||
voice.clip = spoken[index];
|
||||
voice.clip = ClipFor(line);
|
||||
announcementTime = voice.clip.length;
|
||||
repeatAfter[index] = announcementClock + 20f;
|
||||
voice.Play();
|
||||
|
||||
Reference in New Issue
Block a user