Skip to content

Commit

Permalink
uhh some more changes related to options
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexejhero committed Oct 31, 2023
1 parent 8406ff7 commit 3351c6e
Show file tree
Hide file tree
Showing 46 changed files with 142 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Nautilus.Utility;
using UnityEngine.UI;

namespace SCHIZO.Options;
namespace SCHIZO.Options.Bool;

partial class ToggleModOption
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using UnityEngine;

namespace SCHIZO.Options;
namespace SCHIZO.Options.Float;

partial class ConfigurableValueFloat
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Nautilus.Options;
using UnityEngine;

namespace SCHIZO.Options;
namespace SCHIZO.Options.Float;

partial class SliderModOption
{
protected override float ValueInternal
{
get => PlayerPrefs.GetFloat(PlayerPrefsKey, defaultValue);
set => PlayerPrefs.SetFloat(PlayerPrefsKey, value);
set => PlayerPrefs.SetFloat(PlayerPrefsKey, Clamped(value));
}

protected override OptionItem GetOptionItemInternal()
Expand All @@ -23,4 +23,9 @@ protected override OptionItem GetOptionItemInternal()

return option;
}

private float Clamped(float value)
{
return Mathf.Clamp(value, min, max);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SCHIZO.Options;
namespace SCHIZO.Options.Generic;

partial class ConfigurableValue<TRaw, TModOption>
{
Expand Down
68 changes: 39 additions & 29 deletions SCHIZO/Options/ModOption.cs → SCHIZO/Options/Generic/ModOption.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
using System;
using System.Collections.Generic;
using Nautilus.Handlers;
using Nautilus.Options;
using UnityEngine;
using SCHIZO.Options.Bool;

namespace SCHIZO.Options;

partial class ModOption<T>
{
protected string PlayerPrefsKey => $"SCHIZO_ModOption_{id}";

public T Value
{
get => ValueInternal;
set
{
ValueInternal = value;
OnValueChanged?.Invoke(value);
}
}
protected abstract T ValueInternal { get; set; }

public event Action<T> OnValueChanged;
}
namespace SCHIZO.Options.Generic;

partial class ModOption
{
Expand All @@ -34,29 +15,58 @@ public OptionItem GetOptionItem()
OptionItems[result] = this;
return result;
}

protected abstract OptionItem GetOptionItemInternal();

public virtual void AddRealtimeUpdater(GameObject optionObject)
public virtual void SetupOptionUpdater(OptionUpdater updater)
{
RealtimeOptionUpdater updater = optionObject.AddComponent<RealtimeOptionUpdater>();
updater.modOption = this;
updater.OnEnable();

foreach (ToggleModOption toggleModOption in disableIfAnyFalse)
{
toggleModOption.OnValueChanged += _ =>
{
if (updater) updater.OnEnable();
if (updater) updater.UpdateOption();
};
}

foreach (ToggleModOption toggleModOption in disableIfAnyTrue)
{
toggleModOption.OnValueChanged += _ =>
{
if (updater) updater.OnEnable();
if (updater) updater.UpdateOption();
};
}
}

public abstract Type GetOptionUpdaterType();
}

partial class ModOption<TValue>
{
protected string PlayerPrefsKey => $"SCHIZO_ModOption_{id}";

public TValue Value
{
get => ValueInternal;
set
{
ValueInternal = value;
OnValueChanged?.Invoke(value);
}
}
protected abstract TValue ValueInternal { get; set; }

public event Action<TValue> OnValueChanged;

public override Type GetOptionUpdaterType() => typeof(OptionUpdater);
}

partial class ModOption<TValue, TUpdater>
{
public sealed override void SetupOptionUpdater(OptionUpdater updater)
{
base.SetupOptionUpdater(updater);
SetupOptionUpdaterInternal((TUpdater) updater);
}
protected abstract void SetupOptionUpdaterInternal(TUpdater updater);

public sealed override Type GetOptionUpdaterType() => typeof(TUpdater);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
using System.Linq;
using UnityEngine;

namespace SCHIZO.Options;
namespace SCHIZO.Options.Generic;

public sealed class RealtimeOptionUpdater : MonoBehaviour
partial class OptionUpdater : MonoBehaviour
{
public ModOption modOption;

public void OnEnable()
private void OnEnable()
{
if (!modOption) return;
UpdateOption();
}

public virtual void UpdateOption()
{
if (modOption.disableIfAnyFalse.Any(o => !o.Value) || modOption.disableIfAnyTrue.Any(o => o.Value)) gameObject.SetActive(false);
else gameObject.SetActive(true);
}
Expand Down
8 changes: 7 additions & 1 deletion SCHIZO/Options/RuntimeModOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Nautilus.Options;
using SCHIZO.Options.Generic;

namespace SCHIZO.Options;

Expand All @@ -18,6 +19,11 @@ public RuntimeModOptions(List<ModOption> options) : base("Neuro-sama Mod")
private void OnGameObjectCreated(object _, GameObjectCreatedEventArgs evt)
{
ModOption modOption = ModOption.OptionItems[_options[evt.Id]];
modOption.AddRealtimeUpdater(evt.Value);

OptionUpdater updater = (OptionUpdater) evt.Value.AddComponent(modOption.GetOptionUpdaterType());
updater.modOption = modOption;
modOption.SetupOptionUpdater(updater);

updater.UpdateOption();
}
}
2 changes: 0 additions & 2 deletions SCHIZO/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
using BepInEx.Logging;
using ECCLibrary;
using HarmonyLib;
using Nautilus.Handlers;
using SCHIZO.ConsoleCommands;
using SCHIZO.Helpers;
using SCHIZO.Resources;
using SCHIZO.Sounds;
using UnityEngine;

namespace SCHIZO;
Expand Down
6 changes: 3 additions & 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 = -1806460644;
private const int _rnd = -2123123401;

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

Expand All @@ -30,7 +30,7 @@ public static class Assets
public static SCHIZO.Items.Data.CloneItemData Gymbag_GymbagBZ = _a.LoadAsset<SCHIZO.Items.Data.CloneItemData>("Assets/Gymbag/Gymbag BZ.asset");
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.Options.ToggleModOption Options_DisableAllSounds = _a.LoadAsset<SCHIZO.Options.ToggleModOption>("Assets/Options/Disable all sounds.asset");
public static SCHIZO.Options.ToggleModOption Options_EnableAutomaticEvents = _a.LoadAsset<SCHIZO.Options.ToggleModOption>("Assets/Options/Enable automatic events.asset");
public static SCHIZO.Options.Bool.ToggleModOption Options_DisableAllSounds = _a.LoadAsset<SCHIZO.Options.Bool.ToggleModOption>("Assets/Options/Disable all sounds.asset");
public static SCHIZO.Options.Bool.ToggleModOption Options_EnableAutomaticEvents = _a.LoadAsset<SCHIZO.Options.Bool.ToggleModOption>("Assets/Options/Enable automatic events.asset");
public static SCHIZO.Registering.ModRegistry Registry = _a.LoadAsset<SCHIZO.Registering.ModRegistry>("Assets/Registry.asset");
}
Binary file modified SCHIZO/Resources/AssetBundles/assets
Binary file not shown.
4 changes: 4 additions & 0 deletions SCHIZO/SCHIZO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<Compile Remove="$(SolutionDir)/Unity/Assets/Scripts/SCHIZO/_old/**/*.cs" />
<Compile Remove="$(SolutionDir)/Unity/Assets/Scripts/SCHIZO/Materials/**/*.cs" />

<Folder Include="Attributes" />
<Folder Include="Attributes/Typing" />
<Folder Include="Attributes/Validation" />
<Folder Include="Attributes/Visual" />
<Folder Include="Utilities" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using SCHIZO.Interop.Subnautica.Enums;
using SCHIZO.Registering;
using SCHIZO.Interop.Subnautica.Enums;
using UnityEditor;

namespace Editor.Scripts.PropertyDrawers
Expand Down
7 changes: 6 additions & 1 deletion Unity/Assets/Options/Enable automatic events.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ MonoBehaviour:
m_Name: Enable automatic events
m_EditorClassIdentifier:
id: autoevents
disableIfAnyTrue: []
disableIfAnyFalse: []
label: Enable automatic events
defaultValue: 1
tooltip: 'Allows events to trigger automatically.
If disabled, events can
only be started using the "event" command.'
only be started using the "event" command.
(Leave this on unless you''re
Vedal)'
2 changes: 1 addition & 1 deletion Unity/Assets/Options/Inventory sounds maximum delay.asset
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f62dbd26141440dfbb2832db54a5abb9, type: 3}
m_Name: Inventory sounds maximum delay
m_EditorClassIdentifier:
id: inventory_ambient_max_delay
disableIfAnyTrue:
- {fileID: 11400000, guid: 9d930f9cd30bc6e42aaf2db5dc362cf1, type: 2}
- {fileID: 11400000, guid: 586ae6e6828837441a6a92a32eb1ba84, type: 2}
disableIfAnyFalse: []
id: inventory_ambient_max_delay
label: Inventory sounds maximum delay
defaultValue: 120
tooltip: The minimum delay between ambient inventory sounds.
Expand Down
2 changes: 1 addition & 1 deletion Unity/Assets/Options/Inventory sounds minimum delay.asset
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f62dbd26141440dfbb2832db54a5abb9, type: 3}
m_Name: Inventory sounds minimum delay
m_EditorClassIdentifier:
id: inventory_ambient_min_delay
disableIfAnyTrue:
- {fileID: 11400000, guid: 9d930f9cd30bc6e42aaf2db5dc362cf1, type: 2}
- {fileID: 11400000, guid: 586ae6e6828837441a6a92a32eb1ba84, type: 2}
disableIfAnyFalse: []
id: inventory_ambient_min_delay
label: Inventory sounds minimum delay
defaultValue: 60
tooltip: The minimum delay between ambient inventory sounds.
Expand Down
2 changes: 1 addition & 1 deletion Unity/Assets/Options/World sounds maximum delay.asset
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f62dbd26141440dfbb2832db54a5abb9, type: 3}
m_Name: World sounds maximum delay
m_EditorClassIdentifier:
id: world_ambient_max_delay
disableIfAnyTrue:
- {fileID: 11400000, guid: 9d930f9cd30bc6e42aaf2db5dc362cf1, type: 2}
- {fileID: 11400000, guid: f0594ad0952ab554cbe3376036e1020a, type: 2}
disableIfAnyFalse: []
id: world_ambient_max_delay
label: World sounds maximum delay
defaultValue: 30
tooltip: The minimum delay between ambient world sounds.
Expand Down
2 changes: 1 addition & 1 deletion Unity/Assets/Options/World sounds minimum delay.asset
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f62dbd26141440dfbb2832db54a5abb9, type: 3}
m_Name: World sounds minimum delay
m_EditorClassIdentifier:
id: world_ambient_min_delay
disableIfAnyTrue:
- {fileID: 11400000, guid: 9d930f9cd30bc6e42aaf2db5dc362cf1, type: 2}
- {fileID: 11400000, guid: f0594ad0952ab554cbe3376036e1020a, type: 2}
disableIfAnyFalse: []
id: world_ambient_min_delay
label: World sounds minimum delay
defaultValue: 10
tooltip: The minimum delay between ambient world sounds.
Expand Down
2 changes: 1 addition & 1 deletion Unity/Assets/Scripts/SCHIZO/Creatures/Ermshark/Ermshark.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using JetBrains.Annotations;
using NaughtyAttributes;
using SCHIZO.Attributes.Typing;
using SCHIZO.Creatures.Components;
using SCHIZO.Interop.Subnautica;
using SCHIZO.Attributes.Typing;
using UnityEngine;
using WorldAmbientSoundPlayer = SCHIZO.Sounds.Players.WorldAmbientSoundPlayer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using NaughtyAttributes;
using SCHIZO.Attributes.Validation;
using SCHIZO.Helpers;
using SCHIZO.Interop.Subnautica.Enums;
using SCHIZO.Interop.Subnautica.Enums.Subnautica;
using SCHIZO.Registering;
using SCHIZO.Attributes.Validation;
using UnityEngine;

