From 0918ac5a802038be54587412c81700928a090831 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Thu, 12 Sep 2024 08:48:11 -0700 Subject: [PATCH] Progression And Cleanup --- FakeeDeck/ButtonType/HelldiversTwoMacro.cs | 55 ++++++++++++++------ FakeeDeck/Class/AbstractionHelper.cs | 41 +++++++++++++++ FakeeDeck/Class/FakeDeck.cs | 18 ++++++- FakeeDeck/Class/HttpServer.cs | 3 +- FakeeDeck/Class/YamlHelper.cs | 28 +++++++++++ FakeeDeck/configuration.yaml | 58 ++++++++++++++++++++-- 6 files changed, 181 insertions(+), 22 deletions(-) create mode 100644 FakeeDeck/Class/AbstractionHelper.cs create mode 100644 FakeeDeck/Class/YamlHelper.cs diff --git a/FakeeDeck/ButtonType/HelldiversTwoMacro.cs b/FakeeDeck/ButtonType/HelldiversTwoMacro.cs index 25a0926..19e41dc 100644 --- a/FakeeDeck/ButtonType/HelldiversTwoMacro.cs +++ b/FakeeDeck/ButtonType/HelldiversTwoMacro.cs @@ -10,27 +10,45 @@ namespace FakeeDeck.ButtonType { class HelldiversTwoMacro : Button { + const uint Key_Up = 0x68; + const uint Key_Down = 0x62; + const uint Key_Left = 0x64; + const uint Key_Right = 0x66; + //https://helldivers.wiki.gg/wiki/Stratagems //https://helldivers.fandom.com/wiki/Stratagems_(Helldivers_2) public static Dictionary stratogems = new Dictionary { - { "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}}, - { "flamethrower", new uint[] { 0x65, 0x62, 0x64, 0x68, 0x62, 0x68}}, - { "autocannon", new uint[] { 0x65, 0x62, 0x64, 0x62, 0x68, 0x68, 0x66}}, - { "grenade-launcher", new uint[] { 0x65, 0x62, 0x64, 0x68, 0x64, 0x62}}, + //Mission + { "reinforce", new uint[] { 0x65, Key_Up, Key_Down, Key_Right, Key_Left, Key_Up}}, + { "resupply", new uint[] { 0x65, Key_Down, Key_Down, Key_Up, Key_Right }}, + + //Support Weapons + { "anti-material", new uint[] { 0x65, Key_Down, Key_Left, Key_Right, Key_Up, Key_Down}}, + { "flamethrower", new uint[] { 0x65, Key_Down, Key_Left, Key_Up, Key_Down, Key_Up}}, + { "autocannon", new uint[] { 0x65, Key_Down, Key_Left, Key_Down, Key_Up, Key_Up, Key_Right}}, + { "grenade-launcher", new uint[] { 0x65, Key_Down, Key_Left, Key_Up, Key_Left, Key_Down}}, + + //Offensive: Orbital Strikes + { "orbital-precision-strike", new uint[] { 0x65, Key_Right, Key_Right, Key_Up}}, + + //Defensive + { "mortar-sentry", new uint[] { 0x65, Key_Down, Key_Up, Key_Right, Key_Down}}, + { "gatling-sentry", new uint[] { 0x65, Key_Down, Key_Up, Key_Right, Key_Left}}, + + + //Supply: Backpacks + + //Offensive: Eagle + { "strafing-run", new uint[] { 0x65, Key_Up, Key_Right, Key_Right}}, + { "airstrike", new uint[] { 0x65, Key_Up, Key_Right, Key_Down, Key_Right}}, + { "cluster-bomb", new uint[] { 0x65, Key_Up, Key_Right, Key_Down, Key_Down, Key_Right}}, + { "napalm-airstrike", new uint[] { 0x65, Key_Up, Key_Right, Key_Down, Key_Up}}, + { "smoke-strike", new uint[] { 0x65, Key_Up, Key_Right, Key_Up, Key_Down}}, + { "rocket-pods", new uint[] { 0x65, Key_Up, Key_Right, Key_Up, Key_Left}}, + { "bomb", new uint[] { 0x65, Key_Up, Key_Right, Key_Up, Key_Right}}, - //Orbital Cannons - { "orbital-precision-strike", new uint[] { 0x65, 0x66, 0x66, 0x68}}, - //Robotics Workshop - { "mortar-sentry", new uint[] { 0x65, 0x62, 0x68, 0x66, 0x62}}, - { "gatling-sentry", new uint[] { 0x65, 0x62, 0x68, 0x66, 0x64}}, - //Hangar - { "rocket-pods", new uint[] { 0x65, 0x68, 0x66, 0x68, 0x64}}, - { "bomb", new uint[] { 0x65, 0x68, 0x66, 0x68, 0x64}}, }; public static Dictionary stratogemsIcons = new Dictionary @@ -44,6 +62,13 @@ namespace FakeeDeck.ButtonType { "orbital-precision-strike", "https://static.wikia.nocookie.net/helldivers_gamepedia/images/4/47/Orbital_Precision_Strike_Icon.png"}, { "mortar-sentry", "https://static.wikia.nocookie.net/helldivers_gamepedia/images/1/1d/A_M-12_Mortar_Sentry_Icon.png"}, { "gatling-sentry","https://static.wikia.nocookie.net/helldivers_gamepedia/images/4/48/A_G-16_Gatling_Sentry_Icon.png"}, + + //Offensive: Eagle + { "strafing-run","https://static.wikia.nocookie.net/helldivers_gamepedia/images/3/33/Eagle_Strafing_Run_Icon.png"}, + { "airstrike","https://static.wikia.nocookie.net/helldivers_gamepedia/images/7/7e/Eagle_Airstrike_Icon.png"}, + { "cluster-bomb","https://static.wikia.nocookie.net/helldivers_gamepedia/images/8/89/Eagle_Cluster_Bomb_Icon.png"}, + { "napalm-airstrike","https://static.wikia.nocookie.net/helldivers_gamepedia/images/d/d4/Eagle_Napalm_Airstrike_Icon.png"}, + { "smoke-strike","https://static.wikia.nocookie.net/helldivers_gamepedia/images/1/1a/Eagle_Smoke_Strike_Icon.png"}, { "rocket-pods","https://static.wikia.nocookie.net/helldivers_gamepedia/images/e/e3/Eagle_110MM_Rocket_Pods_Icon.png"}, { "bomb","https://static.wikia.nocookie.net/helldivers_gamepedia/images/5/5a/Eagle_500KG_Bomb_Icon.png"}, }; diff --git a/FakeeDeck/Class/AbstractionHelper.cs b/FakeeDeck/Class/AbstractionHelper.cs new file mode 100644 index 0000000..0aaece1 --- /dev/null +++ b/FakeeDeck/Class/AbstractionHelper.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace FakeeDeck.Class +{ + internal class AbstractionHelper + { + public static Type? resolvType(string className) + { + string cleanClass = "FakeeDeck.ButtonType." + className.Trim('/'); + + Type? buttonClass = Type.GetType(cleanClass, true); + + if (buttonClass is null) + return null; + + return buttonClass; + } + + public static string getButtonVisual(JsonElement button) + { + string calssName = button.GetProperty("function").ToString(); + MethodInfo? renderMethod = AbstractionHelper.resolvType(calssName).GetMethod("getButton"); + ParameterInfo[] pars = renderMethod.GetParameters(); + List parameters = new List(); + + foreach (ParameterInfo p in pars) + { + JsonElement parameter = button.GetProperty("parameters").EnumerateArray().SingleOrDefault(item => item.GetProperty("name").ToString() == p.Name); + parameters.Insert(p.Position, parameter.GetProperty("value").ToString()); + } + + return renderMethod.Invoke(null, [.. parameters]).ToString(); + } + } +} diff --git a/FakeeDeck/Class/FakeDeck.cs b/FakeeDeck/Class/FakeDeck.cs index 9b0fb89..e40fccc 100644 --- a/FakeeDeck/Class/FakeDeck.cs +++ b/FakeeDeck/Class/FakeDeck.cs @@ -10,6 +10,7 @@ using System.IO; using System.Text.Json; using System.Reflection; using FakeeDeck.ButtonType; +using YamlDotNet.Serialization; namespace FakeeDeck.Class { @@ -17,9 +18,20 @@ namespace FakeeDeck.Class { public FakeDeck() { + + YamlHelper yaml = new YamlHelper(); HttpServer server = new HttpServer(); - foreach (var stratogem in HelldiversTwoMacro.stratogems) + foreach (JsonElement item in yaml.getData().GetProperty("pages").EnumerateArray()) + { + Debug.WriteLine("PAGE: " + item.GetProperty("page")); + foreach (JsonElement button in item.GetProperty("buttons").EnumerateArray()) + { + server.pageData += AbstractionHelper.getButtonVisual(button); + } + } + + /*foreach (var stratogem in HelldiversTwoMacro.stratogems) { server.pageData += HelldiversTwoMacro.getButton(stratogem.Key); } @@ -27,9 +39,11 @@ namespace FakeeDeck.Class foreach (var control in MediaMacro.mediaControls) { server.pageData += MediaMacro.getButton(control.Key); - } + }*/ server.serv(); } + + } } diff --git a/FakeeDeck/Class/HttpServer.cs b/FakeeDeck/Class/HttpServer.cs index 7a0d73d..50844f4 100644 --- a/FakeeDeck/Class/HttpServer.cs +++ b/FakeeDeck/Class/HttpServer.cs @@ -17,6 +17,7 @@ using System.Reflection.Metadata; using System.Xml.Linq; using System.Reflection; using System.Text.Json; +using System.Collections; namespace FakeeDeck.Class { @@ -118,7 +119,7 @@ namespace FakeeDeck.Class " " + ""; public string pageData = ""; - + private Dictionary> routes; public async Task HandleIncomingConnections() { bool runServer = true; diff --git a/FakeeDeck/Class/YamlHelper.cs b/FakeeDeck/Class/YamlHelper.cs new file mode 100644 index 0000000..d38d842 --- /dev/null +++ b/FakeeDeck/Class/YamlHelper.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; +using YamlDotNet.Serialization; + +namespace FakeeDeck.Class +{ + internal class YamlHelper + { + JsonDocument jsonObjecz; + public YamlHelper() + { + var r = new StreamReader("./configuration.yaml"); + var deserializer = new Deserializer(); + object yamlObject = deserializer.Deserialize(r); + string json = System.Text.Json.JsonSerializer.Serialize(yamlObject); + jsonObjecz = JsonDocument.Parse(json); + } + + public JsonElement getData() + { + return jsonObjecz.RootElement; + } + } +} diff --git a/FakeeDeck/configuration.yaml b/FakeeDeck/configuration.yaml index b769e4c..9cd2bc1 100644 --- a/FakeeDeck/configuration.yaml +++ b/FakeeDeck/configuration.yaml @@ -3,8 +3,58 @@ server: port: 8000 pages: - - page: helldivers, + - page: helldivers buttons: - - button: reinforce, - name: reinforce, - type: HelldiversTwoMacro, \ No newline at end of file + - button: reinforce + function: HelldiversTwoMacro + parameters: + - name: Key + value: "reinforce" + + - button: strafing-run + function: HelldiversTwoMacro + parameters: + - name: Key + value: strafing-run + + - button: airstrike + function: HelldiversTwoMacro + parameters: + - name: Key + value: airstrike + + - button: cluster-bomb + function: HelldiversTwoMacro + parameters: + - name: Key + value: cluster-bomb + + - button: napalm-airstrike + function: HelldiversTwoMacro + parameters: + - name: Key + value: napalm-airstrike + + - button: smoke-strike + function: HelldiversTwoMacro + parameters: + - name: Key + value: smoke-strike + + - button: rocket-pods + function: HelldiversTwoMacro + parameters: + - name: Key + value: rocket-pods + + - button: bomb + function: HelldiversTwoMacro + parameters: + - name: Key + value: bomb + + - button: mute + function: MediaMacro + parameters: + - name: Key + value: "mute" \ No newline at end of file