From 50d0951b4a941947388918bcc635144ae3fae386 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Wed, 11 Sep 2024 07:31:30 -0700 Subject: [PATCH] Tweaks --- FakeeDeck/ButtonType/HelldiversTwoMacro.cs | 2 +- FakeeDeck/Class/KeyboardCode.cs | 2 +- FakeeDeck/Class/YamlConfig.cs | 73 ++++++++++++++++++++++ FakeeDeck/FakeeDeck.csproj | 3 + FakeeDeck/Program.cs | 12 +++- FakeeDeck/configuration.yaml | 26 ++++++++ 6 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 FakeeDeck/Class/YamlConfig.cs create mode 100644 FakeeDeck/configuration.yaml diff --git a/FakeeDeck/ButtonType/HelldiversTwoMacro.cs b/FakeeDeck/ButtonType/HelldiversTwoMacro.cs index 040397e..25a0926 100644 --- a/FakeeDeck/ButtonType/HelldiversTwoMacro.cs +++ b/FakeeDeck/ButtonType/HelldiversTwoMacro.cs @@ -15,7 +15,7 @@ namespace FakeeDeck.ButtonType public static Dictionary stratogems = new Dictionary { - { "reinforce", new uint[] { KeyboardCode.NUMPAD5, 0x68, 0x62, 0x66, 0x64, 0x68}}, + { "reinforce", new uint[] { 0x65, 0x68, 0x62, 0x66, 0x64, 0x68}}, { "resupply", new uint[] { 0x65, 0x62, 0x62, 0x68, 0x66 }}, //Patriotic Administration Center { "anti-material", new uint[] { 0x65, 0x62, 0x64, 0x66, 0x68, 0x62}}, diff --git a/FakeeDeck/Class/KeyboardCode.cs b/FakeeDeck/Class/KeyboardCode.cs index a690955..0745c19 100644 --- a/FakeeDeck/Class/KeyboardCode.cs +++ b/FakeeDeck/Class/KeyboardCode.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace FakeeDeck.Class { - internal class Keyboard + internal class KeyboardCode { public const uint LBUTTON = 0x01; // Left mouse button public const uint RBUTTON = 0x02; // Right mouse button diff --git a/FakeeDeck/Class/YamlConfig.cs b/FakeeDeck/Class/YamlConfig.cs new file mode 100644 index 0000000..b018340 --- /dev/null +++ b/FakeeDeck/Class/YamlConfig.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection.Metadata.Ecma335; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; +using static System.Runtime.InteropServices.JavaScript.JSType; + +namespace FakeeDeck.Class +{ + internal class YamlConfig + { + public Dictionary Data { get; private set; } + public YamlConfig(string path) + { + Data = new Dictionary(); + ParseYamlFile(File.ReadAllLines(path)); + } + private Dictionary ParseYamlFile(string[] lines, int levelStart = 0, int linesParsedPreviuse = 0) + { + Dictionary tempObject = new Dictionary(); + + int linesParsed = 0; + + if ((linesParsed + linesParsedPreviuse) <= lines.Length) + { + int level = 0; + int iterator = 0; + foreach (string line in lines) + { + level = line.Count(x => x == '\t'); + + linesParsed++; + if (string.IsNullOrEmpty(line)) + { + continue; + } + + Console.WriteLine(level + "> level " + linesParsedPreviuse + " Lines handeled previouselly '" + line + "'"); + + if ((level > levelStart || level == 0)) + { + if (line.Contains(":")) + { + iterator = 0; + string[] array = line.Split(":"); + string key = array[0]; + dynamic value = ""; + + if (array.Length > 0) + { + tempObject[key] = array[1]; + } + else if (array.Length == 1 && lines[linesParsed..lines.Length].Length > 0) + { + tempObject[key] = ParseYamlFile(lines[linesParsed..lines.Length], level, linesParsed); + } + } else + { + iterator++; + tempObject[iterator] = line; + } + } + } + } + + Debug.WriteLine(JsonSerializer.Serialize(tempObject)); + return tempObject; + } + } +} diff --git a/FakeeDeck/FakeeDeck.csproj b/FakeeDeck/FakeeDeck.csproj index e6c7a7a..37c5875 100644 --- a/FakeeDeck/FakeeDeck.csproj +++ b/FakeeDeck/FakeeDeck.csproj @@ -12,6 +12,9 @@ + + PreserveNewest + PreserveNewest diff --git a/FakeeDeck/Program.cs b/FakeeDeck/Program.cs index edb43d6..4119387 100644 --- a/FakeeDeck/Program.cs +++ b/FakeeDeck/Program.cs @@ -1,3 +1,13 @@ using FakeeDeck; +using FakeeDeck.Class; +using System.Diagnostics; +using System.Text.Json; -HttpServer.serv(); \ No newline at end of file + +YamlConfig parser = new YamlConfig("configuration.yaml"); +var result = parser.Data; + +Console.WriteLine(JsonSerializer.Serialize(result)); + + +HttpServer.serv(); diff --git a/FakeeDeck/configuration.yaml b/FakeeDeck/configuration.yaml new file mode 100644 index 0000000..b498e54 --- /dev/null +++ b/FakeeDeck/configuration.yaml @@ -0,0 +1,26 @@ +server: + port: 8000 + +pages: + - helldivers: + - test1: + name: test + type: keyboard + url: https://www.reddit.com/r/kde/comments/fen7lj/plasmoid_for_managing_docker_containers/ + action: + - 0x31 + - 0x31 + - test2: + name: test2 + type: keyboard + url: https://www.reddit.com/ + action: + - 0x31 + - 0x31 + - media: + - mute: + name: mute + type: keyboard + url: https://www.reddit.com/r/kde/comments/fen7lj/plasmoid_for_managing_docker_containers/ + action: + - 0x33 \ No newline at end of file