Skip to content

Commit

Permalink
Refactored code and updated version in MagicChatbox.csproj
Browse files Browse the repository at this point in the history
Updated `DataController.cs` for better readability and restructured `SuperscriptMapping` dictionary. Moved `if` statement inside `else` block in `OSCController.cs` for better code organization. Refactored `VRChatOSCQuerySettings` class in `VRChatOSCQuery.cs` to use a `Lazy` instance for loading settings and updated `LoadSettings` and `SaveSettings` methods for better error handling. Replaced `OnAvatarChanged` method with `RefreshAvatarParameters` method. Incremented version number in `MagicChatbox.csproj` from `0.8.885` to `0.8.886`.
  • Loading branch information
BoiHanny committed May 27, 2024
1 parent d6674a8 commit c59f0a8
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 86 deletions.
20 changes: 10 additions & 10 deletions vrcosc-magicchatbox/Classes/DataAndSecurity/DataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ public static class DataController
public static SoundpadModule soundpadModule = null;

private static readonly Dictionary<char, string> SuperscriptMapping = new Dictionary<char, string>
{
{'/', "·"}, {':', "'"}, {'a', "ᵃ"}, {'b', "ᵇ"}, {'c', "ᶜ"}, {'d', "ᵈ"}, {'e', "ᵉ"},
{'f', "ᶠ"}, {'g', "ᵍ"}, {'h', "ʰ"}, {'i', "ⁱ"}, {'j', "ʲ"},
{'k', "ᵏ"}, {'l', "ˡ"}, {'m', "ᵐ"}, {'n', "ⁿ"}, {'o', "ᵒ"},
{'p', "ᵖ"}, {'q', "ᵒ"}, {'r', "ʳ"}, {'s', "ˢ"}, {'t', "ᵗ"},
{'u', "ᵘ"}, {'v', "ᵛ"}, {'w', "ʷ"}, {'x', "ˣ"}, {'y', "ʸ"},
{'z', "ᶻ"}, {'0', "⁰"}, {'1', "¹"}, {'2', "²"}, {'3', "³"},
{'4', "⁴"}, {'5', "⁵"}, {'6', "⁶"}, {'7', "⁷"}, {'8', "⁸"},
{'9', "⁹"}, {',', "'"}, {'.', "'"} , {'%', "⁒"}
};
{
{'/', "·"}, {':', "'"}, {'a', "ᵃ"}, {'b', "ᵇ"}, {'c', "ᶜ"}, {'d', "ᵈ"}, {'e', "ᵉ"},
{'f', "ᶠ"}, {'g', "ᵍ"}, {'h', "ʰ"}, {'i', "ⁱ"}, {'j', "ʲ"},
{'k', "ᵏ"}, {'l', "ˡ"}, {'m', "ᵐ"}, {'n', "ⁿ"}, {'o', "ᵒ"},
{'p', "ᵖ"}, {'q', "ᵒ"}, {'r', "ʳ"}, {'s', "ˢ"}, {'t', "ᵗ"},
{'u', "ᵘ"}, {'v', "ᵛ"}, {'w', "ʷ"}, {'x', "ˣ"}, {'y', "ʸ"},
{'z', "ᶻ"}, {'0', "⁰"}, {'1', "¹"}, {'2', "²"}, {'3', "³"},
{'4', "⁴"}, {'5', "⁵"}, {'6', "⁶"}, {'7', "⁷"}, {'8', "⁸"},
{'9', "⁹"}, {',', "'"}, {'.', "'"} , {'%', "⁒"}
};


public static string GetApplicationVersion()
Expand Down
8 changes: 4 additions & 4 deletions vrcosc-magicchatbox/Classes/DataAndSecurity/OSCController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ public static void AddMediaLink(List<string> Uncomplete)
x = ViewModel.Instance.PrefixIconMusic
? $"{prefix} '{mediaLinkTitle}'"
: $"{mediaAction} '{mediaLinkTitle}'";
}

