diff --git a/js/connections.js b/js/connections.js index eaf0238..7ada5c0 100644 --- a/js/connections.js +++ b/js/connections.js @@ -1,17 +1,17 @@ -import { link_is_from_subgraph_input, get_subgraph_input_type, node_graph } from "./use_everywhere_subgraph_utils.js" +import { link_is_from_subgraph_input, get_subgraph_input_type } from "./use_everywhere_subgraph_utils.js" 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, is_combo_clone } from "./combo_clone.js"; -function get_type(node, link_info) { +function get_type(graph, link_info) { var type = null if (link_info) { if (link_is_from_subgraph_input(link_info)) { // input slot of subgraph - type = get_subgraph_input_type(node_graph(node), link_info.origin_slot) + type = get_subgraph_input_type(graph, link_info.origin_slot) } else { - type = get_real_node(link_info.origin_id, node_graph(node))?.outputs[link_info.origin_slot]?.type + type = get_real_node(link_info.origin_id, graph)?.outputs[link_info.origin_slot]?.type } if (type != link_info.type && link_info.type != '*') { Logger.log_problem(`Type detected from upstream, ${type} != type on link_info ${link_info.type}`) @@ -25,32 +25,38 @@ function get_type(node, link_info) { return type } + /* Called by onConnectionsChange for a UE_Node when side == 1 (input). */ export function input_changed(node, slot, connect, link_info) { if (shared.graph_being_configured) return + if (!node?.inputs) return Logger.log_problem(`input_changed called but node.inputs not retrievable`) + const in_slot = node.inputs[slot] + if (!in_slot) return Logger.log_problem(`input_changed called for node #${node.id} slot ${slot} but that wasn't found`) + const graph = node.graph if (connect) { - const type = get_type(node, link_info) - if (app.ui.settings.getSettingValue("Use Everywhere.Options.use_output_name") && link_info) { - var out_slot - if (link_info.origin_id==-10) { - out_slot = node.graph.inputNode?.allSlots[link_info.origin_slot] - } else { - out_slot = node.graph.getNodeById(link_info.origin_id)?.outputs[link_info.origin_slot] - } - node.inputs[slot].label = out_slot?.label || out_slot?.localized_name || out_slot?.name || i18n(type); + const type = get_type(graph, link_info) + if (in_slot.transient_label) { + in_slot.label = in_slot.transient_label + } else if (app.ui.settings.getSettingValue("Use Everywhere.Options.use_output_name") && link_info) { + const out_slot = (link_info.origin_id==-10) ? + graph.inputNode?.allSlots[link_info.origin_slot] : + graph.getNodeById(link_info.origin_id)?.outputs[link_info.origin_slot] + in_slot.label = out_slot?.label || out_slot?.localized_name || out_slot?.name || i18n(type); } else { - node.inputs[slot].label = i18n(type); + in_slot.label = i18n(type); } - node.inputs[slot].color_on = app.canvas.default_connection_color_byType[type]; - node.inputs[slot].type = type + in_slot.color_on = app.canvas.default_connection_color_byType[type]; + in_slot.type = type } else { - node.inputs[slot].label = i18n('anything'); - node.inputs[slot].color_on = undefined; - node.inputs[slot].type = '*' + in_slot.transient_label = in_slot.label + in_slot.label = i18n('anything'); + in_slot.color_on = undefined; + in_slot.type = '*' + setTimeout(()=>{in_slot.transient_label=null}, 100) } } diff --git a/js/use_everywhere.js b/js/use_everywhere.js index c9ff27f..4feb7b7 100644 --- a/js/use_everywhere.js +++ b/js/use_everywhere.js @@ -11,12 +11,12 @@ import { canvas_menu_settings, SETTINGS, add_extra_menu_items } from "./use_ever import { add_debug } from "./ue_debug.js"; import { settingsCache } from "./use_everywhere_cache.js"; import { convert_to_links } from "./use_everywhere_apply.js"; -import { master_graph, visible_graph } from "./use_everywhere_subgraph_utils.js"; +import { master_graph, visible_graph, copy_ue_accepting } 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, post_configure_fixes } from "./connections.js"; -import { reset_comboclone_on_load, comboclone_on_connection, is_combo_clone } from "./combo_clone.js"; +import { comboclone_on_connection, is_combo_clone } from "./combo_clone.js"; /* The ui component that looks after the link rendering @@ -340,11 +340,11 @@ app.registerExtension({ const ctb_was = graphAnalyser.connect_to_bypassed graphAnalyser.connect_to_bypassed = true try { - const cur_list = graphAnalyser.wait_to_analyse_visible_graph() const mods = convert_to_links(cur_list, null, visible_graph()); const r = original_subgraph.apply(this, arguments); mods.restorer() + copy_ue_accepting(r.node) return r } finally { graphAnalyser.connect_to_bypassed = ctb_was diff --git a/js/use_everywhere_apply.js b/js/use_everywhere_apply.js index c94a0c2..56f6de9 100644 --- a/js/use_everywhere_apply.js +++ b/js/use_everywhere_apply.js @@ -1,6 +1,6 @@ import { app } from "../../scripts/app.js"; import { display_name } from "./use_everywhere_classes.js"; -import { master_graph, node_graph } from "./use_everywhere_subgraph_utils.js"; +import { master_graph } from "./use_everywhere_subgraph_utils.js"; import { is_UEnode, get_real_node, Logger } from "./use_everywhere_utilities.js"; @@ -33,9 +33,9 @@ function _convert_to_links(ue, added_links, removed_links) { }); } -function convert_to_links(ues, control_node, graph) { +export function convert_to_links(ues, control_node, graph) { if (control_node) { - if (!graph) graph = node_graph(control_node) + if (!graph) graph = control_node.graph return _convert_graph_to_links(graph, ues, control_node.id ); } else { if (!graph) graph = master_graph(); @@ -124,8 +124,6 @@ function remove_this(node, keep_seed_everywhere) { return (is_UEnode(node) && !(keep_seed_everywhere && node.comfyClass=="Seed Everywhere") ) } -function remove_all_ues(keep_seed_everywhere) { - app.graph._nodes.filter((node)=>remove_this(node, keep_seed_everywhere)).forEach((node)=>{app.graph.remove(node)}) +export function remove_all_ues(keep_seed_everywhere, graph) { + graph._nodes.filter((node)=>remove_this(node, keep_seed_everywhere)).forEach((node)=>{app.graph.remove(node)}) } - -export {convert_to_links, remove_all_ues} \ No newline at end of file diff --git a/js/use_everywhere_classes.js b/js/use_everywhere_classes.js index c03961c..bbda790 100644 --- a/js/use_everywhere_classes.js +++ b/js/use_everywhere_classes.js @@ -1,6 +1,6 @@ import { i18n_functional, i18n_functional_regex } from "./i18n.js"; import { default_priority } from "./ue_properties.js"; -import { node_graph, visible_graph } from "./use_everywhere_subgraph_utils.js"; +import { visible_graph } from "./use_everywhere_subgraph_utils.js"; import { nodes_in_my_group, nodes_not_in_my_group, nodes_my_color, nodes_not_my_color, nodes_in_groups_matching } from "./use_everywhere_ui.js"; import { Logger, node_is_live, get_real_node, get_connection } from "./use_everywhere_utilities.js"; @@ -160,7 +160,7 @@ export class UseEverywhereList { input_regex: input_regex_override || regex_for(node, 'input'), group_regex: regex_for(node, 'group'), priority: node.properties.ue_properties.priority || default_priority(node), - graph: node_graph(node), + graph: node.graph, additional_requirement: additional_requirement, }; diff --git a/js/use_everywhere_graph_analysis.js b/js/use_everywhere_graph_analysis.js index c9d82ce..401a14a 100644 --- a/js/use_everywhere_graph_analysis.js +++ b/js/use_everywhere_graph_analysis.js @@ -3,7 +3,7 @@ import { node_is_live, is_connected, is_UEnode, Logger, Pausable } from "./use_e import { convert_to_links } from "./use_everywhere_apply.js"; import { app } from "../../scripts/app.js"; import { settingsCache } from "./use_everywhere_cache.js"; -import { master_graph, node_graph, visible_graph } from "./use_everywhere_subgraph_utils.js"; +import { master_graph, visible_graph } from "./use_everywhere_subgraph_utils.js"; import { is_connectable } from "./use_everywhere_settings.js"; class GraphAnalyser extends Pausable { @@ -85,7 +85,7 @@ class GraphAnalyser extends Pausable { //if (!real_node._widget_name_map) real_node._widget_name_map = real_node.widgets?.map(w => w.name) || []; node.inputs?.forEach((input,index) => { if (!input) return; // NoteNode has input = [undefined,] ! - if (is_connected(input, treat_bypassed_as_live, node_graph(node))) return; + if (is_connected(input, treat_bypassed_as_live, node.graph)) return; if (node.reject_ue_connection && node.reject_ue_connection(input)) return; if (is_connectable(node, input.name)) connectable.push({node, input, index}); }) diff --git a/js/use_everywhere_settings.js b/js/use_everywhere_settings.js index 4384caa..abd5705 100644 --- a/js/use_everywhere_settings.js +++ b/js/use_everywhere_settings.js @@ -232,31 +232,33 @@ export function node_menu_settings(options, node) { export function canvas_menu_settings(options) { options.push(null); // divider - options.push({ - content: (app.ui.settings.getSettingValue('Use Everywhere.Graphics.showlinks')>0) ? "Hide UE links" : "Show UE links", - callback: () => { - const setTo = (app.ui.settings.getSettingValue('Use Everywhere.Graphics.showlinks')>0) ? 0 : 4; - app.ui.settings.setSettingValue('Use Everywhere.Graphics.showlinks', setTo); - app.graph.change(); - } - }, - { - content: "Convert all UEs to real links", - callback: async () => { - if (window.confirm("This will convert all links created by Use Everywhere to real links, and delete all the Use Everywhere nodes. Is that what you want?")) { - const ues = GraphAnalyser.instance().wait_to_analyse_visible_graph(); - LinkRenderController.instance().pause("convert"); - try { - convert_to_links(ues, visible_graph()); - remove_all_ues(true); - } finally { - app.graph.change(); - LinkRenderController.instance().unpause() - } - + options.push( + { + content: (app.ui.settings.getSettingValue('Use Everywhere.Graphics.showlinks')>0) ? "Hide UE links" : "Show UE links", + callback: () => { + const setTo = (app.ui.settings.getSettingValue('Use Everywhere.Graphics.showlinks')>0) ? 0 : 4; + app.ui.settings.setSettingValue('Use Everywhere.Graphics.showlinks', setTo); + app.graph.change(); } - } - }); + }, + { + content: "Convert all UEs (in this graph/subgraph) to real links", + callback: async () => { + if (window.confirm("This will convert all links (in this graph/subgraph) created by Use Everywhere to real links, and delete all the Use Everywhere nodes. Is that what you want?")) { + const ues = GraphAnalyser.instance().wait_to_analyse_visible_graph(); + LinkRenderController.instance().pause("convert"); + try { + convert_to_links(ues, visible_graph()); + remove_all_ues(true, visible_graph()); + } finally { + app.graph.change(); + LinkRenderController.instance().unpause() + } + + } + } + }, + ); if (GraphAnalyser.instance().ambiguity_messages.length) { options.push({ content: "Show UE broadcast clashes", diff --git a/js/use_everywhere_subgraph_utils.js b/js/use_everywhere_subgraph_utils.js index 0ef6fed..e2c0674 100644 --- a/js/use_everywhere_subgraph_utils.js +++ b/js/use_everywhere_subgraph_utils.js @@ -1,18 +1,16 @@ import { app } from "../../scripts/app.js"; +import { Logger } from "./use_everywhere_utilities.js"; export function master_graph() { return app.graph } export function master_graph_id() { return master_graph().id } export function visible_graph() { return app.canvas.graph } -export function visible_graph_id() { return visible_graph().id } - -export function node_graph(node) { return node.graph } -export function node_graph_id(node) { return node_graph(node).id } export function in_visible_graph(node) { try { - return node_graph_id(node) == visible_graph_id() - } catch { + return node.graph.id == app.canvas.graph.id + } catch (e) { + Logger.log_error(e) return false } } @@ -20,6 +18,31 @@ export function in_visible_graph(node) { export function get_subgraph_input_type(graph, slot) { return graph.inputNode.slots[slot].type } export function link_is_from_subgraph_input(link) { return link.origin_id==-10 } +export function copy_ue_accepting(new_node) { + try { + const subgraph = new_node.subgraph + subgraph.inputNode.slots.forEach((slot, i)=>{ + slot.linkIds.forEach((lid) => { + const link = subgraph.links[lid] + const target = subgraph._nodes_by_id[link.target_id] + const slot_name = target.inputs[link.target_slot].name + const ue_connectable = target.properties.ue_properties.widget_ue_connectable[slot_name] + if (ue_connectable) { + const input_name = new_node.inputs[i]?.name + if (slot_name!=input_name) { + Logger.log_problem("In copy_ue_accepting names don't match") + } else { + new_node.properties.ue_properties.widget_ue_connectable[input_name] = true + } + } + }) + }) + } catch (e) { + Logger.log_error(e, "in copy_ue_accepting") + } + +} + class WrappedInputNode { constructor(subgraph_input_node) { this.subgraph_input_node = subgraph_input_node; diff --git a/js/use_everywhere_ui.js b/js/use_everywhere_ui.js index 909c3b0..2def133 100644 --- a/js/use_everywhere_ui.js +++ b/js/use_everywhere_ui.js @@ -1,14 +1,13 @@ import { Logger, get_real_node, Pausable } from "./use_everywhere_utilities.js"; import { app } from "../../scripts/app.js"; import { settingsCache } from "./use_everywhere_cache.js"; -import { in_visible_graph, node_graph } from "./use_everywhere_subgraph_utils.js"; +import { in_visible_graph } from "./use_everywhere_subgraph_utils.js"; import { maybe_show_tooltip } from "./tooltip_window.js"; import { is_connectable } from "./use_everywhere_settings.js"; -import { i18n } from "./i18n.js"; function nodes_in_my_group(node) { const nodes_in = new Set(); - node_graph(node)._groups.forEach((group) => { + node.graph._groups.forEach((group) => { if (!app.canvas.selected_group_moving) group.recomputeInsideNodes(); if (group._nodes?.find((nd) => { return (nd.id===node.id) } )) { group._nodes.forEach((nd) => { nodes_in.add(nd.id) } ) @@ -20,7 +19,7 @@ function nodes_in_my_group(node) { function nodes_not_in_my_group(node) { const nid = nodes_in_my_group(node); const nodes_not_in = []; - node_graph(node)._nodes.forEach((nd) => { + node.graph._nodes.forEach((nd) => { if (!nid.includes(nd.id)) nodes_not_in.push(nd.id); }); return nodes_not_in; @@ -51,10 +50,10 @@ function nodes_my_color(node, already_limited_to) { const color = node.color; if (already_limited_to) { already_limited_to.forEach((nid) => { - if (get_real_node(nid, node_graph(node)).color==color) nodes_in.add(nid) + if (get_real_node(nid, node.graph).color==color) nodes_in.add(nid) }) } else { - node_graph(node)._nodes.forEach((nd) => { + node.graph._nodes.forEach((nd) => { if (nd.color==color) nodes_in.add(nd.id) }) } @@ -66,10 +65,10 @@ function nodes_not_my_color(node, already_limited_to) { const color = get_real_node(node.id).color; if (already_limited_to) { already_limited_to.forEach((nid) => { - if (get_real_node(nid, node_graph(node)).color!=color) nodes_in.add(nid) + if (get_real_node(nid, node.graph).color!=color) nodes_in.add(nid) }) } else { - node_graph(node)._nodes.forEach((nd) => { + node.graph._nodes.forEach((nd) => { if (nd.color!=color) nodes_in.add(nd.id) }) } diff --git a/js/use_everywhere_utilities.js b/js/use_everywhere_utilities.js index d281a76..88a0390 100644 --- a/js/use_everywhere_utilities.js +++ b/js/use_everywhere_utilities.js @@ -1,6 +1,6 @@ import { app } from "../../scripts/app.js"; import { settingsCache } from "./use_everywhere_cache.js"; -import { link_is_from_subgraph_input, node_graph, visible_graph, wrap_input } from "./use_everywhere_subgraph_utils.js"; +import { link_is_from_subgraph_input, visible_graph, wrap_input } from "./use_everywhere_subgraph_utils.js"; import { i18n } from "./i18n.js"; export function create( tag, clss, parent, properties ) { @@ -53,7 +53,10 @@ export class Logger { static LIMITED_LOG_MS = 5000; static level; // 0 for errors only, 1 activates 'log_problem', 2 activates 'log_info', 3 activates 'log_detail' - static log_error(message) { console.error(message) } + static log_error(message, more) { + if (more) console.log(more) + console.error(message) + } static log(message, foreachable, limited) { if (limited && Logger.check_limited()) return @@ -145,7 +148,7 @@ class GraphConverter { if (node.inputs) { node.inputs.forEach((input) => { if (input.type=='*') { - const graph = node_graph(node); + const graph = node.graph; if (input.link) { const llink = graph.links[input.link]; if (link_is_from_subgraph_input(llink)) { @@ -335,7 +338,7 @@ export class Pausable { } export function get_connection(node, i) { - const graph = node_graph(node) + const graph = node.graph const in_link = node?.inputs[i]?.link; if (in_link) { var llink = graph.links[in_link]