Skip to content

Commit

Permalink
add quantity to actionNodes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaRiewesell committed Aug 19, 2024
1 parent 7af3869 commit 0c0afed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
7 changes: 4 additions & 3 deletions frontend/src/rete/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 18 additions & 5 deletions frontend/src/rete/nodes/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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

Expand Down

0 comments on commit 0c0afed

Please sign in to comment.