if (!mediaSession.IsLiveTime && mediaSession.TimePeekEnabled)
{
x = CreateTimeStamp(x, mediaSession, ViewModel.Instance.MediaLinkTimeSeekStyle);
if (!mediaSession.IsLiveTime && mediaSession.TimePeekEnabled)
{
x = CreateTimeStamp(x, mediaSession, ViewModel.Instance.MediaLinkTimeSeekStyle);
}
}
}

Expand Down
131 changes: 60 additions & 71 deletions vrcosc-magicchatbox/Classes/DataAndSecurity/VRChatOSCQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,73 +7,70 @@
//using Microsoft.Extensions.Logging.Abstractions;
//using System.Collections.Generic;
//using System.Net;
//using System.Threading.Tasks;

//namespace vrcosc_magicchatbox.Classes.DataAndSecurity
//{
// public partial class VRChatOSCQuerySettings : ObservableObject
// {
// private const string SettingsFileName = "VRChatOSCQuerySettings.json";
// public partial class VRChatOSCQuerySettings : ObservableObject
// {
// private const string SettingsFileName = "VRChatOSCQuerySettings.json";
// private static readonly Lazy<VRChatOSCQuerySettings> _instance = new Lazy<VRChatOSCQuerySettings>(LoadSettings);

// [ObservableProperty]
// private string oSCAddress;
// public static VRChatOSCQuerySettings Instance => _instance.Value;

// [ObservableProperty]
// private int oSCPort;
// [ObservableProperty]
// private string oSCAddress;

// private VRChatOSCQuerySettings()
// {
// // Load settings from file during initialization
// LoadSettings();
// }
// [ObservableProperty]
// private int oSCPort;

// // Singleton pattern to ensure a single instance of settings
// public static VRChatOSCQuerySettings Instance { get; } = LoadSettings();
// private VRChatOSCQuerySettings() { }

// private static VRChatOSCQuerySettings LoadSettings()
// private static VRChatOSCQuerySettings LoadSettings()
// {
// var path = GetSettingsFilePath();

// if (File.Exists(path))
// {
// var path = GetSettingsFilePath();
// var settingsJson = File.ReadAllText(path);

// if (File.Exists(path))
// if (string.IsNullOrWhiteSpace(settingsJson) || settingsJson.All(c => c == '\0'))
// {
// var settingsJson = File.ReadAllText(path);

// if (string.IsNullOrWhiteSpace(settingsJson) || settingsJson.All(c => c == '\0'))
// {
// Logging.WriteInfo("The settings JSON file is empty or corrupted.");
// return new VRChatOSCQuerySettings();
// }
// Logging.WriteInfo("The settings JSON file is empty or corrupted.");
// return new VRChatOSCQuerySettings();
// }

// try
// {
// var settings = JsonConvert.DeserializeObject<VRChatOSCQuerySettings>(settingsJson);
// return settings ?? new VRChatOSCQuerySettings();
// }
// catch (JsonException ex)
// {
// Logging.WriteInfo($"Error parsing settings JSON: {ex.Message}");
// return new VRChatOSCQuerySettings();
// }
// try
// {
// var settings = JsonConvert.DeserializeObject<VRChatOSCQuerySettings>(settingsJson);
// return settings ?? new VRChatOSCQuerySettings();
// }
// else
// catch (JsonException ex)
// {
// Logging.WriteInfo("Settings file does not exist, returning new settings instance.");
// Logging.WriteInfo($"Error parsing settings JSON: {ex.Message}");
// return new VRChatOSCQuerySettings();
// }
// }

// public void SaveSettings()
// else
// {
// var path = GetSettingsFilePath();
// Directory.CreateDirectory(Path.GetDirectoryName(path));
// var settingsJson = JsonConvert.SerializeObject(this, Formatting.Indented);
// File.WriteAllText(path, settingsJson);
// Logging.WriteInfo("Settings file does not exist, returning new settings instance.");
// return new VRChatOSCQuerySettings();
// }
// }

