Skip to content

Commit

Permalink
Paused fix, and send updates to game on config update
Browse files Browse the repository at this point in the history
  • Loading branch information
LucHeart committed May 3, 2024
1 parent 9ee6eda commit 8e9ae1f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions ShockOsc/Services/UnderscoreConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ private void ValidateSettings()
public async Task SendUpdateForAll()
{
await _oscClient.SendGameMessage("/avatar/parameters/ShockOsc/_Config/Paused", KillSwitch);
await _oscClient.SendGameMessage("/avatar/parameters/ShockOsc/_Config/_All/Paused", KillSwitch);
await _oscClient.SendGameMessage("/avatar/parameters/ShockOsc/_Config/_All/MinIntensity",
MathUtils.ClampFloat(_configManager.Config.Behaviour.IntensityRange.Min / 100f));
await _oscClient.SendGameMessage("/avatar/parameters/ShockOsc/_Config/_All/MaxIntensity",
Expand Down
40 changes: 23 additions & 17 deletions ShockOsc/Ui/Pages/Dash/Tabs/ConfigTab.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@using OpenShock.ShockOsc.Config
@using OpenShock.ShockOsc.Services
@using OpenShock.ShockOsc.Ui.Utils
@using OpenShock.ShockOsc.Utils
@implements IDisposable
@inject UnderscoreConfig underscoreConfig
@inject ConfigManager ConfigManager
Expand All @@ -14,7 +15,7 @@
<MudText>Global Shocker Options (_All Shocker)</MudText>
<MudDivider/>
<MudPaper Style="display: inline-block; width: 200px; padding-top: 8px; padding-left: 5px">
<MudSelect Class="option-width" @bind-Value="ConfigManager.Config.Behaviour.WhileBoneHeld" Label="While PhysBone Held" @bind-Value:after="OnSettingsValueChange">
<MudSelect Class="option-width" @bind-Value="ConfigManager.Config.Behaviour.WhileBoneHeld" Label="While PhysBone Held" @bind-Value:after="OnSettingsValueChangeAsync">
@foreach (BehaviourConf.BoneHeldAction boneHeldAction in Enum.GetValues(typeof(BehaviourConf.BoneHeldAction)))
{
<MudSelectItem Value="@boneHeldAction">@boneHeldAction</MudSelectItem>
Expand All @@ -24,10 +25,10 @@

<br/>
<br/>
<MudTextField Class="option-width" Variant="Variant.Filled" @bind-Value="ConfigManager.Config.Behaviour.CooldownTime" Label="Cooldown Time" @bind-Value:after="OnSettingsValueChange"/>
<MudTextField Class="option-width" Variant="Variant.Filled" @bind-Value="ConfigManager.Config.Behaviour.HoldTime" Label="Contact Hold Time" @bind-Value:after="OnSettingsValueChange"/>
<MudTextField Class="option-width" Variant="Variant.Filled" @bind-Value="ConfigManager.Config.Behaviour.CooldownTime" Label="Cooldown Time" @bind-Value:after="OnSettingsValueChangeAsync"/>
<MudTextField Class="option-width" Variant="Variant.Filled" @bind-Value="ConfigManager.Config.Behaviour.HoldTime" Label="Contact Hold Time" @bind-Value:after="OnSettingsValueChangeAsync"/>
<br/>
<MudToggleGroup T="string" @bind-Value="RandomIntensityString" Style="width: 330px; margin: 30px 0 0 10px;" Outline="true" Delimiters="true" Dense="true" Rounded="true" CheckMark="false" FixedContent="false" @bind-Value:after="OnSettingsValueChange">
<MudToggleGroup T="string" @bind-Value="RandomIntensityString" Style="width: 330px; margin: 30px 0 0 10px;" Outline="true" Delimiters="true" Dense="true" Rounded="true" CheckMark="false" FixedContent="false" @bind-Value:after="OnSettingsValueChangeAsync">
<MudToggleItem Value="@("Fixed Intensity")"/>
<MudToggleItem Value="@("Random Intensity")"/>
</MudToggleGroup>
Expand All @@ -37,27 +38,27 @@
@if (!ConfigManager.Config.Behaviour.RandomIntensity)
{
<DebouncedSlider T="byte" Size="Size.Large" Min="0" Max="100" Class="openshock-slider-length" @bind-SliderValue="@ConfigManager.Config.Behaviour.FixedIntensity"
OnSaveAction="_ => ConfigManager.SaveFnf()">
OnSaveAction="_ => OnSettingsValueChange()">
Intensity: @ConfigManager.Config.Behaviour.FixedIntensity%
</DebouncedSlider>
}
else
{
<DebouncedSlider T="uint" Size="Size.Large" Min="0" Max="100" Class="openshock-slider-length" @bind-SliderValue="@ConfigManager.Config.Behaviour.IntensityRange.Min"
OnValueChanged="u => { if (ConfigManager.Config.Behaviour.IntensityRange.Max < u) ConfigManager.Config.Behaviour.IntensityRange.Max = u; }"
OnSaveAction="_ => ConfigManager.SaveFnf()">
OnSaveAction="_ => OnSettingsValueChange()">
Min Intensity: @ConfigManager.Config.Behaviour.IntensityRange.Min%
</DebouncedSlider>

<DebouncedSlider T="uint" Size="Size.Large" Min="0" Max="100" Class="openshock-slider-length" @bind-SliderValue="@ConfigManager.Config.Behaviour.IntensityRange.Max"
OnValueChanged="u => { if (ConfigManager.Config.Behaviour.IntensityRange.Min > u) ConfigManager.Config.Behaviour.IntensityRange.Min = u; }"
OnSaveAction="_ => ConfigManager.SaveFnf()">
OnSaveAction="_ => OnSettingsValueChange()">
Max Intensity: @ConfigManager.Config.Behaviour.IntensityRange.Max%
</DebouncedSlider>
}


<MudToggleGroup T="string" @bind-Value="RandomDurationString" Style="width: 330px; margin: 30px 0 0 10px;" Outline="true" Delimiters="true" Dense="true" Rounded="true" CheckMark="false" FixedContent="false" @bind-Value:after="OnSettingsValueChange">
<MudToggleGroup T="string" @bind-Value="RandomDurationString" Style="width: 330px; margin: 30px 0 0 10px;" Outline="true" Delimiters="true" Dense="true" Rounded="true" CheckMark="false" FixedContent="false" @bind-Value:after="OnSettingsValueChangeAsync">
<MudToggleItem Value="@("Fixed Duration")"/>
<MudToggleItem Value="@("Random Duration")"/>
</MudToggleGroup>
Expand All @@ -66,7 +67,7 @@
@if (!ConfigManager.Config.Behaviour.RandomDuration)
{
<DebouncedSlider T="uint" Size="Size.Large" Class="openshock-slider-length" @bind-SliderValue="@ConfigManager.Config.Behaviour.FixedDuration"
OnSaveAction="_ => ConfigManager.SaveFnf()"
OnSaveAction="_ => OnSettingsValueChange()"
Min="300" Max="30000" Step="100">
Duration: @MathF.Round(ConfigManager.Config.Behaviour.FixedDuration / 1000f, 1).ToString(CultureInfo.InvariantCulture)s
</DebouncedSlider>
Expand All @@ -75,14 +76,14 @@
{
<DebouncedSlider T="uint" Size="Size.Large" Class="openshock-slider-length" @bind-SliderValue="@ConfigManager.Config.Behaviour.DurationRange.Min"
OnValueChanged="u => { if (ConfigManager.Config.Behaviour.DurationRange.Max < u) ConfigManager.Config.Behaviour.DurationRange.Max = u; }"
OnSaveAction="_ => ConfigManager.SaveFnf()"
OnSaveAction="_ => OnSettingsValueChange()"
Min="300" Max="30000" Step="100">
Min Duration: @MathF.Round(ConfigManager.Config.Behaviour.DurationRange.Min / 1000f, 1).ToString(CultureInfo.InvariantCulture)s
</DebouncedSlider>

<DebouncedSlider T="uint" Size="Size.Large" Class="openshock-slider-length" @bind-SliderValue="@ConfigManager.Config.Behaviour.DurationRange.Max"
OnValueChanged="u => { if (ConfigManager.Config.Behaviour.DurationRange.Min > u) ConfigManager.Config.Behaviour.DurationRange.Min = u; }"
OnSaveAction="_ => ConfigManager.SaveFnf()"
OnSaveAction="_ => OnSettingsValueChange()"
Min="300" Max="30000" Step="100">
Max Duration: @MathF.Round(ConfigManager.Config.Behaviour.DurationRange.Max / 1000f, 1).ToString(CultureInfo.InvariantCulture)s
</DebouncedSlider>
Expand All @@ -95,9 +96,9 @@
<MudPaper Outlined="true" Class="rounded-lg mud-paper-padding-margin">
<MudText>Game Options</MudText>
<MudDivider/>
<MudCheckBox Class="option-width option-checkbox-height" @bind-Value="underscoreConfig.KillSwitch" Label="Kill Switch" @bind-Value:after="OnSettingsValueChange"/>
<MudCheckBox Class="option-width option-checkbox-height" @bind-Value="ConfigManager.Config.Behaviour.DisableWhileAfk" Label="Disable While Afk" @bind-Value:after="OnSettingsValueChange"/>
<MudCheckBox Class="option-width option-checkbox-height" @bind-Value="ConfigManager.Config.Behaviour.ForceUnmute" Label="Force Unmute" @bind-Value:after="OnSettingsValueChange"/>
<MudCheckBox Class="option-width option-checkbox-height" @bind-Value="underscoreConfig.KillSwitch" Label="Kill Switch" @bind-Value:after="OnSettingsValueChangeAsync"/>
<MudCheckBox Class="option-width option-checkbox-height" @bind-Value="ConfigManager.Config.Behaviour.DisableWhileAfk" Label="Disable While Afk" @bind-Value:after="OnSettingsValueChangeAsync"/>
<MudCheckBox Class="option-width option-checkbox-height" @bind-Value="ConfigManager.Config.Behaviour.ForceUnmute" Label="Force Unmute" @bind-Value:after="OnSettingsValueChangeAsync"/>
</MudPaper>

@code {
Expand All @@ -114,11 +115,14 @@
set => ConfigManager.Config.Behaviour.RandomDuration = value == "Random Duration";
}

private void OnSettingsValueChange()
{
OsTask.Run(OnSettingsValueChangeAsync);
}

private async Task OnSettingsValueChange()
private Task OnSettingsValueChangeAsync()
{
await ConfigManager.SaveAsync();
await underscoreConfig.SendUpdateForAll();
return Task.WhenAll(ConfigManager.SaveAsync(), underscoreConfig.SendUpdateForAll());
}

protected override void OnInitialized()
Expand All @@ -135,5 +139,7 @@
{
UnderscoreConfig.OnConfigUpdate -= OnConfigUpdate;
}



}

0 comments on commit 8e9ae1f

Please sign in to comment.