Skip to content

Commit

Permalink
Small Module refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
VolcanicArts committed Jun 11, 2022
1 parent b1a0006 commit 247136c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
26 changes: 3 additions & 23 deletions VRCOSC.Game/Modules/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,9 @@ public abstract class Module

public bool HasAttributes => HasSettings || HasParameters;

public T GetDefaultSetting<T>(string key)
{
return (T)defaultSettings[key];
}
public T GetDefaultSetting<T>(string key) => (T)defaultSettings[key];

public string GetDefaultOutputParameter(string key)
{
return defaultOutputParameters[key];
}
public string GetDefaultOutputParameter(string key) => defaultOutputParameters[key];

internal void CreateAttributes()
{
Expand Down Expand Up @@ -149,10 +143,7 @@ protected virtual void OnIntParameterReceived(Enum key, int value) { }

protected virtual void OnFloatParameterReceived(Enum key, float value) { }

protected T GetSettingAs<T>(Enum key)
{
return DataManager.GetSettingAs<T>(key);
}
protected T GetSettingAs<T>(Enum key) => DataManager.GetSettingAs<T>(key);

protected void SendParameter(Enum key, int value) => sendParameter(key, value);

Expand All @@ -167,15 +158,4 @@ private void sendParameter(Enum key, object value)
OscClient.SendMessageAsync(message);
OnParameterSent?.Invoke(DataManager.GetParameter(key), value);
}

protected static int[] ToDigitArray(int num, int totalWidth)
{
var numStr = num.ToString().PadLeft(totalWidth, '0');
return numStr.Select(digit => int.Parse(digit.ToString())).ToArray();
}

protected static float MapBetween(float value, float sMin, float sMax, float dMin, float dMax)
{
return value / (sMax - sMin) * (dMax - dMin) + dMin;
}
}
2 changes: 1 addition & 1 deletion VRCOSC.Game/Modules/Modules/HypeRate/HypeRateModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void handleHeartRateUpdate(int heartrate)
{
receivedHeartrate = true;
var normalisedHeartRate = heartrate / 60.0f;
var individualValues = ToDigitArray(heartrate, 3);
var individualValues = ModuleHelper.ToDigitArray(heartrate, 3);

SendParameter(HypeRateParameter.HeartrateEnabled, true);
SendParameter(HypeRateParameter.HeartrateNormalised, normalisedHeartRate);
Expand Down
13 changes: 13 additions & 0 deletions VRCOSC.Game/Modules/Modules/ModuleHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) VolcanicArts. Licensed under the GPL-3.0 License.
// See the LICENSE file in the repository root for full license text.

using System.Linq;

namespace VRCOSC.Game.Modules.Modules;

public static class ModuleHelper
{
public static int[] ToDigitArray(int num, int totalWidth) => num.ToString().PadLeft(totalWidth, '0').Select(digit => int.Parse(digit.ToString())).ToArray();

public static float MapBetween(float value, float sMin, float sMax, float dMin, float dMax) => value / (sMax - sMin) * (dMax - dMin) + dMin;
}

0 comments on commit 247136c

Please sign in to comment.