Pasting and duplicating nodes (#902)

* Pasting and duplicating nodes

* Rebind duplication

* Update selection on duplicate
This commit is contained in:
0HyperCube 2022-12-22 21:47:48 +00:00 committed by Keavon Chambers
parent 8f4f7b3cf1
commit af001f8db6
8 changed files with 119 additions and 2 deletions

View file

@ -300,7 +300,7 @@ import { defineComponent, nextTick } from "vue";
import type { IconName } from "@/utility-functions/icons";
import type { FrontendNodeLink } from "@/wasm-communication/messages";
import { UpdateNodeGraphSelection, FrontendNodeLink } from "@/wasm-communication/messages";
import LayoutCol from "@/components/layout/LayoutCol.vue";
import LayoutRow from "@/components/layout/LayoutRow.vue";
@ -721,6 +721,10 @@ export default defineComponent({
const outputPort2 = document.querySelectorAll(`[data-port="output"]`)[6] as HTMLDivElement | undefined;
const inputPort2 = document.querySelectorAll(`[data-port="input"]`)[3] as HTMLDivElement | undefined;
if (outputPort2 && inputPort2) this.createWirePath(outputPort2, inputPort2.getBoundingClientRect(), true, false);
this.editor.subscriptions.subscribeJsMessage(UpdateNodeGraphSelection, (updateNodeGraphSelection) => {
this.selected = updateNodeGraphSelection.selected;
});
},
components: {
IconLabel,

View file

@ -262,6 +262,8 @@ export function createInputManager(editor: Editor, container: HTMLElement, dialo
item.getAsString((text) => {
if (text.startsWith("graphite/layer: ")) {
editor.instance.pasteSerializedData(text.substring(16, text.length));
} else if (text.startsWith("graphite/nodes: ")) {
editor.instance.pasteSerializedNodes(text.substring(16, text.length));
}
});
}

View file

@ -33,11 +33,17 @@ export class UpdateNodeGraph extends JsMessage {
@Type(() => FrontendNodeLink)
readonly links!: FrontendNodeLink[];
}
export class UpdateNodeTypes extends JsMessage {
@Type(() => FrontendNode)
readonly nodeTypes!: FrontendNodeType[];
}
export class UpdateNodeGraphSelection extends JsMessage {
@Type(() => BigInt)
readonly selected!: bigint[];
}
export class UpdateNodeGraphVisibility extends JsMessage {
readonly visible!: boolean;
}
@ -1407,6 +1413,7 @@ export const messageMakers: Record<string, MessageMaker> = {
UpdateMouseCursor,
UpdateNodeGraph,
UpdateNodeGraphBarLayout,
UpdateNodeGraphSelection,
UpdateNodeTypes,
UpdateNodeGraphVisibility,
UpdateOpenDocumentsList,

View file

@ -627,6 +627,13 @@ impl JsEditorHandle {
self.dispatch(message);
}
/// Pastes the nodes based on serialized data
#[wasm_bindgen(js_name = pasteSerializedNodes)]
pub fn paste_serialized_nodes(&self, serialized_nodes: String) {
let message = NodeGraphMessage::PasteNodes { serialized_nodes };
self.dispatch(message);
}
/// Notifies the backend that the user double clicked a node
#[wasm_bindgen(js_name = doubleClickNode)]
pub fn double_click_node(&self, node: u64) {