-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from Govorunb/cds-nuts
Custom jukebox tracks (+ unlockable disks)
- Loading branch information
Showing
59 changed files
with
1,220 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace SCHIZO.Interop.Subnautica; | ||
|
||
partial class _JukeboxDisk : | ||
#if BELOWZERO | ||
JukeboxDisk; | ||
#else | ||
UnityEngine.MonoBehaviour; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Text; | ||
using Nautilus.Handlers; | ||
using Nautilus.Utility; | ||
using UnityEngine; | ||
|
||
namespace SCHIZO.Sounds.Jukebox; | ||
|
||
partial class CustomJukeboxDisk | ||
{ | ||
private CustomJukeboxTrack _track; | ||
public AudioClip unlockSound; | ||
|
||
public new void Start() | ||
{ | ||
if (_track) track = _track; | ||
if (track == default) LOGGER.LogWarning($"Jukebox disk {name} at {transform.position} was not assigned a track"); | ||
|
||
// the lore is that when you pick up a disk, AL-AN plays a snippet of it in your head | ||
// if (unlockSound && Story.StoryGoalManager.main!?.GetAlanActor() == Actor.AlAn) | ||
if (unlockSound) // temp for development/testing // Alex's PR comment: uuh | ||
{ | ||
int soundLenHash = unlockSound.samples.GetHashCode(); | ||
int soundNameHash = unlockSound.name.GetHashCode(); | ||
string guid = new StringBuilder(32).Insert(0, $"{soundLenHash:x08}{soundNameHash:x08}", 2).ToString(); | ||
|
||
if (!CustomSoundHandler.TryGetCustomSound(guid, out _)) | ||
{ | ||
CustomSoundHandler.RegisterCustomSound(guid, unlockSound, "bus:/master/SFX_for_pause/PDA_pause/jukebox", AudioUtils.StandardSoundModes_2D); | ||
} | ||
|
||
acquireSound = AudioUtils.GetFmodAsset(guid); | ||
} | ||
base.Start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
using System; | ||
using FMOD; | ||
using Nautilus.Handlers; | ||
using Nautilus.Utility; | ||
using UnityEngine; | ||
using BZJukebox = Jukebox; | ||
|
||
namespace SCHIZO.Sounds.Jukebox; | ||
|
||
public sealed partial class CustomJukeboxTrack | ||
{ | ||
public partial struct TrackLabel | ||
{ | ||
public override string ToString() => string.IsNullOrEmpty(artist) ? title : $"{artist} - {title}"; | ||
public static implicit operator string(TrackLabel trackLabel) => trackLabel.ToString(); | ||
} | ||
|
||
public uint Length => audioClip ? (uint) audioClip.length * 1000 : 0; | ||
|
||
internal Sound sound; | ||
|
||
public bool IsSoundValid() => sound.hasHandle() && sound.getMode(out _) != RESULT.ERR_INVALID_HANDLE; | ||
|
||
public static implicit operator BZJukebox.TrackInfo(CustomJukeboxTrack track) | ||
{ | ||
string label = track.trackLabel; | ||
if (label.Length == 0) label = track.identifier; | ||
return new BZJukebox.TrackInfo { label = label, length = track.Length }; | ||
} | ||
|
||
public static implicit operator BZJukebox.UnlockableTrack(CustomJukeboxTrack track) | ||
=> EnumHandler.TryGetValue(track.identifier, out BZJukebox.UnlockableTrack id) ? id | ||
: throw new ArgumentException("Track is not registered, cannot convert to Jukebox.UnlockableTrack", nameof(track)); | ||
|
||
protected override void Register() | ||
{ | ||
LOGGER.LogDebug($"Registering custom jukebox track {identifier}"); | ||
|
||
if (EnumHandler.TryGetValue(identifier, out BZJukebox.UnlockableTrack trackId)) | ||
{ | ||
LOGGER.LogWarning($"Someone else has already registered unlockable track {identifier}! ({trackId} at {(int) trackId})"); | ||
return; | ||
} | ||
|
||
if (EnumHandler.TryAddEntry(identifier, out EnumBuilder<BZJukebox.UnlockableTrack> registered)) | ||
{ | ||
trackId = registered.Value; | ||
} | ||
else | ||
{ | ||
LOGGER.LogError($"Could not add Jukebox.UnlockableTrack entry for {identifier}"); | ||
return; | ||
} | ||
CustomJukeboxTrackPatches.customTracks[trackId] = this; | ||
|
||
if (!Player.main) return; | ||
|
||
// if we get here, we're registering during a game | ||
// less than ideal but let's roll with it | ||
LOGGER.LogWarning($"Setting up unlock for track '{identifier}' during a game! This might not behave how you expect it to."); | ||
SetupUnlock(); | ||
} | ||
|
||
public static bool TryGetCustomTrack(string identifier, out CustomJukeboxTrack track) | ||
{ | ||
track = null; | ||
|
||
return identifier is not null | ||
&& EnumHandler.TryGetValue(identifier, out BZJukebox.UnlockableTrack trackId) | ||
&& TryGetCustomTrack(trackId, out track); | ||
} | ||
|
||
public static bool TryGetCustomTrack(BZJukebox.UnlockableTrack trackId, out CustomJukeboxTrack track) | ||
=> CustomJukeboxTrackPatches.customTracks.TryGetValue(trackId, out track); | ||
|
||
internal void SetupUnlock(BZJukebox.UnlockableTrack trackId = BZJukebox.UnlockableTrack.None) | ||
{ | ||
if (trackId == default) | ||
trackId = this; | ||
|
||
if (!Player.main || !GameModeManager.HaveGameOptionsSet) | ||
{ | ||
LOGGER.LogError($"Can't set up unlock for {trackId} with no {(!Player.main ? "player" : "game options")}!"); | ||
return; | ||
} | ||
|
||
if (unlockedOnStart || !GameModeManager.GetOption<bool>(GameOption.Story)) | ||
{ | ||
BZJukebox.Unlock(trackId, false); | ||
BZJukebox.main.SetInfo(identifier, this); | ||
} | ||
else | ||
{ | ||
SpawnDisk(trackId, diskSpawnLocation); | ||
} | ||
} | ||
|
||
internal GameObject SpawnDisk(BZJukebox.UnlockableTrack trackId, Vector3 position) | ||
{ | ||
bool isDefault = !diskPrefab; | ||
GameObject prefab = !isDefault ? diskPrefab.gameObject : CustomJukeboxTrackPatches.defaultDiskPrefab; | ||
|
||
GameObject disk = Instantiate(prefab); | ||
disk.transform.position = position; | ||
|
||
if (isDefault) Destroy(disk.GetComponent<JukeboxDisk>()); | ||
|
||
CustomJukeboxDisk diskComp = disk.EnsureComponent<CustomJukeboxDisk>(); | ||
diskComp.track = trackId; | ||
diskComp.unlockSound = unlockSound; | ||
|
||
disk.GetComponent<LargeWorldEntity>().enabled = false; // don't save | ||
|
||
if (!isDefault) MaterialUtils.ApplySNShaders(disk, 1); | ||
|
||
return disk; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace SCHIZO.Sounds.Jukebox; | ||
|
||
partial class CustomJukeboxTrack | ||
{ | ||
protected override void Register() | ||
{ | ||
} | ||
} |
Oops, something went wrong.