1+ using System ;
2+ using System . IO ;
3+ using System . Collections . Generic ;
4+ using System . Linq ;
15using FreneticUtilities . FreneticExtensions ;
26using FreneticUtilities . FreneticToolkit ;
37using Newtonsoft . Json . Linq ;
48using SwarmUI . Accounts ;
59using SwarmUI . Core ;
610using SwarmUI . Text2Image ;
11+ using SwarmUI . Media ;
712using SwarmUI . Utils ;
813using SwarmUI . WebAPI ;
9- using System . IO ;
1014using System . Net . WebSockets ;
1115using SixLabors . Fonts ;
1216using SixLabors . ImageSharp ;
1317using SixLabors . ImageSharp . Processing ;
1418using SixLabors . ImageSharp . Drawing . Processing ;
19+
1520using static SwarmUI . Builtin_GridGeneratorExtension . GridGenCore ;
1621using Image = SwarmUI . Utils . Image ;
1722using ISImage = SixLabors . ImageSharp . Image ;
1823using ISImageRGBA = SixLabors . ImageSharp . Image < SixLabors . ImageSharp . PixelFormats . Rgba32 > ;
19- using SwarmUI . Media ;
2024
2125namespace SwarmUI . Builtin_GridGeneratorExtension ;
2226
@@ -29,6 +33,15 @@ public class GridGeneratorExtension : Extension
2933 public static PermInfo PermReadGrids = Permissions . Register ( new ( "gridgen_read_grids" , "[Grid Generator] Read Grids" , "Allows the user to read their list of saved grids." , PermissionDefault . USER , Permissions . GroupUser ) ) ;
3034 public static PermInfo PermSaveGrids = Permissions . Register ( new ( "gridgen_save_grids" , "[Grid Generator] Save Grids" , "Allows the user to save new custom grids to their list of saved grids." , PermissionDefault . USER , Permissions . GroupUser ) ) ;
3135
36+ /// <summary>Set of parameter IDs that should be comma-stackable in multiple grid axes.</summary>
37+ public static Dictionary < string , T2IParamType > CommaStackableParameters = [ ] ;
38+
39+ /// <summary>Marks a parameter type as being stackable with comma separation in multiple grid axes.</summary>
40+ public static void MakeStackable ( T2IParamType type )
41+ {
42+ CommaStackableParameters [ type . ID ] = type ;
43+ }
44+
3245 public override void OnPreInit ( )
3346 {
3447 ScriptFiles . Add ( "Assets/grid_gen.js" ) ;
@@ -90,9 +103,9 @@ public override void OnPreInit()
90103 ( call . LocalData as GridCallData ) . Additions . Add ( val ) ;
91104 return true ;
92105 }
93- else if ( cleaned == PresetsParameter . Type . ID )
106+ else if ( CommaStackableParameters . TryGetValue ( cleaned , out T2IParamType type ) )
94107 {
95- ( call . LocalData as GridCallData ) . Presets . Add ( val ) ;
108+ ( call . LocalData as GridCallData ) . CommaStackable . GetOrCreate ( type , ( ) => [ ] ) . Add ( val ) ;
96109 return true ;
97110 }
98111 else if ( cleaned == "width" || cleaned == "outwidth" )
@@ -135,14 +148,18 @@ public override void OnPreInit()
135148 string prompt = param . InternalSet . Get ( T2IParamTypes . Prompt , "" ) + " " + data . Additions . JoinString ( " " ) ;
136149 param . InternalSet . Set ( T2IParamTypes . Prompt , prompt . Trim ( ) ) ;
137150 }
138- if ( data . Presets . Any ( ) )
151+ foreach ( ( T2IParamType key , List < string > vals ) in data . CommaStackable )
139152 {
140- string presets = data . Presets . JoinString ( "," ) ;
141- if ( param . InternalSet . TryGet ( PresetsParameter , out string existing ) )
153+ string joined = vals . JoinString ( "," ) ;
154+ if ( param . TryGetRaw ( key , out object existing ) )
142155 {
143- presets += $ ",{ existing } ";
156+ if ( existing is List < string > strs )
157+ {
158+ existing = strs . JoinString ( "," ) ;
159+ }
160+ joined = $ "{ existing } ,{ joined } ";
144161 }
145- param . InternalSet . Set ( PresetsParameter , presets ) ;
162+ param . Set ( key , joined ) ;
146163 }
147164 } ;
148165 GridRunnerPreRunHook = ( runner ) =>
@@ -278,6 +295,11 @@ public override void OnInit()
278295 API . RegisterAPICall ( GridGenDeleteData , true , PermSaveGrids ) ;
279296 API . RegisterAPICall ( GridGenGetData , false , PermReadGrids ) ;
280297 API . RegisterAPICall ( GridGenListData , false , PermReadGrids ) ;
298+ MakeStackable ( PresetsParameter . Type ) ;
299+ MakeStackable ( T2IParamTypes . Loras . Type ) ;
300+ MakeStackable ( T2IParamTypes . LoraWeights . Type ) ;
301+ MakeStackable ( T2IParamTypes . LoraTencWeights . Type ) ;
302+ MakeStackable ( T2IParamTypes . LoraSectionConfinement . Type ) ;
281303 }
282304
283305 public async Task < JObject > GridGenSaveData ( Session session , string gridName , bool isPublic , JObject rawData )
@@ -340,7 +362,7 @@ public class GridCallData
340362
341363 public List < string > Additions = [ ] ;
342364
343- public List < string > Presets = [ ] ;
365+ public Dictionary < T2IParamType , List < string > > CommaStackable = [ ] ;
344366 }
345367
346368 public class SwarmUIGridData
0 commit comments