mirror of
https://github.com/SamueleLorefice/ComfySharp
synced 2026-01-15 03:35:48 +00:00
Started work on classes generation
- Removed Input and PrimitiveTypes classes. - Added IInput interface - Added INode interface - Reworked Inputfield to be a class implementing IInput - Added Inputs class, holding all the inputs for a node. Making it 1:1 with the serialized version - Bandaid fixed the Node class, still deciding if keeping it removing it.
This commit is contained in:
@@ -12,6 +12,7 @@ namespace ComfySharp;
|
|||||||
|
|
||||||
public class NodeDBGenerator {
|
public class NodeDBGenerator {
|
||||||
readonly private List<ExpandoObject> nodes;
|
readonly private List<ExpandoObject> nodes;
|
||||||
|
|
||||||
#region Conversion
|
#region Conversion
|
||||||
readonly private ConversionSettings settings;
|
readonly private ConversionSettings settings;
|
||||||
|
|
||||||
@@ -140,13 +141,21 @@ public class NodeDBGenerator {
|
|||||||
foreach (var knownEnum in knownEnums) {
|
foreach (var knownEnum in knownEnums) {
|
||||||
GenerateEnum(knownEnum.Key, knownEnum.Value, enumNs);
|
GenerateEnum(knownEnum.Key, knownEnum.Value, enumNs);
|
||||||
}
|
}
|
||||||
GenerateEnum("BaseTypes", knownTypes, enumNs);//TODO: make a proper method that handles the edge cases, like * and comma separated multi instances
|
//TODO: make a proper method that handles the edge cases, like * and comma separated multi instances
|
||||||
|
//GenerateEnum("BaseTypes", knownTypes, enumNs);
|
||||||
|
|
||||||
|
compileUnit.Namespaces.Remove(enumNs);
|
||||||
Logger.Info($"Enum Generation finished. Took {timer.ElapsedMilliseconds} ms");
|
Logger.Info($"Enum Generation finished. Took {timer.ElapsedMilliseconds} ms");
|
||||||
|
|
||||||
|
Logger.Info("Classes Generation starting...");
|
||||||
timer.Restart();
|
timer.Restart();
|
||||||
//compileUnit.Namespaces.Add(codeNamespace);
|
compileUnit.Namespaces.Add(codeNamespace);
|
||||||
//ns.Imports.AddRange(new CodeNamespaceImport[] { new ("System"), new ("System.Collections.Generics"), new ("ComfySharp") });
|
codeNamespace.Imports.AddRange(new CodeNamespaceImport[] { new ("System"), new ("System.Collections.Generics"), new ("ComfySharp") });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void GenerateEnum(string name, List<string> enumValues, CodeNamespace ns) {
|
private void GenerateEnum(string name, List<string> enumValues, CodeNamespace ns) {
|
||||||
string path = Path.Combine(Environment.CurrentDirectory, settings.CodeOutputFolderName, $"{name}.cs");
|
string path = Path.Combine(Environment.CurrentDirectory, settings.CodeOutputFolderName, $"{name}.cs");
|
||||||
Logger.Debug($"Generating enum {name} w\\ {enumValues.Count} values.\n" +
|
Logger.Debug($"Generating enum {name} w\\ {enumValues.Count} values.\n" +
|
||||||
|
|||||||
5
ComfySharp/Types/IInput.cs
Normal file
5
ComfySharp/Types/IInput.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
namespace ComfySharp.Types;
|
||||||
|
|
||||||
|
public interface IInput {
|
||||||
|
|
||||||
|
}
|
||||||
30
ComfySharp/Types/INode.cs
Normal file
30
ComfySharp/Types/INode.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace ComfySharp.Types;
|
||||||
|
|
||||||
|
public interface INode {
|
||||||
|
//Inputs
|
||||||
|
[DataMember(Name = "input")]
|
||||||
|
public Inputs Inputs { get; }
|
||||||
|
//Outputs
|
||||||
|
[DataMember(Name = "output")]
|
||||||
|
public string[] Outputs { get; }
|
||||||
|
[DataMember(Name = "output_is_list")]
|
||||||
|
public bool[] OutputIsList { get; }
|
||||||
|
[DataMember(Name = "output_name")]
|
||||||
|
public string[] OutputNames { get; }
|
||||||
|
//Metadata
|
||||||
|
[DataMember(Name = "name")]
|
||||||
|
public string Name { get; }
|
||||||
|
[DataMember(Name = "display_name")]
|
||||||
|
public string DisplayName { get; }
|
||||||
|
[DataMember(Name = "description")]
|
||||||
|
public string Description { get; }
|
||||||
|
[DataMember(Name = "category")]
|
||||||
|
public string Category { get; }
|
||||||
|
[DataMember(Name = "output_node")]
|
||||||
|
public bool IsOutputNode { get; }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
namespace ComfySharp.Types;
|
|
||||||
|
|
||||||
[DataContract]
|
|
||||||
public struct Input {
|
|
||||||
[DataMember]
|
|
||||||
public List<InputField> Required { get; set; }
|
|
||||||
[DataMember]
|
|
||||||
public List<InputField> Optional { get; set; }
|
|
||||||
[DataMember]
|
|
||||||
public List<InputField> Hidden { get; set; }
|
|
||||||
|
|
||||||
public Input() {
|
|
||||||
Required = new();
|
|
||||||
Optional = new();
|
|
||||||
Hidden = new();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,17 @@
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace ComfySharp.Types;
|
namespace ComfySharp.Types;
|
||||||
|
|
||||||
public struct InputField {
|
[DataContract, JsonSerializable(typeof(InputField))]
|
||||||
[DataMember(Name = "name")]
|
public class InputField : IInput {
|
||||||
|
[DataMember(Name = "name", IsRequired = false)]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
[DataMember(Name = "type", IsRequired = false)]
|
||||||
public PrimitiveType Type { get; set; }
|
public string Type { get; set; }
|
||||||
|
|
||||||
|
public InputField(string name, string type) {
|
||||||
|
Name = name;
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
14
ComfySharp/Types/Inputs.cs
Normal file
14
ComfySharp/Types/Inputs.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace ComfySharp.Types;
|
||||||
|
|
||||||
|
[DataContract, JsonSerializable(typeof(Inputs))]
|
||||||
|
public class Inputs {
|
||||||
|
[DataMember(Name = "required")]
|
||||||
|
public List<IInput> Required { get; set; } = new();
|
||||||
|
[DataMember(Name = "optional", IsRequired = false)]
|
||||||
|
public List<IInput>? Optional { get; set; }
|
||||||
|
[DataMember(Name = "hidden", IsRequired = false)]
|
||||||
|
public List<IInput>? Hidden { get; set; }
|
||||||
|
}
|
||||||
@@ -8,9 +8,9 @@ public class Node {
|
|||||||
[DataMember(Name = "name")]
|
[DataMember(Name = "name")]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
[DataMember(Name = "input")]
|
[DataMember(Name = "input")]
|
||||||
public Input Input { get; set; }
|
public Inputs Inputs { get; set; }
|
||||||
[DataMember(Name = "output")]
|
[DataMember(Name = "output")]
|
||||||
public List<PrimitiveType> Outputs { get; set; }
|
public List<string> Outputs { get; set; }
|
||||||
[DataMember(Name = "output_is_list")]
|
[DataMember(Name = "output_is_list")]
|
||||||
public List<bool> OutputIsList { get; set; }
|
public List<bool> OutputIsList { get; set; }
|
||||||
[DataMember(Name = "output_name")]
|
[DataMember(Name = "output_name")]
|
||||||
@@ -26,7 +26,7 @@ public class Node {
|
|||||||
|
|
||||||
public Node() {
|
public Node() {
|
||||||
Name = "";
|
Name = "";
|
||||||
Input = new();
|
Inputs = new();
|
||||||
Outputs = new();
|
Outputs = new();
|
||||||
OutputIsList = new();
|
OutputIsList = new();
|
||||||
OutputNames = new();
|
OutputNames = new();
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
namespace ComfySharp.Types;
|
|
||||||
|
|
||||||
public enum PrimitiveType {
|
|
||||||
ANY,
|
|
||||||
CLIP,
|
|
||||||
CLIP_VISION,
|
|
||||||
CLIP_VISION_OUTPUT,
|
|
||||||
CONDITIONING,
|
|
||||||
CONTROL_NET,
|
|
||||||
EXTRA_PNGINFO,
|
|
||||||
FLOAT,
|
|
||||||
GLIGEN,
|
|
||||||
IMAGE,
|
|
||||||
INT,
|
|
||||||
LATENT,
|
|
||||||
MASK,
|
|
||||||
MODEL,
|
|
||||||
PROMPT,
|
|
||||||
SAMPLER,
|
|
||||||
SIGMAS,
|
|
||||||
STRING,
|
|
||||||
STYLE_MODEL,
|
|
||||||
UNIQUE_ID,
|
|
||||||
UPSCALE_MODEL,
|
|
||||||
VAE,
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user