Skip to content

Commit

Permalink
Even more!
Browse files Browse the repository at this point in the history
  • Loading branch information
RedstoneWizard08 committed Sep 19, 2024
1 parent 014d997 commit a299fe4
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `FreeMetaCoins` option
- Added `Gravity` option
- Added face customization options
- Add support for the `HellDivers` mod
- Add the `KeyCodeOption`
- Add `KeyCode` support into `States`
- GZip the AssetBundle
- Fix a bunch of bugs

## [v1.15.2-config] - 2024-09-06

Expand Down
1 change: 1 addition & 0 deletions ContentLibrary/ContentLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<Reference Include="Virality" HintPath="..\deps\MaxWasUnavailable.Virality-publicized.dll" Private="False" ExcludeAssets="RUNTIME" Publicize="True"/>
<Reference Include="Flashcard" HintPath="..\deps\me.loaforc.Flashcard-publicized.dll" Private="False" ExcludeAssets="RUNTIME" Publicize="True"/>
<Reference Include="Spookdivers" HintPath="..\deps\cheese.spookdivers-publicized.dll" Private="False" ExcludeAssets="RUNTIME" Publicize="True"/>
<Reference Include="HellDivers" HintPath="..\deps\HellDivers-publicized.dll" Private="False" ExcludeAssets="RUNTIME" Publicize="True"/>
</ItemGroup>

<ItemGroup Condition="$(CI) != 'true' And $(USER) != 'codespace' And $(REDSTONE_IS_DUMB) != 1">
Expand Down
145 changes: 145 additions & 0 deletions ContentLibrary/Source/ConfigurableWarning/API/Options/KeyCodeOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#pragma warning disable CS0612 // The obsolete message is only for other mods, we still need to use these methods.

using System;
using System.Collections.Generic;
using ConfigurableWarning.API.State;
using ContentSettings.API;
using Unity.Mathematics;
using UnityEngine;
using Zorro.Settings;

namespace ConfigurableWarning.API.Options;

/// <summary>
/// A float option. This *must* be inherited from to use.
/// Its state is stored in the <see cref="OptionsState" /> class.
/// </summary>
public class KeyCodeOption : KeyCodeSetting, IOption<KeyCode> {
private readonly List<Action<KeyCodeOption>> _applyActions;
private readonly KeyCode _defaultValue;
private readonly string _displayName;
private readonly string _name;

/// <summary>
/// Initialize a <see cref="IOption{T}" /> with the <see cref="KeyCode" /> type.
/// </summary>
/// <param name="name">The option's name.</param>
/// <param name="defaultValue">The default value.</param>
/// <param name="displayName">The option's displayed name.</param>
/// <param name="min">The minimum value.</param>
/// <param name="max">The maximum value.</param>
/// <param name="doClamp">Whether to clamp the value when changed.</param>
protected KeyCodeOption(string name, KeyCode defaultValue, string displayName) : this(name, defaultValue, displayName, []) {
}

/// <summary>
/// Initialize a <see cref="IOption{T}" /> with the <see cref="KeyCode" /> type.
/// </summary>
/// <param name="name">The option's name.</param>
/// <param name="defaultValue">The default value.</param>
/// <param name="displayName">The option's displayed name.</param>
/// <param name="actions">Functions to run when the value is applied.</param>
protected KeyCodeOption(string name, KeyCode defaultValue, string displayName, Action<KeyCodeOption>[] actions) {
_name = name;
_displayName = displayName;
_defaultValue = defaultValue;
_applyActions = [.. actions];
}

/// <inheritdoc />
public KeyCode State {
get => AsOption().State;
set => AsOption().State = value;
}

/// <inheritdoc />
public void RegisterSetting(string tab, string category) {
SettingsLoader.RegisterSetting(tab, category, this);
}

/// <inheritdoc />
public void SetValue(KeyCode value) {
Value = (int) value;
GameHandler.Instance.SettingsHandler.SaveSetting(this);
}

/// <summary>
/// Gets this option's name. This is its name in the registry
/// and in the state holder.
/// </summary>
/// <returns>The option's name.</returns>
public string GetName() {
return _name;
}

/// <summary>
/// Get this option's default value.
/// </summary>
/// <returns>The option's default value.</returns>
public new KeyCode GetDefaultValue() {
return _defaultValue;
}

/// <inheritdoc />
public KeyCode GetValue() {
return (KeyCode) Value;
}

/// <summary>
/// Get the display name of this option.
/// </summary>
/// <returns>The option's display name.</returns>
public string GetDisplayName() {
return _displayName;
}

/// <inheritdoc />
public IUntypedOption AsUntyped() {
return this;
}

/// <summary>
/// Get this option's default value.
/// </summary>
/// <returns>The option's default value.</returns>
public override KeyCode GetDefaultKey() {
return _defaultValue;
}

/// <inheritdoc />
public IOption<KeyCode> AsOption() {
return this;
}

object IUntypedOption.GetValue() {
return GetValue();
}

/// <inheritdoc />
public void SetValue(object value) {
SetValue((KeyCode) value);
}

/// <summary>
/// Get an instance of an option.
/// </summary>
/// <param name="name">The option's name.</param>
/// <returns>The option.</returns>
public static KeyCodeOption? Instance(string name) {
return (KeyCodeOption?) IOption<KeyCode>.Instance(name);
}

/// <summary>
/// Applies the value. This is run when the user changes the value.
/// This will sync it, update the state, and run any apply actions.
/// </summary>
public override void ApplyValue() {
OptionsState.Instance.Update(this);
ConfigurableWarningAPI.Sync.SyncSettings();

foreach (var action in _applyActions) action(this);
}

/// <inheritdoc />
public StateHolder<KeyCode> StateHolder => States.Keys;
}
7 changes: 7 additions & 0 deletions ContentLibrary/Source/ConfigurableWarning/API/State/States.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using UnityEngine;

