From 0c0afed159fefc9abf2f41a824f5963887b5a90b Mon Sep 17 00:00:00 2001 From: JoshuaRiewesell <40123349+JoshuaRiewesell@users.noreply.github.com> Date: Mon, 19 Aug 2024 12:16:30 +0200 Subject: [PATCH] add quantity to actionNodes --- frontend/src/rete/import.ts | 7 ++++--- frontend/src/rete/nodes/action.ts | 23 ++++++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/frontend/src/rete/import.ts b/frontend/src/rete/import.ts index 26aee8b2..f4ed2841 100644 --- a/frontend/src/rete/import.ts +++ b/frontend/src/rete/import.ts @@ -46,19 +46,19 @@ export async function importEditor(context: Context, nodes: any) { for (const n of nodes) { if (n.type === "Action") { - let initial: DropdownOption = { + let initialSelection: DropdownOption = { name: "", value: "", } ActionIDs.find((action) => { if (action.id === n.action) { - initial = { + initialSelection = { name: action.name, value: action.id, } } }) - const node = new ActionNode(initial) + const node = new ActionNode(initialSelection, undefined, n.quantity) node.id = n.id await context.editor.addNode(node) } else { @@ -113,6 +113,7 @@ export function exportEditor(context: Context) { id: n.id, type: n.label, action: n.selection().value, + quantity: n.quantity(), next: { true: connections.filter(c => c.source === n.id && c.sourceOutput === "true")[0]?.target || null, false: connections.filter(c => c.source === n.id && c.sourceOutput === "false")[0]?.target || null, diff --git a/frontend/src/rete/nodes/action.ts b/frontend/src/rete/nodes/action.ts index 979960f7..37c581e7 100644 --- a/frontend/src/rete/nodes/action.ts +++ b/frontend/src/rete/nodes/action.ts @@ -35,14 +35,19 @@ export class ActionNode extends Classic.Node< { input: Classic.Socket; true: Classic.Socket; false: Classic.Socket }, { true: Classic.Socket; false: Classic.Socket }, - { selection: DropdownControl } + { selection: DropdownControl, quantity: Classic.InputControl<"number"> } > implements DataflowNode { width = 180 - height = 190 + height = 230 - constructor(initial?: DropdownOption, change?: (option: DropdownOption) => void) { + constructor( + initialSelection?: DropdownOption, + changeSelection?: (option: DropdownOption) => void, + initialQuantity?: number, + changeQuantity?: (value: number) => void + ) { super("Action") ActionIDs.sort((a, b) => a.name.localeCompare(b.name)) @@ -57,16 +62,24 @@ export class ActionNode name: action.name, value: action.id, })), - initial, - change, + initialSelection, + changeSelection, ) ) + this.addControl( + "quantity", + new Classic.InputControl("number", { initial: initialQuantity, change: changeQuantity }) + ) } selection() { return this.controls["selection"].selection } + quantity() { + return this.controls["quantity"].value + } + data() { const value = this.controls["selection"].selection