Progression And Cleanup

This commit is contained in:
2024-09-12 08:48:11 -07:00
parent 012cc02352
commit 0918ac5a80
6 changed files with 181 additions and 22 deletions

View File

@@ -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<object> parameters = new List<object>();
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();
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -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
" </body>" +
"</html>";
public string pageData = "";
private Dictionary<string, Dictionary<string, Action>> routes;
public async Task HandleIncomingConnections()
{
bool runServer = true;

View File

@@ -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;
}
}
}