Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for PhysBones handling. #37

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ShockOsc/Config/BehaviourConf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public sealed class BehaviourConf
public uint HoldTime { get; set; } = 250;
public uint CooldownTime { get; set; } = 5000;
public BoneHeldAction WhileBoneHeld { get; set; } = BoneHeldAction.Vibrate;
public bool SuppressPhysBoneReleaseAction { get; set; }
public bool DisableWhileAfk { get; set; } = true;
public bool ForceUnmute { get; set; }

Expand Down
5 changes: 4 additions & 1 deletion ShockOsc/Config/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ public sealed class Group

public bool OverrideCooldownTime { get; set; }
public uint CooldownTime { get; set; } = 5000;
}

public bool OverridePhysBoneReleaseAction { get; set; }
public bool SuppressPhysBoneReleaseAction { get; set; }
}
1 change: 1 addition & 0 deletions ShockOsc/Models/ProgramGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public sealed class ProgramGroup
public DateTime LastActive { get; set; }
public DateTime LastExecuted { get; set; }
public DateTime LastVibration { get; set; }
public DateTime PhysBoneGrabLimitTime { get; set; }
public ushort LastDuration { get; set; }
public byte LastIntensity { get; set; }
public float LastStretchValue { get; set; }
Expand Down
18 changes: 17 additions & 1 deletion ShockOsc/Services/ShockOsc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,13 @@ private async Task ReceiveLogic()
}
}

if (!programGroup.IsGrabbed && isGrabbed)
{
// on physbone grab
ushort TheDuration = GetDuration(programGroup);
programGroup.PhysBoneGrabLimitTime = DateTime.UtcNow.AddMilliseconds(TheDuration);
_logger.LogDebug("Limiting hold duration of Group {Group} to {Duration}ms", programGroup.Name, TheDuration);
}
programGroup.IsGrabbed = isGrabbed;
return;
// Normal shocker actions
Expand Down Expand Up @@ -540,10 +547,12 @@ private async Task CheckProgramGroup(ProgramGroup programGroup, Guid pos, Behavi
_configManager.Config.Behaviour.WhileBoneHeld !=
BehaviourConf.BoneHeldAction.None &&
!isActiveOrOnCooldown &&
!_underscoreConfig.KillSwitch &&
programGroup.IsGrabbed &&
programGroup.PhysBoneGrabLimitTime > DateTime.UtcNow &&
programGroup.LastVibration < DateTime.UtcNow.Subtract(TimeSpan.FromMilliseconds(100)))
{
var pullIntensityTranslated = Math.Max(Convert.ToByte(programGroup.LastStretchValue * 100f), (byte)1);
var pullIntensityTranslated = GetPhysbonePullIntensity(programGroup, programGroup.LastStretchValue);
programGroup.LastVibration = DateTime.UtcNow;

_logger.LogDebug("Vibrating/Shocking {Shocker} at {Intensity}", pos, pullIntensityTranslated);
Expand Down Expand Up @@ -586,6 +595,13 @@ private async Task CheckProgramGroup(ProgramGroup programGroup, Guid pos, Behavi

if (programGroup.TriggerMethod == TriggerMethod.PhysBoneRelease)
{
programGroup.TriggerMethod = TriggerMethod.None;
if (programGroup.ConfigGroup is { OverridePhysBoneReleaseAction: true } ? programGroup.ConfigGroup is { SuppressPhysBoneReleaseAction: true } : _configManager.Config.Behaviour.SuppressPhysBoneReleaseAction)
{
programGroup.LastExecuted = DateTime.UtcNow;
programGroup.LastDuration = 0;
return;
}
intensity = GetPhysbonePullIntensity(programGroup, programGroup.LastStretchValue);
programGroup.LastStretchValue = 0;

Expand Down
5 changes: 3 additions & 2 deletions ShockOsc/Ui/Pages/Dash/Tabs/ConfigTab.razor
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
}
</MudSelect>
</MudPaper>
<MudCheckBox @bind-Value="ConfigManager.Config.Behaviour.SuppressPhysBoneReleaseAction" Class="checkbox-title" Label="Suppress PhysBone Release Action" @bind-Value:after="OnSettingsValueChangeAsync" />

<br/>
<br/>
<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="OnSettingsValueChangeAsync">
<MudToggleGroup T="string" @bind-Value="RandomIntensityString" Style="width: 330px; margin: 30px 0 0 10px;" Delimiters="true" Rounded="true" CheckMark="false" FixedContent="false" @bind-Value:after="OnSettingsValueChangeAsync">
<MudToggleItem Value="@("Fixed Intensity")"/>
<MudToggleItem Value="@("Random Intensity")"/>
</MudToggleGroup>
Expand Down Expand Up @@ -58,7 +59,7 @@
}


<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">
<MudToggleGroup T="string" @bind-Value="RandomDurationString" Style="width: 330px; margin: 30px 0 0 10px;" Delimiters="true" Rounded="true" CheckMark="false" FixedContent="false" @bind-Value:after="OnSettingsValueChangeAsync">
<MudToggleItem Value="@("Fixed Duration")"/>
<MudToggleItem Value="@("Random Duration")"/>
</MudToggleGroup>
Expand Down
15 changes: 13 additions & 2 deletions ShockOsc/Ui/Pages/Dash/Tabs/GroupsTab.razor
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<div class="d-flex" style="justify-content: space-between">

<MudToggleGroup T="string" @bind-Value="CurrentRandomIntensityString" Style="width: 330px; margin: 0 0 0 10px;"
Outline="true" Delimiters="true" Dense="true" Rounded="true" CheckMark="false" FixedContent="false" @bind-Value:after="OnGroupSettingsValueChange">
Delimiters="true" Rounded="true" CheckMark="false" FixedContent="false" @bind-Value:after="OnGroupSettingsValueChange">
<MudToggleItem Value="@("Fixed Intensity")"/>
<MudToggleItem Value="@("Random Intensity")"/>
</MudToggleGroup>
Expand Down Expand Up @@ -198,7 +198,7 @@
<div class="d-flex" style="justify-content: space-between">

<MudToggleGroup T="string" @bind-Value="CurrentRandomDurationString" Style="width: 330px; margin: 0 0 0 10px;"
Outline="true" Delimiters="true" Dense="true" Rounded="true" CheckMark="false" FixedContent="false" @bind-Value:after="OnGroupSettingsValueChange">
Delimiters="true" Rounded="true" CheckMark="false" FixedContent="false" @bind-Value:after="OnGroupSettingsValueChange">
<MudToggleItem Value="@("Fixed Duration")"/>
<MudToggleItem Value="@("Random Duration")"/>
</MudToggleGroup>
Expand Down Expand Up @@ -244,6 +244,17 @@
</MudCollapse>
</MudPaper>

<MudPaper Outlined="true" Class="rounded-lg mud-paper-padding-margin">
<MudCheckBox Class="checkbox-title" @bind-Value="@CurrentGroup.OverridePhysBoneReleaseAction" Label="Override PhysBone Release Action" @bind-Value:after="OnGroupSettingsValueChange" />
<MudDivider />
<MudCollapse Expanded="CurrentGroup.OverridePhysBoneReleaseAction">
<br/>

<MudCheckBox Class="checkbox-title" @bind-Value="@CurrentGroup.SuppressPhysBoneReleaseAction" Label="Suppress PhysBone Release Action" @bind-Value:after="OnGroupSettingsValueChange" />

</MudCollapse>
</MudPaper>

<MudPaper Outlined="true" Class="rounded-lg mud-paper-padding-margin">
<MudText>Shockers in Group</MudText>
<MudDivider/>
Expand Down