namespace SCHIZO.Interop.NaughtyAttributes
Expand Down
6 changes: 6 additions & 0 deletions Unity/Assets/Scripts/SCHIZO/Items/Data/CloneItemData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using JetBrains.Annotations;
using NaughtyAttributes;
using SCHIZO.Interop.Subnautica.Enums;
using SCHIZO.Items.Gymbag;
using UnityEngine;

namespace SCHIZO.Items.Data
Expand All @@ -16,5 +17,10 @@ public sealed partial class CloneItemData : ItemData

[BZData, Label("Clone Target"), SerializeField, UsedImplicitly, ShowIf(nameof(registerInBZ))]
private TechType_All cloneTargetBZ;

#if UNITY_EDITOR
[ContextMenu("Set Loader/Gymbag")]
private void CreateGymbagLoader() => AssignItemLoader(CreateInstance<GymbagLoader>());
#endif
}
}
2 changes: 1 addition & 1 deletion Unity/Assets/Scripts/SCHIZO/Items/Data/ItemData.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using JetBrains.Annotations;
using NaughtyAttributes;
using SCHIZO.Attributes.Visual;
using SCHIZO.Interop.Subnautica.Enums;
using SCHIZO.Interop.Subnautica.Enums.BelowZero;
using SCHIZO.Interop.Subnautica.Enums.Subnautica;
using SCHIZO.Items.Data.Crafting;
using SCHIZO.Registering;
using SCHIZO.Attributes.Visual;
using UnityEngine;
using UnityEngine.Serialization;
using static NaughtyAttributes.EConditionOperator;
Expand Down
11 changes: 0 additions & 11 deletions Unity/Assets/Scripts/SCHIZO/Items/Gymbag/GymbagLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,3 @@ public sealed partial class GymbagLoader : CloneItemLoader
{
}
}

#if UNITY_EDITOR
namespace SCHIZO.Items.Data
{
partial class CloneItemData
{
[UnityEngine.ContextMenu("Set Loader/Gymbag")]
private void CreateGymbagLoader() => AssignItemLoader(CreateInstance<Gymbag.GymbagLoader>());
}
}
#endif
2 changes: 1 addition & 1 deletion Unity/Assets/Scripts/SCHIZO/Jukebox/CustomJukeboxTrack.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using NaughtyAttributes;
using SCHIZO.Attributes.Visual;
using SCHIZO.Registering;
using JetBrains.Annotations;
using SCHIZO.Attributes.Visual;
using UnityEngine;

namespace SCHIZO.Jukebox
Expand Down
4 changes: 2 additions & 2 deletions Unity/Assets/Scripts/SCHIZO/Loading/LoadingBackground.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using SCHIZO.Attributes.Visual;
using SCHIZO.Registering;
using SCHIZO.Registering;
using SCHIZO.Attributes.Visual;
using UnityEngine;

namespace SCHIZO.Loading
Expand Down
Loading

0 comments on commit 3351c6e

Please sign in to comment.