cleaning up

This commit is contained in:
Chris
2025-09-14 20:52:06 +10:00
parent 35fd8a4a8e
commit 3724ddeafe
4 changed files with 53 additions and 63 deletions
+13 -7
View File
@@ -2,18 +2,24 @@ import { shared } from "./shared.js"
import { Logger } from "./use_everywhere_utilities.js"
function update_me(node) {
Logger.log_problem(`Reseting combo clone node ${node.id}`)
node.IS_COMBO_CLONE = true
node.widgets[0].options.values = [...node.properties.comboclone.options]
node.outputs[0].type = "COMBO"
node.outputs[0].label = node.properties.comboclone.name
if (node.properties.comboclone) {
Logger.log_problem(`Reseting combo clone node ${node.id}`)
node.widgets[0].options.values = [...node.properties.comboclone.options]
node.outputs[0].type = "COMBO"
node.outputs[0].label = node.properties.comboclone.name
}
}
export function is_combo_clone(node) {
return (node.type == "Combo Clone")
}
export function reset_comboclone_on_load(node) {
if (node.properties?.comboclone) update_me(node)
if (is_combo_clone(node)) update_me(node)
}
export function comboclone_on_connection(node, link_info, connect) {
if (!is_combo_clone(node)) return Logger.log_problem(`comboclone_on_connection called for node ${node.id} of type ${node.type}`)
if (shared.graph_being_configured) return
if (connect) {
if (!link_info) return
@@ -31,6 +37,6 @@ export function comboclone_on_connection(node, link_info, connect) {
link_info.type = "COMBO"
}
} else {
let a;
// no action when we disconnect
}
}
+21 -47
View File
@@ -3,7 +3,7 @@ import { get_real_node, is_UEnode, Logger } from "./use_everywhere_utilities.js"
import { app } from "../../scripts/app.js";
import { i18n } from "./i18n.js";
import { shared } from "./shared.js";
import { reset_comboclone_on_load } from "./combo_clone.js";
import { reset_comboclone_on_load, is_combo_clone } from "./combo_clone.js";
function get_type(node, link_info) {
var type = null
@@ -47,55 +47,33 @@ export function input_changed(node, slot, connect, link_info) {
node.inputs[slot].color_on = undefined;
node.inputs[slot].type = '*'
}
fix_inputs(node)
fix_inputs(node, "input_changed")
}
function store_input_state(node) {
return
node.properties.ue_properties.input_state = []
node.inputs.filter((inputslot)=>(inputslot.type!='*')).forEach((input)=>{
node.properties.ue_properties.input_state.push( {
type : input.type,
label : input.label,
color_on : input.color_on
} )
})
}
function restore_input_state(node) {
return
if (node.properties.ue_properties.input_state) {
while (node.inputs.length < node.properties.ue_properties.input_state.length+1) add_new_input(node)
while (node.inputs.length > node.properties.ue_properties.input_state.length+1) {
if (!remove_excess_input(node)) return
}
node.properties.ue_properties.input_state.forEach((state, i) => {
Object.assign(node.inputs[i], state)
})
} else {
Logger.log_problem(`restore_input_state called for a node with no stored input state`)
}
}
export function restore_input_states(graph) {
export function post_configure_fixes(graph) {
graph.nodes.forEach((node) => {
reset_comboclone_on_load(node)
if (node.properties.ue_properties?.input_state) restore_input_state(node)
if (is_UEnode(node)) fix_inputs(node)
if (node.subgraph) restore_input_states(node.subgraph)
if (is_combo_clone(node)) reset_comboclone_on_load(node)
if (is_UEnode(node)) fix_inputs(node, "post_configure_fixes")
if (node.subgraph) post_configure_fixes(node.subgraph)
})
}
function add_new_input(node) {
node.properties.ue_properties.next_input_index = (node.properties.ue_properties.next_input_index || 10) + 1
node.addInput(`anything${node.properties.ue_properties.next_input_index}`, "*", {label:i18n('anything')})
Logger.log_info(`Adding new anything input to node ${node.id} (${fix_call_message})`)
try {
node.properties.ue_properties.next_input_index = (node.properties.ue_properties.next_input_index || 10) + 1
node.addInput(`anything${node.properties.ue_properties.next_input_index}`, "*", {label:i18n('anything')})
return true
} catch (e) { Logger.log_error(e) }
return false
}
function remove_excess_input(node) {
const idx = node.inputs.findIndex((inputslot)=>(inputslot.type=='*'))
if (idx>=0) {
try {
Logger.log_info(`Removing excess anything input from node ${node.id}`)
Logger.log_info(`Removing excess anything input from node ${node.id} (${fix_call_message})`)
node.removeInput(idx)
return true
} catch (e) { Logger.log_error(e) }
@@ -106,26 +84,22 @@ function remove_excess_input(node) {
/*
This is called in various places (node load, creation, link change) to ensure there is exactly one empty input
*/
export function fix_inputs(node) {
var fix_call_message;
export function fix_inputs(node, message) {
fix_call_message = message
if (!node.graph) return // node has been deleted prior to the fix
if (shared.graph_being_configured) return
if (node.properties.ue_properties.fixed_inputs) return store_input_state(node)
if (node.properties.ue_properties.fixed_inputs) return
const empty_inputs = node.inputs.filter((inputslot)=>(inputslot.type=='*'))
var excess_inputs = empty_inputs.length - 1
if (excess_inputs<0) {
try {
Logger.log_info(`Adding new anything input to node ${node.id}`)
add_new_input(node)
fix_inputs(node)
} catch (e) {
Logger.log_error(e)
}
if (add_new_input(node)) fix_inputs(node)
} else if (excess_inputs>0) {
if (remove_excess_input(node)) fix_inputs(node)
}
store_input_state(node)
}
+1 -1
View File
@@ -139,5 +139,5 @@ function convert_node_types(node) {
if (node.properties.ue_properties[rname]==".*") node.properties.ue_properties[rname] = undefined
})
fix_inputs(node)
fix_inputs(node, "convert_node_types")
}
+18 -8
View File
@@ -15,8 +15,8 @@ import { master_graph, visible_graph } from "./use_everywhere_subgraph_utils.js"
import { any_restrictions, setup_ue_properties_oncreate, setup_ue_properties_onload } from "./ue_properties.js";
import { edit_restrictions } from "./ue_properties_editor.js";
import { language_changed } from "./i18n.js";
import { input_changed, fix_inputs, restore_input_states } from "./connections.js";
import { reset_comboclone_on_load, comboclone_on_connection } from "./combo_clone.js";
import { input_changed, fix_inputs, post_configure_fixes } from "./connections.js";
import { reset_comboclone_on_load, comboclone_on_connection, is_combo_clone } from "./combo_clone.js";
/*
The ui component that looks after the link rendering
@@ -57,29 +57,39 @@ app.registerExtension({
settings: SETTINGS,
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name=="Combo Clone") {
nodeType.prototype.IS_COMBO_CLONE = true
}
/*
When a node is connected or unconnected, the link list is dirty.
If it is a UE node, we need to update it as well
*/
const onConnectionsChange = nodeType.prototype.onConnectionsChange;
nodeType.prototype.onConnectionsChange = function (side,slot,connect,link_info,output) {
if (this.IS_COMBO_CLONE) comboclone_on_connection(this, link_info, connect)
if (is_combo_clone(this)) comboclone_on_connection(this, link_info, connect)
if (this.IS_UE && side==1) { // side 1 is input
input_changed(this, slot, connect, link_info)
// I suspect this is no longer needed... in which case the whole Deferred can be dumped!
if (!shared.graph_being_configured) {
// do the fix at the end of graph change
deferred_actions.push( { fn:fix_inputs, args:[this,]} )
deferred_actions.push( { fn:fix_inputs, args:[this,"deferred",]} )
// disconnecting doesn't trigger graphChange call?
setTimeout(deferred_actions.execute.bind(deferred_actions), 100)
}
// ...to here
}
linkRenderController?.mark_link_list_outdated();
onConnectionsChange?.apply(this, arguments);
};
/* Combo Clone can connect to COMBO or to UE nodes */
if (nodeData.name=="Combo Clone") {
const onConnectOutput = nodeType.prototype.onConnectOutput
nodeType.prototype.onConnectOutput = function(outputIndex, type, input, inputNode, inputIndex) {
if (!(type=="COMBO" || is_UEnode(inputNode))) return false;
return onConnectOutput?.apply(this,arguments)
}
}
/*
Extra menu options are the node right click menu.
@@ -362,7 +372,7 @@ app.registerExtension({
graphConverter.remove_saved_ue_links_recursively(app.graph)
//convert_old_nodes(app.graph)
shared.graph_being_configured = false
restore_input_states(master_graph())
post_configure_fixes(master_graph())
}
});