Skip to content

Commit

Permalink
add custom disk prefabs
Browse files Browse the repository at this point in the history
update to new api
  • Loading branch information
Govorunb committed Oct 18, 2023
1 parent 4be726d commit 1f5979e
Show file tree
Hide file tree
Showing 44 changed files with 708 additions and 46 deletions.
4 changes: 2 additions & 2 deletions SCHIZO/Helpers/MaterialHelpers.BelowZero.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections;
using System.Collections;
using System.Runtime.CompilerServices;
using SCHIZO.Attributes;
using SCHIZO.Attributes.Loading;
using UnityEngine;
using UWE;

Expand Down
4 changes: 2 additions & 2 deletions SCHIZO/Interop/NaughtyAttributes/NaughtyAttributesInterop.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ReSharper disable UnusedParameter.Local
// ReSharper disable UnusedParameter.Local
// ReSharper disable UnusedType.Global

#pragma warning disable CS9113 // Parameter is unread.
Expand Down Expand Up @@ -56,7 +56,7 @@ internal class EnumFlagsAttribute : Attribute;
internal class ValidateInputAttribute(string callbackName, string message = null) : Attribute;

[Conditional("NEVER")]
internal class RequiredAttribute : Attribute;
internal class RequiredAttribute(string message = null) : Attribute;

[Conditional("NEVER")]
internal class DropdownAttribute(string valuesName) : Attribute;
Expand Down
3 changes: 3 additions & 0 deletions SCHIZO/Interop/Subnautica/_JukeboxDisk.BelowZero.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace SCHIZO.Interop.Subnautica;

partial class _JukeboxDisk : JukeboxDisk;
2 changes: 0 additions & 2 deletions SCHIZO/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using SCHIZO.Sounds;
using UnityEngine;
using SCHIZO.Sounds.Jukebox_;
using SCHIZO.Unity.Items;

namespace SCHIZO;

Expand All @@ -34,7 +33,6 @@ private void Awake()
Assets.Registry.InvokeRegister();
Assets.Registry.InvokePostRegister();

Assets.All<CustomJukeboxTrack>().ForEach(CustomJukeboxTrack.Register);
AddComponentAttribute.AddAll(gameObject);
LoadMethodAttribute.LoadAll();

Expand Down
4 changes: 1 addition & 3 deletions SCHIZO/Resources/AssetBundles/Assets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace SCHIZO.Resources;

public static class Assets
{
private const int _rnd = -1122530483;
private const int _rnd = 572943;

private static readonly UnityEngine.AssetBundle _a = ResourceManager.GetAssetBundle("assets");

Expand All @@ -33,6 +33,4 @@ public static class Assets
public static SCHIZO.Items.Data.CloneItemData Gymbag_GymbagSN = _a.LoadAsset<SCHIZO.Items.Data.CloneItemData>("Assets/Gymbag/Gymbag SN.asset");
public static UnityEngine.Texture2D Loading_Icon_LoadingIcon = _a.LoadAsset<UnityEngine.Texture2D>("Assets/Loading/Icon/loading icon.png");
public static SCHIZO.Registering.ModRegistry Registry = _a.LoadAsset<SCHIZO.Registering.ModRegistry>("Assets/Registry.asset");
public static SCHIZO.Sounds.Jukebox_.CustomJukeboxTrack Jukebox_HELLOCHAT = _a.LoadAsset<SCHIZO.Sounds.Jukebox_.CustomJukeboxTrack>("Assets/Jukebox/HELLO CHAT.asset");
public static SCHIZO.Sounds.Jukebox_.CustomJukeboxTrack Jukebox_TruckersFM = _a.LoadAsset<SCHIZO.Sounds.Jukebox_.CustomJukeboxTrack>("Assets/Jukebox/TruckersFM.asset");
}
Binary file modified SCHIZO/Resources/AssetBundles/assets
Binary file not shown.
2 changes: 1 addition & 1 deletion SCHIZO/SCHIZO.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configurations>Subnautica;BelowZero</Configurations>
<NoWarn>$(NoWarn);CS0436;CS0649;Publicizer001;</NoWarn>
Expand Down
32 changes: 32 additions & 0 deletions SCHIZO/Sounds/Jukebox/CustomJukeboxDisk.BelowZero.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Text;
using Nautilus.Handlers;
using Nautilus.Utility;
using Story;
using UnityEngine;