namespace ConfigurableWarning.API.State;

/// <summary>
Expand All @@ -23,6 +25,11 @@ public static class States {
/// String states.
/// </summary>
public static readonly StateHolder<string> Strings = new();

/// <summary>
/// KeyCode states.
/// </summary>
public static readonly StateHolder<KeyCode> Keys = new();

/// <summary>
/// Enum states.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Linq;
using ConfigurableWarning.API.Attributes;
using ConfigurableWarning.API.Compat;
using ConfigurableWarning.API.Options;
using ConfigurableWarning.API.State;
using UnityEngine;

namespace ConfigurableWarning.Settings.Compat;

/// <summary>
/// Settings keys for HellDivers compat
/// </summary>
public static class HellDiversSettingKeys {
#pragma warning disable CS1591
public const string DiveKey = "DiveKey";
#pragma warning restore CS1591
}

/// <summary>
/// HellDivers compat settings
/// </summary>
[CompatModule(["HellDivers"])]
public class HellDiversCompat : ICompatModule {
/// <inheritdoc />
public void Init() {
States.Keys[HellDiversSettingKeys.DiveKey] = HellDivers.Main.instance.diveKeybind.Value;
}

internal static void ApplySettings(IUntypedOption _opt) {
string[] all = [HellDiversSettingKeys.DiveKey];

if (!all.All(v => OptionsState.Instance.Has(v))) return;

HellDivers.Main.instance.diveKeybind.Value = States.Keys[HellDiversSettingKeys.DiveKey];
}

[CompatGroup("HELLDIVERS", "GENERAL")]
private static class Settings {
[Register]
private class DiveKey()
: KeyCodeOption(HellDiversSettingKeys.DiveKey, KeyCode.F, "Max Players", [ApplySettings]);
}
}
1 change: 1 addition & 0 deletions deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"MaxWasUnavailable/Virality",
"loaforc/Flashcard",
"OriginalCheese/Spookdivers",
"Playboi/HellDivers",
]

deps = [f"https://thunderstore.io/api/experimental/package/{it}/" for it in DEPS]
Expand Down

0 comments on commit a299fe4

Please sign in to comment.