mirror of
https://github.com/SamueleLorefice/ComfySharp
synced 2026-01-15 04:53:42 +00:00
Moved all classes and enums to their respective files under the Types namespace. Added ObjectInfoPArser class to delegate the processing of the massice node info json to a more clean place.
Let the pain begin.
This commit is contained in:
83
ComfySharp/ObjectInfoParser.cs
Normal file
83
ComfySharp/ObjectInfoParser.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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"));
|
||||
n.OutputIsList = ParseOutputIsList(node.GetProperty("output"));
|
||||
n.OutputNames = ParseOutputNames(node.GetProperty("output"));
|
||||
n.DisplayName = node.GetProperty("display_name").GetString() ?? "";
|
||||
n.Description = node.GetProperty("description").GetString() ?? "";
|
||||
n.Category = node.GetProperty("category").GetString() ?? "";
|
||||
n.IsOutputNode = node.GetProperty("output_node").GetBoolean();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user