namespace SCHIZO.Sounds.Jukebox_;
partial class CustomJukeboxDisk
{
public CustomJukeboxTrack _track;
public AudioClip unlockSound;

public new void Start()

Check warning on line 13 in SCHIZO/Sounds/Jukebox/CustomJukeboxDisk.BelowZero.cs

View workflow job for this annotation

GitHub Actions / build (BelowZero)

The member 'CustomJukeboxDisk.Start()' does not hide an accessible member. The new keyword is not required.
{
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 && StoryGoalManager.main!?.GetAlanActor() == Actor.AlAn)
{
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();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using FMOD;
using Nautilus.Handlers;
using Nautilus.Utility;
using UnityEngine;

// ReSharper disable once CheckNamespace
namespace SCHIZO.Sounds.Jukebox_;

public sealed partial class CustomJukeboxTrack
Expand All @@ -22,35 +24,37 @@ public static implicit operator Jukebox.UnlockableTrack(CustomJukeboxTrack track
=> EnumHandler.TryGetValue(track.identifier, out Jukebox.UnlockableTrack id) ? id
: throw new ArgumentException("Track is not registered, cannot convert to Jukebox.UnlockableTrack", nameof(track));

public static void Register(CustomJukeboxTrack track)
protected override void Register()
{
LOGGER.LogDebug($"Registering custom jukebox track {track.identifier}");
LOGGER.LogDebug($"Registering custom jukebox track {identifier}");

if (EnumHandler.TryGetValue(track.identifier, out Jukebox.UnlockableTrack trackId))
if (EnumHandler.TryGetValue(identifier, out Jukebox.UnlockableTrack trackId))
{
LOGGER.LogWarning($"Someone else has already registered unlockable track {track.identifier}! ({trackId} at {(int) trackId})");
LOGGER.LogWarning($"Someone else has already registered unlockable track {identifier}! ({trackId} at {(int) trackId})");
return;
}
else
{
if (EnumHandler.TryAddEntry(track.identifier, out EnumBuilder<Jukebox.UnlockableTrack> registered))
if (EnumHandler.TryAddEntry(identifier, out EnumBuilder<Jukebox.UnlockableTrack> registered))
trackId = registered.Value;
else
{
LOGGER.LogError($"Could not add Jukebox.UnlockableTrack entry for {track.identifier}");
LOGGER.LogError($"Could not add Jukebox.UnlockableTrack entry for {identifier}");
return;
}
}
CustomJukeboxTrackPatches.customTracks[trackId] = track;
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 '{track.identifier}' during a game! This might not behave how you expect it to.");
track.SetupUnlock();
LOGGER.LogWarning($"Setting up unlock for track '{identifier}' during a game! This might not behave how you expect it to.");
SetupUnlock();
}

public static void Register(CustomJukeboxTrack track) => track.Register();

public static bool TryGetCustomTrack(string identifier, out CustomJukeboxTrack track)
{
track = null;
Expand Down Expand Up @@ -78,21 +82,31 @@ internal void SetupUnlock(Jukebox.UnlockableTrack trackId = Jukebox.UnlockableTr
{
Jukebox.Unlock(trackId, false);
Jukebox.main.SetInfo(identifier, this);
//LOGGER.LogWarning($"Unlocked {trackLabel} ({identifier})");
}
else
{
SpawnDisk(trackId, diskSpawnLocation);
//LOGGER.LogWarning($"Spawned disk for {trackLabel} ({identifier})");
}
}

internal static void SpawnDisk(Jukebox.UnlockableTrack trackId, Vector3 position)
internal GameObject SpawnDisk(Jukebox.UnlockableTrack trackId, Vector3 position)
{
//LOGGER.LogWarning($"Spawning disk for {trackId} at {position}");
GameObject disk = Instantiate(CustomJukeboxTrackPatches.jukeboxDiskPrefab);
bool isDefault = !diskPrefab;
GameObject prefab = !isDefault ? diskPrefab.gameObject : CustomJukeboxTrackPatches.defaultDiskPrefab;

GameObject disk = Instantiate(prefab);
disk.transform.position = position;
disk.GetComponent<JukeboxDisk>().track = trackId;

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

MaterialUtils.ApplySNShaders(disk, 1);

return disk;
}
}
8 changes: 8 additions & 0 deletions SCHIZO/Sounds/Jukebox/CustomJukeboxTrack.Subnautica.cs
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()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class CustomJukeboxTrackPatches
{
internal static readonly SelfCheckingDictionary<Jukebox.UnlockableTrack, CustomJukeboxTrack> customTracks = new("customTracks");

internal static GameObject jukeboxDiskPrefab;
internal static GameObject defaultDiskPrefab;

[HarmonyPatch(typeof(Jukebox), nameof(Jukebox.Awake))]
public static class AwakeWorkaround
Expand All @@ -38,7 +38,7 @@ public static void AddCustomTracks(Jukebox __instance)
Jukebox.musicLabels[track.identifier] = track.trackLabel; // only read inside Awake but why not
__instance._info[track.identifier] = track;
}
if (!jukeboxDiskPrefab) CoroutineHost.StartCoroutine(GetJukeboxDiskPrefab());
if (!defaultDiskPrefab) CoroutineHost.StartCoroutine(GetJukeboxDiskPrefab());
}
}

Expand All @@ -48,7 +48,7 @@ private static IEnumerator GetJukeboxDiskPrefab()
const string diskPrefabPath = "Misc/JukeboxDisk8.prefab";
IPrefabRequest request = PrefabDatabase.GetPrefabForFilenameAsync(diskPrefabPath);
yield return request;
if (!request.TryGetPrefab(out jukeboxDiskPrefab))
if (!request.TryGetPrefab(out defaultDiskPrefab))
throw new Exception("Could not get prefab for jukebox disk!");
}

