Skip to content

Commit

Permalink
fix only value1 is right when using ForEachOpen
Browse files Browse the repository at this point in the history
  • Loading branch information
lldacing committed Sep 26, 2024
1 parent 55de32f commit 373e2e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
10 changes: 6 additions & 4 deletions easyapi/ForEachNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def INPUT_TYPES(cls):
inputs["optional"]["initial_value%d" % i] = ("*",)
return inputs

RETURN_TYPES = tuple(["*"] * NUM_FLOW_SOCKETS)
RETURN_TYPES = tuple([any_type] * NUM_FLOW_SOCKETS)
RETURN_NAMES = tuple(["value%d" % i for i in range(NUM_FLOW_SOCKETS)])
FUNCTION = "while_loop_close"

Expand Down Expand Up @@ -188,7 +188,8 @@ def INPUT_TYPES(cls):
"total": ("INT", {"default": 1, "min": 1, "max": 1000, "step": 1, "tooltip": "总循环次数"}),
},
"optional": {
"initial_value1": (any_type,)
# 必须声明全部,否者循环时只有第一个值能正确传递
"initial_value%d" % i: (any_type,) for i in range(1, NUM_FLOW_SOCKETS)
},
"hidden": {
"initial_value0": (any_type,)
Expand All @@ -213,7 +214,7 @@ def for_loop_open(self, total, **kwargs):
initial_value_num = find_max_initial_value_number(kwargs, "initial_value")

# 好像没啥用
# while_open = graph.node("WhileLoopOpen", condition=remaining, initial_value0=total, **{("initial_value%d" % i): kwargs.get("initial_value%d" % i, None) for i in range(1, NUM_FLOW_SOCKETS)})
# while_open = graph.node("WhileLoopOpen", condition=total, initial_value0=index, **{("initial_value%d" % i): kwargs.get("initial_value%d" % i, None) for i in range(1, initial_value_num + 1)})

outputs = [kwargs.get("initial_value%d" % i, None) for i in range(1, initial_value_num + 1)]
return {
Expand All @@ -230,7 +231,8 @@ def INPUT_TYPES(cls):
"flow_control": ("FLOW_CONTROL", {"rawLink": True}),
},
"optional": {
"initial_value1": (any_type, {"rawLink": True})
# 必须声明全部,否者循环时只有第一个值能正确传递
"initial_value%d" % i: (any_type, {"rawLink": True}) for i in range(1, NUM_FLOW_SOCKETS)
},
}

Expand Down
24 changes: 18 additions & 6 deletions static/js/easyapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@ app.registerExtension({
let output_name = "value";
let fixed_head_input_names = ["flow_control"];
let fixed_tail_input_names = ["total"];
// 与py代码中定义保持一致
let max_number_of_inputs = 20;
// 比py代码中定义少1,因为不含initial_value0
let max_number_of_inputs = 19;
let out_fixed_num = output_fixed_num_for_filter_node_type[filter_node_type.indexOf(nodeData.name)];

nodeType.prototype.onConnectionsChange = function (type, index, connected, link_info) {
Expand All @@ -619,7 +619,7 @@ app.registerExtension({
// 设置输入类型
let input_slot = link_info.origin_slot - out_fixed_num + fixed_head_solt_count
if (connected) {
let output_type = app.graph._nodes_by_id[link_info.target_id].inputs[link_info.target_slot].type
let output_type = app.graph._nodes_by_id[link_info.target_id]?.inputs[link_info.target_slot]?.type
if(!this.inputs[input_slot]?.link && output_type !== "*") {
// 输入节点无连接
this.setOutputDataType(link_info.origin_slot, output_type)
Expand Down Expand Up @@ -662,9 +662,11 @@ app.registerExtension({

// 设置类型
if (connected) {
let input_type = app.graph._nodes_by_id[link_info.origin_id].outputs[link_info.origin_slot].type
this.inputs[link_info.target_slot].type = input_type
this.setOutputDataType(link_info.target_slot - fixed_head_solt_count + out_fixed_num, input_type)
let input_type = app.graph._nodes_by_id[link_info.origin_id]?.outputs[link_info.origin_slot]?.type
if (!!input_type) {
this.inputs[link_info.target_slot].type = input_type
this.setOutputDataType(link_info.target_slot - fixed_head_solt_count + out_fixed_num, input_type)
}
} else {
let out_slot = link_info.target_slot - fixed_head_solt_count + out_fixed_num
if ((!this.outputs[out_slot]?.links || this.outputs[out_slot]?.links?.length == 0) && this.inputs[link_info.target_slot]?.type !== "*") {
Expand Down Expand Up @@ -732,6 +734,16 @@ app.registerExtension({
if (filter_node_type.indexOf(node.title) > -1) {
let out_fixed_num = output_fixed_num_for_filter_node_type[filter_node_type.indexOf(node.title)];
if (node.id == -1) {
let input_name = "initial_value";
for (let i = node.inputs.length - 1; i >= 0; i--) {
let index = node.inputs[i].name.indexOf(input_name);
if (index == 0) {
let num = parseInt(node.inputs[i].name.replace(input_name, ""))
if (num > 1) {
node.removeInput(i)
}
}
}
for (let i = node.outputs.length - 1; i > out_fixed_num; i--) {
removeOutSoltAndLink(node, i);
}
Expand Down

0 comments on commit 373e2e2

Please sign in to comment.