mirror of
https://github.com/SamueleLorefice/ComfySharp
synced 2026-01-15 06:13:41 +00:00
Revamped parsing part 1
This commit is contained in:
@@ -1,75 +1,21 @@
|
||||
using System.Text.Json;
|
||||
using System.Dynamic;
|
||||
using System.Text.Json;
|
||||
using ComfySharp.Types;
|
||||
|
||||
namespace ComfySharp;
|
||||
|
||||
public static class ObjectInfoParser {
|
||||
public static void Parse(JsonDocument document, out List<Node> nodes) {
|
||||
nodes = new List<Node>();
|
||||
foreach (var node in document.RootElement.EnumerateObject()) {
|
||||
Node n = new();
|
||||
n.Name = node.Name;
|
||||
|
||||
foreach (var prop in node.Value.EnumerateObject()) {
|
||||
switch (prop.Name) {
|
||||
case "input":
|
||||
n.Input = new();
|
||||
|
||||
foreach (var input in prop.Value.EnumerateObject()) {
|
||||
switch (input.Name) {
|
||||
case "required":
|
||||
foreach (var field in input.Value.EnumerateObject()) {
|
||||
InputField f = new();
|
||||
f.Name = field.Name;
|
||||
f.Type = Enum.Parse<PrimitiveType>(field.Value.GetString() ?? "");
|
||||
n.Input.Required.Add(f);
|
||||
}
|
||||
break;
|
||||
case "optional":
|
||||
foreach (var field in input.Value.EnumerateObject()) {
|
||||
InputField f = new();
|
||||
f.Name = field.Name;
|
||||
f.Type = Enum.Parse<PrimitiveType>(field.Value.GetString() ?? "");
|
||||
n.Input.Optional.Add(f);
|
||||
}
|
||||
break;
|
||||
case "hidden":
|
||||
foreach (var field in input.Value.EnumerateObject()) {
|
||||
InputField f = new();
|
||||
f.Name = field.Name;
|
||||
f.Type = Enum.Parse<PrimitiveType>(field.Value.GetString() ?? "");
|
||||
n.Input.Hidden.Add(f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "output":
|
||||
foreach (var output in prop.Value.EnumerateObject()) {
|
||||
n.Outputs.Add(Enum.Parse<PrimitiveType>(output.Value.GetString() ?? ""));
|
||||
n.OutputIsList.Add(output.Value.GetBoolean());
|
||||
n.OutputNames.Add(output.Name);
|
||||
}
|
||||
break;
|
||||
case "display_name":
|
||||
n.DisplayName = prop.Value.GetString() ?? "";
|
||||
break;
|
||||
case "description":
|
||||
n.Description = prop.Value.GetString() ?? "";
|
||||
break;
|
||||
case "category":
|
||||
n.Category = prop.Value.GetString() ?? "";
|
||||
break;
|
||||
case "output_node":
|
||||
n.IsOutputNode = prop.Value.GetBoolean();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Parse(JsonDocument document, out List<ExpandoObject> nodes) {
|
||||
NodeDBGenerator dbGenerator = new();
|
||||
dbGenerator.GenerateNodes(document);
|
||||
nodes = dbGenerator.GetNodes();
|
||||
dbGenerator.GenerateClasses(document);
|
||||
}
|
||||
|
||||
private static void ParseNode(JsonElement node, out Node n) {
|
||||
n = new();
|
||||
|
||||
n.Name = node.GetProperty("name").GetString() ?? "";
|
||||
n.Input = ParseInput(node.GetProperty("input"));
|
||||
n.Outputs = ParseOutputs(node.GetProperty("output"));
|
||||
@@ -80,4 +26,20 @@ public static class ObjectInfoParser {
|
||||
n.Category = node.GetProperty("category").GetString() ?? "";
|
||||
n.IsOutputNode = node.GetProperty("output_node").GetBoolean();
|
||||
}
|
||||
static private List<string> ParseOutputNames(JsonElement getProperty) {
|
||||
List<string> outputNames = new();
|
||||
foreach (var output in getProperty.EnumerateArray()) {
|
||||
outputNames.Add(output.GetProperty("name").GetString() ?? "");
|
||||
}
|
||||
return outputNames;
|
||||
}
|
||||
static private List<bool> ParseOutputIsList(JsonElement getProperty) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
static private List<PrimitiveType> ParseOutputs(JsonElement getProperty) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
static private Input ParseInput(JsonElement getProperty) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user