Skip to content

Commit

Permalink
Cooldown System
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenithVal committed Mar 14, 2024
1 parent 255af0c commit cdf3e6c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Configs/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public static void Reset() {
readout_parameter = "/avatar/parameters/timer_readout",
readout_parameter2 = "",

cooldown_parameter = "",

readout_interval = 500
}
}));
Expand Down
2 changes: 2 additions & 0 deletions Configs/TimerMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class TimerMode {
public int readout_mode { get; set; }
public string readout_parameter { get; set; }
public string readout_parameter2 { get; set; }
public string cooldown_parameter { get; set; }



[TomlInlineComment("Time (miliseconds) between outgoing messages")]
Expand Down
54 changes: 45 additions & 9 deletions Logic/OSCTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,34 @@ public static class OSCTimer {
private static int inc_step;
private static string dec_parameter;
private static int dec_step;
private static float input_delay;
private static float input_cooldown;

private static int readout_mode;
private static string readout_parameter;
private static string readout_parameter2;

private static bool cooldown_tracker;
private static string cooldown_parameter;
private static DateTime cooldownEndTime = DateTime.Now;

private static int starting_time;
private static int random_min;
private static int random_max;

private static DateTime lastAdded = DateTime.Now;

public static async Task OnIncParam(OscMessage message) {
var shouldAdd = (bool)message.Arguments[0];
if (shouldAdd) {
Console.WriteLine($"Param recieved - Attempting to add {inc_step} seconds(s)");
if (input_delay > 0 && DateTime.Now < lastAdded) {
ColorConsole.WithYellowText.WriteLine($"Restricted by input delay until: " + lastAdded);
} else AddTime(inc_step);

if (input_cooldown > 0 && DateTime.Now < cooldownEndTime)
{
ColorConsole.WithYellowText.WriteLine($"Restricted by input cooldown until: " + cooldownEndTime);
}
else
{
AddTime(inc_step);
cooldownEndTime = DateTime.Now.AddMilliseconds(input_cooldown);
}
}
}

Expand Down Expand Up @@ -110,16 +119,20 @@ public static void Setup() {
Console.WriteLine($"Address: {handler.Key} | Value: {handler.Value}");
}

input_delay = timerConfig.input_cooldown;
Console.WriteLine($"input_delay: {input_delay}\n");
input_cooldown = timerConfig.input_cooldown;
Console.WriteLine($"input_cooldoown: {input_cooldown}\n");

readout_mode = timerConfig.readout_mode;
readout_parameter = timerConfig.readout_parameter;
readout_parameter2 = timerConfig.readout_parameter2;

cooldown_parameter = timerConfig.cooldown_parameter;

Console.WriteLine($"readout_mode: {readout_mode}");
Console.WriteLine($"readout_parameter: {readout_parameter}");
Console.WriteLine($"readout_parameter2: {readout_parameter2}\n");
Console.WriteLine($"readout_parameter2: {readout_parameter2}");
Console.WriteLine($"cooldown_parameter: {cooldown_parameter}");
Console.WriteLine();

if (readout_parameter != "" && ConfigManager.ApplicationConfig.oscQuery) {
VRChatConnector.ModifyEndPoint(true, readout_parameter, "f", Attributes.AccessValues.ReadOnly, "OSCLock Readout Param 1");
Expand Down Expand Up @@ -419,6 +432,29 @@ private static async void OnProgress(object sender, ElapsedEventArgs elapsedEven

var remainingTime = ((EndTime - DateTime.Now).TotalMinutes);

// Cooldown readout
if (cooldown_parameter != "" && input_cooldown > 0) // output true if on cooldown
{
if (DateTime.Now < cooldownEndTime)
{
if (!cooldown_tracker)
{
var message = new OscMessage(cooldown_parameter, true);
VRChatConnector.SendToVRChat(message);
cooldown_tracker = true;
}
}
else
{
if (cooldown_tracker)
{
var message = new OscMessage(cooldown_parameter, false);
VRChatConnector.SendToVRChat(message);
cooldown_tracker = false;
}
}
}


try
{
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ Tables containing information on all available settings you can change in the co
| inc_step | Time in seconds to add (int) | 60 |
| dec_parameter | When this Bool is true via OSC, it should decrease the timer. | "" |
| dec_step | Time in seconds to subtract (int) | 300 |
| input_delay | Minimum cooldown between allowed inputs. | 1500 |
| input_cooldown | Minimum cooldown between allowed inputs. | 1500 |
| | | |
| readout_mode | Method of translating time remaining via OSC. Chart below | 0 |
| readout_parameter | Readout parameter 1 | "" |
| readout_parameter2 | Readout parameter 2 (optional) | "" |
| | | |
| cooldown_parameter | True while cooldown is active | "" |
| readout_interval | Time in miliseconds between parameter updates. | 500 |
</details>

Expand Down

0 comments on commit cdf3e6c

Please sign in to comment.