// private static string GetSettingsFilePath() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Vrcosc-MagicChatbox", SettingsFileName);
// public void SaveSettings()
// {
// var path = GetSettingsFilePath();
// Directory.CreateDirectory(Path.GetDirectoryName(path));
// var settingsJson = JsonConvert.SerializeObject(this, Formatting.Indented);
// File.WriteAllText(path, settingsJson);
// }

// private static string GetSettingsFilePath() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Vrcosc-MagicChatbox", SettingsFileName);
// }


//public partial class VRChatOSCQuery : ObservableObject, IDisposable
// public partial class VRChatOSCQuery : ObservableObject, IDisposable
// {
// private readonly OSCQueryService _oscQueryService;
// private readonly Dictionary<string, OSCQueryNode> _avatarParameters = new();
Expand All @@ -84,17 +81,12 @@
// {
// _oscQueryService = new OSCQueryServiceBuilder()
// .WithDefaults()
// .WithServiceName("MyOSCService")
// .WithLogger(new NullLogger<OSCQueryService>())
// .WithServiceName("MCb-client")
// .Build();

// _oscQueryService.OnOscServiceAdded += OnOscServiceDiscovered;
// _oscQueryService.OnOscQueryServiceAdded += OnOscQueryServiceDiscovered;

// var rootNode = _oscQueryService.RootNode;
// var avatarChangeNode = new OSCQueryNode("/avatar/change");
// avatarChangeNode.OnValueChangedEvent += OnAvatarChanged;
// rootNode.AddNode(avatarChangeNode);
// _oscQueryService.RootNode.AddNode(new OSCQueryNode("/avatar/change"));
// }

// private void OnOscServiceDiscovered(OSCQueryServiceProfile profile)
Expand All @@ -107,40 +99,37 @@
// Console.WriteLine($"Discovered OSCQuery service: {profile.name} at {profile.address}:{profile.port}");
// }

// private async void OnAvatarChanged(object sender, ValueChangedEventArgs args)
// public async Task RefreshAvatarParameters()
// {
// string avatarId = (string)args.Value;
// Console.WriteLine($"Avatar changed to: {avatarId}");

// _avatarParameters.Clear();

// IPAddress ip = _oscQueryService.HostIP;
// int port = _oscQueryService.TcpPort;
// var oscTree = await Extensions.GetOSCTree(ip, port);

// var parameterNodes = oscTree.GetNodeWithPath("/avatar/parameters")?.Contents;
// if (parameterNodes != null)
// try
// {
// foreach (var paramNode in parameterNodes.Values)
// var ip = _oscQueryService.HostIP;
// var port = _oscQueryService.TcpPort;
// var oscTree = await Extensions.GetOSCTree(ip, port);

// var parameterNodes = oscTree.GetNodeWithPath("/avatar/parameters")?.Contents;
// if (parameterNodes != null)
// {
// _avatarParameters[paramNode.Name] = paramNode;
// paramNode.OnValueChangedEvent += OnAvatarParameterValueChanged;
// foreach (var paramNode in parameterNodes.Values)
// {
// _avatarParameters[paramNode.Name] = paramNode;
// }
// }
// }
// }

// private void OnAvatarParameterValueChanged(object sender, ValueChangedEventArgs args)
// {
// var node = (OSCQueryNode)sender;
// string parameterName = node.Name;
// OnAvatarParameterChanged?.Invoke(parameterName, args.Value);
// catch (Exception ex)
// {
// Console.WriteLine($"Error refreshing avatar parameters: {ex.Message}");
// }
// }

// public void SetAvatarParameter<T>(string parameterName, T value)
// {
// if (_avatarParameters.TryGetValue(parameterName, out var node))
// {
// node.Value = new object[] { value };
// OnAvatarParameterChanged?.Invoke(parameterName, value);
// }
// else
// {
Expand Down
2 changes: 1 addition & 1 deletion vrcosc-magicchatbox/MagicChatbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<Version>0.8.885</Version>
<Version>0.8.886</Version>
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
<RootNamespace>vrcosc_magicchatbox</RootNamespace>
<Nullable>enable</Nullable>
Expand Down

0 comments on commit c59f0a8

Please sign in to comment.