File size: 7,050 Bytes
3d5837a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { ComfyApp, app } from "../../scripts/app.js";

app.registerExtension({
	name: "Comfy.Inspire.LBW",

	nodeCreated(node, app) {
		if(node.comfyClass == "LoraLoaderBlockWeight //Inspire") {
		    // category filter
			const lora_names_widget = node.widgets[node.widgets.findIndex(obj => obj.name === 'lora_name')];
			var full_lora_list = lora_names_widget.options.values;
			const category_filter_widget = node.widgets[node.widgets.findIndex(obj => obj.name === 'category_filter')];

			Object.defineProperty(lora_names_widget.options, "values", {
			    set: (x) => {
			        full_lora_list = x;
			    },
			    get: () => {
			        if(category_filter_widget.value == 'All')
			            return full_lora_list;

                    let l = full_lora_list.filter(x => x.startsWith(category_filter_widget.value));
                    return l;
			    }
			});

		    // vector selector
		    let preset_i = 9;
		    let vector_i = 10;
			node._value = "Preset";

			Object.defineProperty(node.widgets[preset_i], "value", {
				set: (value) => {
				        const stackTrace = new Error().stack;
                        if(stackTrace.includes('inner_value_change')) {
                            if(value != "Preset") {
                                node.widgets[vector_i].value = value.split(':')[1];
	                            if(node.widgets_values) {
	                                node.widgets_values[vector_i] = node.widgets[preset_i].value;
                                }
                            }
                        }

						node._value = value;
					},
				get: () => {
                        return node._value;
					 }
			});
		}

		if(node.comfyClass == "XY Input: Lora Block Weight //Inspire") {
		    // category filter
            const lora_names_widget = node.widgets[node.widgets.findIndex(obj => obj.name === 'lora_name')];
			var full_lora_list = lora_names_widget.options.values;
			const category_filter_widget = node.widgets[node.widgets.findIndex(obj => obj.name === 'category_filter')];

			Object.defineProperty(lora_names_widget.options, "values", {
			    set: (x) => {
			        full_lora_list = x;
			    },
			    get: () => {
			        if(category_filter_widget.value == 'All')
			            return full_lora_list;

                    let l = full_lora_list.filter(x => x.startsWith(category_filter_widget.value));
                    return l;
			    }
			});

            // vector selector
		    let preset_i = 9;
		    let vector_i = 10;
			node._value = "Preset";
			Object.defineProperty(node.widgets[preset_i], "value", {
				set: (value) => {
				        const stackTrace = new Error().stack;
                        if(stackTrace.includes('inner_value_change')) {
                            if(value != "Preset") {
                                if(!value.startsWith('@') && node.widgets[vector_i].value != "")
                                    node.widgets[vector_i].value += "\n";
                                if(value.startsWith('@')) {
                                    let spec = value.split(':')[1];
                                    var n;
                                    var sub_n = null;
                                    var block = null;

                                    if(isNaN(spec)) {
                                        let sub_spec = spec.split(',');

                                        if(sub_spec.length != 3) {
	                                        node.widgets_values[vector_i] = '!! SPEC ERROR !!';
	                                        node._value = '';
	                                        return;
                                        }

                                        n = parseInt(sub_spec[0].trim());
                                        sub_n = parseInt(sub_spec[1].trim());
                                        block = parseInt(sub_spec[2].trim());
                                    }
                                    else {
                                        n = parseInt(spec.trim());
                                    }

                                    node.widgets[vector_i].value = "";
                                    if(sub_n == null) {
                                        for(let i=1; i<=n; i++) {
                                            var temp = "";
                                            for(let j=1; j<=n; j++) {
                                                if(temp!='')
                                                    temp += ',';
                                                if(j==i)
                                                    temp += 'A';
                                                else
                                                    temp += '0';
                                            }

                                            node.widgets[vector_i].value += `B${i}:${temp}\n`;
                                        }
                                    }
                                    else {
                                        for(let i=1; i<=sub_n; i++) {
                                            var temp = "";
                                            for(let j=1; j<=n; j++) {
                                                if(temp!='')
                                                    temp += ',';

                                                if(block!=j)
                                                    temp += '0';
                                                else {
                                                    temp += ' ';
                                                    for(let k=1; k<=sub_n; k++) {
                                                        if(k==i)
                                                            temp += 'A ';
                                                        else
                                                            temp += '0 ';
                                                    }
                                                }
                                            }

                                            node.widgets[vector_i].value += `B${block}.SUB${i}:${temp}\n`;
                                        }
                                    }
                                }
                                else {
                                    node.widgets[vector_i].value += `${value}/${value.split(':')[0]}`;
                                }
	                            if(node.widgets_values) {
	                                node.widgets_values[vector_i] = node.widgets[preset_i].value;
                                }
                            }
                        }

						node._value = value;
					},
				get: () => {
                        return node._value;
					 }
			});
		}
	}
});