Expand Down
8 changes: 8 additions & 0 deletions Unity/Assets/Jukebox/Audio.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
22 changes: 22 additions & 0 deletions Unity/Assets/Jukebox/Audio/Seishun Complex unlock sound.mp3.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
22 changes: 22 additions & 0 deletions Unity/Assets/Jukebox/Audio/TruckersFM unlock clip.mp3.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Unity/Assets/Jukebox/Data.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2a0830f50dd2e554381676c875e2cdf1, type: 3}
m_Name: HELLO CHAT
m_Name: Seishun Complex
m_EditorClassIdentifier:
identifier: HELLOCHAT
source: 1
audioClip: {fileID: 0}
URL: http://127.0.0.1/HELLO_CHAT.mp3
identifier: SeishunComplex
source: 0
audioClip: {fileID: 8300000, guid: c432a6b3a5c9a6543b0f23667c4af264, type: 3}
URL:
isStream: 0
overrideTrackLabel: 0
trackLabel:
artist: Eliv
title: AAAAAAAAAAAAAAAAAAA
artist: Neuro-sama ft. anny
title: Seishun Complex (cover)
unlockedOnStart: 0
diskSpawnLocation: {x: -112.2, y: 15.4, z: 305.8}
diskPrefab: {fileID: 0}
diskSpawnLocation: {x: -326, y: 14.1, z: 255}
unlockSound: {fileID: 8300000, guid: 005268b15c059594891b6c1757b0181f, type: 3}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ MonoBehaviour:
artist:
title: TruckersFM
unlockedOnStart: 0
diskSpawnLocation: {x: -328, y: 14.21, z: 255}
diskPrefab: {fileID: 3181987456837979554, guid: 963e240b83e14bc40a5dc0468a639348,
type: 3}
diskSpawnLocation: {x: -328, y: 14.22, z: 255}
unlockSound: {fileID: 8300000, guid: 5ba4e19b28e28bd40b3d57d369a781f0, type: 3}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Unity/Assets/Jukebox/Disks.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Unity/Assets/Jukebox/Disks/Models.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Loading

0 comments on commit 1f5979e

Please sign in to comment.