;
- colorRGBA: [number, number, number, number]
+ colorRGBA: ColorRGBA
- protected fromValue(colorRGBA: [number, number, number, number] ) {
+ protected fromValue(colorRGBA: ColorRGBA ) {
this.colorRGBA = colorRGBA
this.__properties = new Map()
const properties = this.getInitialProperties()
diff --git a/src/core/instances/AbstractType.ts b/src/core/instances/AbstractType.ts
index add9efd..6fd50b2 100644
--- a/src/core/instances/AbstractType.ts
+++ b/src/core/instances/AbstractType.ts
@@ -1,13 +1,27 @@
import AbstractSerializable from "./AbstractSerializable";
-export default class AbstractType extends AbstractSerializable<{type: string}> implements IType {
+type P = { name?: string, type: string, color?: ColorRGBA }
+export default class AbstractType extends AbstractSerializable implements IType {
+
_type: string
+ _color?: ColorRGBA
+ _name?: string;
getType(): string {
return this._type;
}
- from(props) {
+ from(props: P) {
this._type = props.type
+ this._name = props.name
+ this._color = props.color ?? [0, 0, 0, 0]
+ }
+
+ getColor(): ColorRGBA {
+ return this._color;
+ }
+
+ getName(): string {
+ return this._name;
}
}
diff --git a/src/core/instances/Comment.ts b/src/core/instances/Comment.ts
deleted file mode 100644
index 8e37dc3..0000000
--- a/src/core/instances/Comment.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import type CanvasRenderEngine from "../CanvasRenderEngine"
-import RendererUtil from "../util/RendererUtil"
-import AbstractDraggable from "./AbstractDraggable"
-
-
-export default class Comment extends AbstractDraggable implements ICommentDraggable {
- static of(props: CommentProps) {
- const instance = new Comment()
- instance.from(props)
- return instance
- }
-
- from(props: CommentProps) {
- super.from(props)
- this.height = 200
- }
-
- drawToCanvas() {
- const ctx = this.__canvas.__ctx
- RendererUtil.drawRoundedRect(ctx, this, 3, this.__canvas.__selectionMap.get(this.id) !== undefined, this.__canvas.lastSelection === this, `rgba(${[this.colorRGBA[0], this.colorRGBA[1], this.colorRGBA[2], .5]})`)
- RendererUtil.drawDraggableHeader(ctx, this)
- this.drawScale()
- }
-
- getInitialProperties(): MutableObject | undefined {
- return undefined;
- }
-}
diff --git a/src/core/instances/CommentDraggable.ts b/src/core/instances/CommentDraggable.ts
new file mode 100644
index 0000000..ccc0f0d
--- /dev/null
+++ b/src/core/instances/CommentDraggable.ts
@@ -0,0 +1,28 @@
+import RendererUtil from "../util/RendererUtil"
+import AbstractDraggable from "./AbstractDraggable"
+
+
+export default class CommentDraggable extends AbstractDraggable implements ICommentDraggable {
+ static of(props: AbstractDraggableProps) {
+ const instance = new CommentDraggable()
+ instance.from(props)
+ return instance
+ }
+
+ from(props: AbstractDraggableProps) {
+ super.from(props)
+ this.height = 200
+ }
+
+ drawToCanvas() {
+ const ctx = this.__canvas.__ctx
+ const state = this.__canvas.getState()
+ RendererUtil.drawDraggableBody(ctx, this, 3, state.selected.get(this.id) !== undefined, state.lastSelection === this, `rgba(${this.colorRGBA[0]}, ${this.colorRGBA[1]}, ${this.colorRGBA[2]}, .5)`)
+ RendererUtil.drawDraggableHeader(ctx, this)
+ this.drawScale()
+ }
+
+ getInitialProperties(): MutableObject | undefined {
+ return undefined;
+ }
+}
diff --git a/src/core/instances/Input.ts b/src/core/instances/Input.ts
index ba61881..f4f860f 100644
--- a/src/core/instances/Input.ts
+++ b/src/core/instances/Input.ts
@@ -7,7 +7,7 @@ export default class Input extends AbstractInput {
accept: IType[],
disabled: boolean,
visibleOnNode: boolean,
- colorRGBA?: [number, number, number, number]
+ colorRGBA?: ColorRGBA
}) {
const instance = new Input()
instance.from(props)
diff --git a/src/core/instances/Output.ts b/src/core/instances/Output.ts
index 645a10a..3e7e131 100644
--- a/src/core/instances/Output.ts
+++ b/src/core/instances/Output.ts
@@ -6,7 +6,7 @@ export default class Output extends AbstractOutput {
label: string,
type: IType,
disabled: boolean
- colorRGBA?: [number, number, number, number]
+ colorRGBA?: ColorRGBA
}){
const instance = new Output()
instance.from(props)
diff --git a/src/core/instances/PropertyType.ts b/src/core/instances/PropertyType.ts
index b5b660c..4a85980 100644
--- a/src/core/instances/PropertyType.ts
+++ b/src/core/instances/PropertyType.ts
@@ -1,9 +1,9 @@
import AbstractType from "./AbstractType";
export default class PropertyType extends AbstractType{
- static of(type: string) {
+ static of(type: string, name?: string, color?: ColorRGBA) {
const instance = new PropertyType()
- instance.from({type})
+ instance.from({type, color, name})
return instance
}
}
diff --git a/src/core/instances/Variable.ts b/src/core/instances/Variable.ts
new file mode 100644
index 0000000..97d3d58
--- /dev/null
+++ b/src/core/instances/Variable.ts
@@ -0,0 +1,17 @@
+export default class Variable implements IVariable{
+ _name: string;
+ _type: IType;
+
+ constructor(name: string, type: IType) {
+ this._name = name
+ this._type = type
+ }
+
+ getName(): string {
+ return this._name
+ }
+
+ getType(): IType {
+ return this._type;
+ }
+}
diff --git a/src/core/instances/VariableGetterNode.ts b/src/core/instances/VariableGetterNode.ts
new file mode 100644
index 0000000..abd662c
--- /dev/null
+++ b/src/core/instances/VariableGetterNode.ts
@@ -0,0 +1,42 @@
+import AbstractNode from "./AbstractNode";
+import Output from "./Output";
+import NodeType from "./NodeType";
+import {NodeTypes} from "../pscript.enum";
+
+export default class VariableGetterNode extends AbstractNode implements IVariableNode{
+ _variable: IVariable
+ nodeType = NodeType.of(NodeTypes.VAR);
+
+ getVariable(){
+ return this._variable
+ }
+
+ from(props: VariableProps) {
+ super.from(props)
+ this._variable = props.variable
+ }
+
+
+ getInitialProperties(): MutableObject {
+ return {truthy: false};
+ }
+
+ static of(props: VariableProps) {
+ const instance = new VariableGetterNode()
+ instance._variable = props.variable
+ instance.from({
+ ...props,
+ inputs: [],
+ outputs: [
+ Output.of({
+ key: "value",
+ label: "Value",
+ type: props.variable.getType(),
+ disabled: false,
+ colorRGBA: props.variable.getType().getColor()
+ })
+ ]
+ });
+ return instance
+ }
+}
diff --git a/src/core/instances/VariableSetterNode.ts b/src/core/instances/VariableSetterNode.ts
new file mode 100644
index 0000000..e87d473
--- /dev/null
+++ b/src/core/instances/VariableSetterNode.ts
@@ -0,0 +1,57 @@
+import AbstractNode from "./AbstractNode";
+import NodeType from "./NodeType";
+import {NodeTypes} from "../pscript.enum";
+import Input from "./Input";
+import Output from "./Output";
+import ExecutionInput from "./ExecutionInput";
+import ExecutionOutput from "./ExecutionOutput";
+
+export default class VariableSetterNode extends AbstractNode implements IVariableNode {
+ _variable: IVariable
+ nodeType = NodeType.of(NodeTypes.VAR);
+
+ getVariable() {
+ return this._variable
+ }
+
+ from(props: VariableProps) {
+ super.from(props)
+ this._variable = props.variable
+ }
+
+
+ getInitialProperties(): MutableObject {
+ return {truthy: false};
+ }
+
+
+ static of(props: VariableProps) {
+ const instance = new VariableSetterNode()
+ instance._variable = props.variable
+ instance.from({
+ ...props,
+ inputs: [
+ ExecutionInput.of("run", "Continue"),
+ Input.of({
+ key: "value",
+ label: "Value",
+ accept: [props.variable.getType()],
+ colorRGBA: props.variable.getType().getColor(),
+ disabled: false,
+ visibleOnNode: true
+ })
+ ],
+ outputs: [
+ ExecutionOutput.of("run", "Continue"),
+ Output.of({
+ key: "value",
+ label: "Value",
+ type: props.variable.getType(),
+ disabled: false,
+ colorRGBA: props.variable.getType().getColor()
+ })
+ ]
+ });
+ return instance
+ }
+}
diff --git a/src/core/libs/ActionHistory.ts b/src/core/libs/ActionHistory.ts
index 9e3167c..1bcaf68 100644
--- a/src/core/libs/ActionHistory.ts
+++ b/src/core/libs/ActionHistory.ts
@@ -1,6 +1,6 @@
import type CanvasRenderEngine from "../CanvasRenderEngine"
import AbstractNode from "../instances/AbstractNode"
-import Comment from "../instances/Comment"
+import CommentDraggable from "../instances/CommentDraggable"
import ToastNotificationSystem from "../../components/alert/ToastNotificationSystem";
import LocalizationEN from "../resources/LocalizationEN";
import UndoRedo from "./UndoRedo";
@@ -15,7 +15,7 @@ export default class ActionHistory {
this.#cache.history = [null]
}
- save(value: (AbstractNode | Comment)[], isRemoval?: boolean) {
+ save(value: (AbstractNode | CommentDraggable)[], isRemoval?: boolean) {
// if (value.length === 0)
// return
// const data = value.map(v => {
@@ -48,12 +48,12 @@ export default class ActionHistory {
#apply(action: IAction) {
const {toAdd, toRemove} = action
- this.canvas.removeDraggable(toRemove, true)
+ // CanvasStateUtil.removeDraggable(this.canvas.getId(), toRemove)
if (toAdd)
for (let i = 0; i < toAdd.length; i++) {
const current = toAdd[i]
if (current.DATA_TYPE === "comment") {
- // const parsed = new Comment(current.x, current.y)
+ // const parsed = new CommentDraggable(current.x, current.y)
// parsed.color = current.color
// parsed.name = current.name
// parsed.width = current.width
diff --git a/src/core/libs/CanvasStateStore.ts b/src/core/libs/CanvasStateStore.ts
new file mode 100644
index 0000000..00b389a
--- /dev/null
+++ b/src/core/libs/CanvasStateStore.ts
@@ -0,0 +1,73 @@
+import AbstractStore from "./AbstractStore"
+import CanvasRenderEngine from "../CanvasRenderEngine";
+
+export default class CanvasStateStore extends AbstractStore {
+ static silentlyUpdateProperty(instanceId: string, key: string, value: any) {
+ const state = this.getDataById(instanceId)
+
+ if (state != null) {
+ state[key] = value
+ }
+ }
+
+ static updateProperty(instanceId: string, key: string, value: any) {
+ const state = this.getDataById(instanceId)
+ if (state != null) {
+ state[key] = value
+ this.updateStore({[instanceId]: state})
+ }
+ }
+
+ static createState(id: string) {
+ const instance = new CanvasRenderEngine(id)
+ this.updateStore({
+ [id]: {
+ offsetX: 0,
+ offsetY: 0,
+ getId: () => id,
+ links: [],
+ nodes: [],
+ functions: [],
+ variables: [],
+ comments: [],
+ needsUpdate: false,
+ getInstance: () => instance,
+ grid: 20,
+ scale: 1,
+ defaultTextSize: 1,
+ smallTextSize: 1,
+ tempLinkCoords: {x: 0, y: 0, startY: 0, startX: 0, color: "white"},
+ drawTempLink: false,
+ selected: new Map(),
+ lastSelection: undefined,
+ variableNames: {}
+ }
+ })
+ return instance
+ }
+
+ static getDataById(id: string): RendererState | undefined {
+ return this.getData()[id]
+ }
+
+ static triggerDelayedUpdate(instanceId: string) {
+ const state = this.getDataById(instanceId)
+ console.trace(state, instanceId)
+ if (state != null) {
+ this.updateStore({[instanceId]: state})
+ }
+ }
+
+ static destroyState(id: string) {
+ const data = this.getData()
+ const current = data[id] as RendererState
+ if (current != null) {
+ current.getInstance().stop()
+ current.getInstance().__observer.disconnect()
+ delete data[id]
+ this.updateStore(data)
+ }
+ }
+
+}
+
diff --git a/src/core/libs/PScriptRendererState.ts b/src/core/libs/PScriptRendererState.ts
deleted file mode 100644
index 292d912..0000000
--- a/src/core/libs/PScriptRendererState.ts
+++ /dev/null
@@ -1,58 +0,0 @@
-import DynamicMap from "./DynamicMap";
-import CanvasRenderEngine from "../CanvasRenderEngine";
-
-export default class PScriptRendererState {
- static #state = new DynamicMap>()
-
- static getState(id: string) {
- return this.#state.get(id)
- }
-
- static createState(id: string) {
- const instance = new CanvasRenderEngine(id)
- this.#state.set(id, {
- offsetX: 0,
- offsetY: 0,
- getId: () => id,
- links: [],
- nodes: [],
- functions: [],
- comments: [],
- needsUpdate: false,
- getInstance: () => instance,
- grid: 20,
- scale: 1,
- backgroundColor: "#292929",
- rectColor: "#353535",
- borderColor: "#6b6b6b",
- defaultFont: "10px Roboto",
- smallFont: "9px Roboto",
- textColor: "#f0f0f0",
- defaultTextSize: 1,
- smallTextSize: 1,
- firstSelectionColor: "white",
- multiSelectionColor: "darkorange",
- ioTextColor: "#e0e0e0",
- tempLinkCoords: {x: 0, y: 0, startY: 0, startX: 0, color: "white"},
- drawTempLink: false,
- executionIOColor: "white"
- })
- return instance
- }
-
- static destroyState(id: string) {
- if (!this.#state.has(id))
- return
- const state = this.#state.get(id)
- state.getInstance().stop()
- state.getInstance().__observer.disconnect()
-
-
- this.#state.delete(id)
- }
-
- static setState(canvas: CanvasRenderEngine, canvasRenderEngineRendererState: RendererState) {
- this.#state.delete(canvas.getId())
- this.#state.set(canvas.getId(), canvasRenderEngineRendererState)
- }
-}
diff --git a/src/core/libs/Serializer.ts b/src/core/libs/Serializer.ts
index ed09828..a08f292 100644
--- a/src/core/libs/Serializer.ts
+++ b/src/core/libs/Serializer.ts
@@ -1,5 +1,4 @@
-import AbstractStateful from "../instances/AbstractStateful";
-import Comment from "../instances/Comment"
+import CommentDraggable from "../instances/CommentDraggable"
import PropertyType from "../instances/PropertyType";
import NodeType from "../instances/NodeType";
import Output from "../instances/Output";
@@ -7,15 +6,13 @@ import Input from "../instances/Input";
import ExecutionLink from "../instances/ExecutionLink";
import ExecutionOutput from "../instances/ExecutionOutput";
import ExecutionInput from "../instances/ExecutionInput";
-import Bend from "../instances/Bend";
import AbstractSerializable from "../instances/AbstractSerializable";
import CanvasRenderEngine from "../CanvasRenderEngine";
-import AbstractNode from "../instances/AbstractNode";
import AbstractDraggable from "../instances/AbstractDraggable";
export default class Serializer {
static #types: typeof AbstractSerializable[] = [
- Comment,
+ CommentDraggable,
ExecutionInput,
ExecutionOutput,
ExecutionLink,
diff --git a/src/core/pscript.enum.ts b/src/core/pscript.enum.ts
index 9a5af73..f436408 100644
--- a/src/core/pscript.enum.ts
+++ b/src/core/pscript.enum.ts
@@ -21,4 +21,11 @@ enum MaterialDataTypes {
UNDEFINED = "-1"
}
-export {MaterialDataTypes}
+enum NodeTypes {
+ FUNCTION = "func",
+ CONST = "const",
+ VAR = "var",
+ STRUCT = "struct"
+}
+
+export {MaterialDataTypes, NodeTypes}
diff --git a/src/core/pscript.g.ts b/src/core/pscript.g.ts
index 3e1bf1f..8b8521c 100644
--- a/src/core/pscript.g.ts
+++ b/src/core/pscript.g.ts
@@ -1,28 +1,41 @@
+interface IFunctionNode {
+
+}
+
+type ColorRGBA = [number, number, number, number]
+
+interface IVariableNode extends INodeDraggable {
+ _variable: IVariable;
+ getVariable: () => IVariable
+}
+
interface ISerializable {
from(props: T)
}
+interface VariableProps extends NodeProps {
+ variable: IVariable
+}
+
type NodeProps = {
canvas: IRenderEngine;
x: number;
y: number;
label: string;
- colorRGBA: [number, number, number, number];
+ colorRGBA: ColorRGBA;
outputs?: IOutput[];
inputs?: IInput[];
}
-type CommentProps = {
+type AbstractDraggableProps = {
canvas: IRenderEngine;
x: number;
y: number;
label: string;
- colorRGBA: [number, number, number, number];
+ colorRGBA: ColorRGBA;
}
interface IRenderEngine {
- lastSelection: IDraggable;
- __selectionMap: Map;
__observer: ResizeObserver;
stop: VoidFunction;
__ctx: CanvasRenderingContext2D;
@@ -30,11 +43,11 @@ interface IRenderEngine {
getState(): RendererState;
}
-interface IStateful extends ISerializable{
+interface IStateful extends ISerializable {
__properties: Map;
setProperty: (key: string, value: any) => void;
getProperty: (key: string) => T;
- colorRGBA: [number, number, number, number];
+ colorRGBA: ColorRGBA;
}
interface IDraggable extends IStateful {
@@ -73,7 +86,7 @@ interface IBend {
y: number
}
-interface ILink extends ISerializable{
+interface ILink extends ISerializable {
input: IInput,
output: IOutput,
targetNode: INodeDraggable,
@@ -87,7 +100,9 @@ interface IAction {
}
interface IType {
- getType: () => string
+ getType(): string
+
+ getColor(): ColorRGBA
}
@@ -110,13 +125,25 @@ interface IInput extends IStateful {
acceptsType(type: IType): boolean;
}
+interface IVariable {
+ _name: string;
+ _type: IType;
+
+ getName(): string
-interface RendererState {
+ getType(): IType
+}
+
+/**
+ * Should act like a function scope
+ */
+type RendererState = {
getId: GenericNonVoidFunction,
links: ILink[],
nodes: INodeDraggable[],
functions: IFunctionDraggable[],
comments: ICommentDraggable[],
+ variables: IVariable[],
needsUpdate: boolean,
getInstance: () => T,
@@ -124,17 +151,8 @@ interface RendererState {
offsetY: number,
grid: number,
scale: number,
- backgroundColor: string,
- rectColor: string,
- borderColor: string,
defaultTextSize: number,
smallTextSize: number,
- defaultFont: string,
- smallFont: string,
- textColor: string,
- firstSelectionColor: string,
- multiSelectionColor: string,
- ioTextColor: string,
tempLinkCoords: {
x: number,
y: number,
@@ -142,7 +160,10 @@ interface RendererState {
startY: number,
color: string
},
- drawTempLink: boolean
- executionIOColor: string
+ drawTempLink: boolean,
+
+ selected: Map,
+ lastSelection: IDraggable,
+ variableNames: { [key: string]: boolean }
}
diff --git a/src/core/resources/GlobalStyles.ts b/src/core/resources/GlobalStyles.ts
new file mode 100644
index 0000000..0097a28
--- /dev/null
+++ b/src/core/resources/GlobalStyles.ts
@@ -0,0 +1,15 @@
+export default class GlobalStyles {
+ static rectColor = "#353535";
+ static borderColor = "#6b6b6b";
+ static defaultFont = "10px Roboto";
+ static smallFont = "9px Roboto";
+ static textColor = "#f0f0f0";
+ static firstSelectionColor = "white";
+ static multiSelectionColor = "darkorange";
+ static ioTextColor = "#e0e0e0";
+ static executionIOColor = "white";
+
+ static IO_RADIUS = 4
+ static HEADER_HEIGHT = 25
+ static SCALE_BUTTON_SIZE = 10
+}
diff --git a/src/core/util/CanvasStateUtil.ts b/src/core/util/CanvasStateUtil.ts
new file mode 100644
index 0000000..4261639
--- /dev/null
+++ b/src/core/util/CanvasStateUtil.ts
@@ -0,0 +1,185 @@
+import AbstractLink from "../instances/AbstractLink";
+import CanvasStateStore from "../libs/CanvasStateStore";
+import AbstractNode from "../instances/AbstractNode";
+import CommentDraggable from "../instances/CommentDraggable";
+import VariableGetterNode from "../instances/VariableGetterNode";
+import VariableSetterNode from "../instances/VariableSetterNode";
+import Variable from "../instances/Variable";
+
+export default class CanvasStateUtil {
+ static addLink(id: string, link: AbstractLink, noUpdate?: boolean) {
+ const state = CanvasStateStore.getDataById(id)
+ const foundExisting = state.links.findIndex(l => l.input === link.input)
+ if (foundExisting > -1)
+ state.links[foundExisting] = link
+ else
+ state.links.push(link)
+ if (!noUpdate)
+ state.needsUpdate = true
+ CanvasStateStore.triggerDelayedUpdate(id)
+ }
+
+ static removeLink(id: string, index: number) {
+ const state = CanvasStateStore.getDataById(id)
+ state.links.splice(index, 1)
+ state.needsUpdate = true
+ CanvasStateStore.triggerDelayedUpdate(id)
+ }
+
+
+ static removeLinks(id: string, links: ILink[]) {
+ const state = CanvasStateStore.getDataById(id)
+ state.links = state.links.filter(l => !links.includes(l))
+ state.needsUpdate = true
+ CanvasStateStore.triggerDelayedUpdate(id)
+ }
+
+
+ static addDraggable(id: string, node: IDraggable) {
+ const state = CanvasStateStore.getDataById(id)
+ if (node instanceof CommentDraggable) {
+ state.comments.push(node)
+ } else {
+ state.nodes.push(node)
+ }
+ state.needsUpdate = true
+ CanvasStateStore.triggerDelayedUpdate(id)
+ }
+
+ static removeDraggable(id: string, toRemove: INodeDraggable[]) {
+ const state = CanvasStateStore.getDataById(id)
+ const focusedFunction = CanvasStateStore.getData().focusedFunction
+ const toRemoveMap = {}
+ for (let i = 0; i < toRemove.length; i++) {
+ const draggable = toRemove[i];
+ state.selected.delete(draggable.id)
+ toRemoveMap[draggable.id] = draggable
+ if (focusedFunction === draggable.id) {
+ CanvasStateStore.updateProperty(id, "focusedFunction", undefined)
+ }
+ if (draggable instanceof AbstractNode) {
+ const index = state.nodes.indexOf(draggable)
+ if (index > -1) {
+ state.nodes.splice(index, 1)
+ }
+ } else {
+ const index = state.comments.indexOf(draggable)
+ state.comments.splice(index, 1)
+ }
+ }
+
+ const linksToRemove = state.links.flatMap((l, index) => {
+ return (toRemoveMap[l.sourceNode.id] != null || toRemoveMap[l.targetNode.id] != null) ? [l] : []
+ })
+ CanvasStateUtil.removeLinks(id, linksToRemove)
+
+ state.needsUpdate = true
+ CanvasStateStore.triggerDelayedUpdate(id)
+ }
+
+ static addVariable(id: string, type: IType, variableName: string): boolean {
+ const state = CanvasStateStore.getDataById(id)
+ console.trace(state.variableNames, variableName)
+ if (state.variableNames[variableName])
+ return false
+ state.variableNames[variableName] = true
+ state.variables.push(new Variable(variableName, type))
+ CanvasStateStore.triggerDelayedUpdate(id)
+ return true
+ }
+
+ static removeVariable(id: string, variableName: string) {
+ const state = CanvasStateStore.getDataById(id)
+ const variableIndex = state.variables.findIndex(v => v.getName() === variableName)
+
+ if (variableIndex > -1) {
+ const nodesWithVariable = state.nodes.filter(n => {
+ return (n instanceof VariableGetterNode || n instanceof VariableSetterNode) && n.getVariable().getName() === variableName
+ })
+ this.removeDraggable(id, nodesWithVariable)
+ const variablesRemoved = state.variables.splice(variableIndex, 1)
+
+ delete state.variableNames[variablesRemoved[0].getName()]
+ CanvasStateStore.triggerDelayedUpdate(id)
+ }
+ }
+
+ static addVariableGetter(id: string, x: number, y: number, variableName: string) {
+ const state = CanvasStateStore.getDataById(id)
+ const variable = state.variables.find(v => v.getName() === variableName)
+ if (variable != null) {
+ const newNode = VariableGetterNode.of({
+ variable,
+ canvas: state.getInstance(),
+ x,
+ y,
+ label: variableName + " (GETTER)",
+ colorRGBA: variable.getType().getColor()
+ })
+ state.nodes.push(newNode)
+ state.needsUpdate = true
+ CanvasStateStore.triggerDelayedUpdate(id)
+ }
+ }
+
+ static addVariableSetter(id: string, x: number, y: number, variableName: string) {
+ const state = CanvasStateStore.getDataById(id)
+ const name = variableName.toLowerCase()
+ const variable = state.variables.find(v => v.getName() === name)
+ if (variable != null) {
+ const newNode = VariableSetterNode.of({
+ variable,
+ canvas: state.getInstance(),
+ x,
+ y,
+ label: variableName + " (SETTER)",
+ colorRGBA: variable.getType().getColor()
+ })
+ state.nodes.push(newNode)
+ state.needsUpdate = true
+ CanvasStateStore.triggerDelayedUpdate(id)
+ }
+ }
+
+ static renameVariable(id: string, variable: IVariable, value: string) {
+ const state = CanvasStateStore.getDataById(id)
+ delete state.variableNames[variable._name]
+ variable._name = value
+ state.variableNames[value] = true
+ state.nodes.forEach(n => {
+ if (n instanceof VariableGetterNode && n.getVariable() === variable) {
+ n.label = value + " (GETTER)"
+ } else if (n instanceof VariableSetterNode && n.getVariable() === variable) {
+ n.label = value + " (SETTER)"
+ }
+ })
+ state.needsUpdate = true
+ CanvasStateStore.triggerDelayedUpdate(id)
+ }
+
+ static changeVariableType(id: string, variable: IVariable, value: IType) {
+ const state = CanvasStateStore.getDataById(id)
+ variable._type = value
+ let nodesToRecreate: IVariableNode[] = state.nodes.filter(n => {
+ return (n instanceof VariableGetterNode || n instanceof VariableSetterNode) && n.getVariable() === variable
+ })
+ CanvasStateUtil.removeDraggable(id, nodesToRecreate)
+ nodesToRecreate = nodesToRecreate.map(n => {
+ const variableProps = {
+ variable: n._variable,
+ canvas: state.getInstance(),
+ x: n.x,
+ y: n.y,
+ label: n.label,
+ colorRGBA: variable.getType().getColor()
+ }
+ if (n instanceof VariableGetterNode)
+ return VariableGetterNode.of(variableProps)
+ else if (n instanceof VariableSetterNode)
+ return VariableSetterNode.of(variableProps)
+ })
+ state.nodes.push(...nodesToRecreate)
+ state.needsUpdate = true
+ CanvasStateStore.triggerDelayedUpdate(id)
+ }
+}
diff --git a/src/core/util/IDraggableUtil.ts b/src/core/util/IDraggableUtil.ts
index 07885bb..0f88b91 100644
--- a/src/core/util/IDraggableUtil.ts
+++ b/src/core/util/IDraggableUtil.ts
@@ -1,9 +1,12 @@
import AbstractDraggable from "../instances/AbstractDraggable"
import AbstractNode from "../instances/AbstractNode"
import RendererUtil from "./RendererUtil";
-import Comment from "../instances/Comment";
+import CommentDraggable from "../instances/CommentDraggable";
import CanvasRenderEngine from "../CanvasRenderEngine";
import PScriptUtil from "./PScriptUtil";
+import CanvasStateStore from "../libs/CanvasStateStore";
+import CanvasStateUtil from "./CanvasStateUtil";
+import GlobalStyles from "../resources/GlobalStyles";
export default class IDraggableUtil {
@@ -24,10 +27,10 @@ export default class IDraggableUtil {
const coord = node.getTransformedCoordinates()
const xN = coord.x, yN = coord.y, w = node.width
- const H = AbstractDraggable.HEADER_HEIGHT - 5
+ const H = GlobalStyles.HEADER_HEIGHT - 5
const Y = yN + H * (index + 2)
const xIO = !asOutput ? xN : xN + w
- const yIO = Y - AbstractNode.IO_RADIUS
+ const yIO = Y - GlobalStyles.IO_RADIUS
return {x: xIO, y: yIO, height: H, width: w, rowY: Y}
@@ -79,19 +82,22 @@ export default class IDraggableUtil {
}, nodesOnDrag, canvasAPI: CanvasRenderEngine, parentBBox, parentElement: HTMLElement, event: MouseEvent) {
const state = canvasAPI.getState()
const nodes = state.nodes
- const comments = state.comments
+ const comments = state.comments
const links = state.links
const X = (event.clientX - BBox.x) / state.scale
const Y = (event.clientY - BBox.y) / state.scale
+ const selectionMap = canvasAPI.getState().selected
if (!event.ctrlKey) {
- canvasAPI.lastSelection = undefined
- canvasAPI.__selectionMap.clear()
- } else
- canvasAPI.__selectionMap.forEach(node => {
+ CanvasStateStore.updateStore({lastSelection: undefined})
+ selectionMap.clear()
+ } else {
+ selectionMap.forEach(node => {
nodesOnDrag.push(IDraggableUtil.drag(event, node, parentBBox, true))
})
+ }
+
let executionBroken = false
for (let i = nodes.length - 1; i >= 0; i--) {
@@ -100,8 +106,8 @@ export default class IDraggableUtil {
const onHeader = node.checkHeaderClick(X, Y)
if (!onHeader && !onBody)
continue
- canvasAPI.__selectionMap.set(node.id, node)
- canvasAPI.lastSelection = node
+ selectionMap.set(node.id, node)
+ CanvasStateStore.updateProperty(canvasAPI.getId(), "lastSelection", node)
if (onHeader) {
nodesOnDrag.push(IDraggableUtil.drag(event, node, parentBBox, true))
node.isOnDrag = true
@@ -132,7 +138,6 @@ export default class IDraggableUtil {
executionBroken = true
break
}
-
if (!executionBroken) {
for (let i = comments.length - 1; i >= 0; i--) {
const comment = comments[i]
@@ -145,6 +150,7 @@ export default class IDraggableUtil {
}
}
+ CanvasStateStore.triggerDelayedUpdate(canvasAPI.getId())
if (nodesOnDrag.length > 0 || IO.node !== undefined)
canvasAPI.__ctx.canvas.style.cursor = "grabbing"
canvasAPI.clear()
@@ -174,7 +180,7 @@ export default class IDraggableUtil {
IO.node = found.sourceNode
IO.output = found.output
- canvasAPI.removeLink(linkIndex)
+ CanvasStateUtil.removeLink(canvasAPI.getId(), linkIndex)
const state = canvasAPI.getState()
state.tempLinkCoords.startX = originalPosition.x
state.tempLinkCoords.startY = originalPosition.y
@@ -182,7 +188,7 @@ export default class IDraggableUtil {
RendererUtil.drawTempLink(event, parentElement, parentBBox, canvasAPI)
}
- private static processCommentClick(onHeader: boolean, nodesOnDrag, event: MouseEvent, comment: Comment, parentBBox, X: number, Y: number, canvasAPI: CanvasRenderEngine) {
+ private static processCommentClick(onHeader: boolean, nodesOnDrag, event: MouseEvent, comment: CommentDraggable, parentBBox, X: number, Y: number, canvasAPI: CanvasRenderEngine) {
if (onHeader) {
nodesOnDrag.push(IDraggableUtil.drag(event, comment, parentBBox, true))
comment.isOnDrag = true
@@ -193,8 +199,10 @@ export default class IDraggableUtil {
comment.isOnDrag = true
}
}
- canvasAPI.__selectionMap.set(comment.id, comment)
- canvasAPI.lastSelection = comment
+
+ canvasAPI.getState().selected.set(comment.id, comment)
+ CanvasStateStore.silentlyUpdateProperty(canvasAPI.getId(), "lastSelection", comment)
+ CanvasStateStore.triggerDelayedUpdate(canvasAPI.getId())
}
static #checkOffset(ev1: MouseEvent, ev2: { x: number, y: number }): boolean {
diff --git a/src/core/util/MathUtil.ts b/src/core/util/MathUtil.ts
new file mode 100644
index 0000000..7387384
--- /dev/null
+++ b/src/core/util/MathUtil.ts
@@ -0,0 +1,27 @@
+export default class MathUtil {
+ static isPointInsideCircle(x: number, y: number, centerX: number, centerY: number, radiusSquared: number): boolean {
+ return ((x - centerX) ** 2 + (y - centerY) ** 2 < radiusSquared)
+ }
+
+ static isPointInsideRect(x: number, y: number, centerX: number, centerY: number, width: number, height: number): boolean {
+ const XI = centerX + width
+ const YI = centerY + height
+ return x >= centerX && x <= XI && y >= centerY && y < YI
+ }
+
+ static #areaOfTriangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number) {
+ return Math.abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0);
+ }
+
+ static isPointInsideTriangle(x: number, y: number, positions: [number, number, number, number, number, number]): boolean {
+ const x1 = positions[0], y1 = positions[1],
+ x2 = positions[2], y2 = positions[3],
+ x3 = positions[4], y3 = positions[5]
+
+ const A = this.#areaOfTriangle(x1, y1, x2, y2, x3, y3);
+ const A1 = this.#areaOfTriangle(x, y, x2, y2, x3, y3);
+ const A2 = this.#areaOfTriangle(x1, y1, x, y, x3, y3);
+ const A3 = this.#areaOfTriangle(x1, y1, x2, y2, x, y);
+ return (A === A1 + A2 + A3);
+ }
+}
diff --git a/src/core/util/PScriptUtil.ts b/src/core/util/PScriptUtil.ts
index fff192d..c62587f 100644
--- a/src/core/util/PScriptUtil.ts
+++ b/src/core/util/PScriptUtil.ts
@@ -4,6 +4,7 @@ import {MaterialDataTypes} from "../pscript.enum";
import LocalizationEN from "../resources/LocalizationEN";
import ToastNotificationSystem from "../../components/alert/ToastNotificationSystem";
import Link from "../instances/Link";
+import CanvasStateUtil from "./CanvasStateUtil";
export default class PScriptUtil {
/**
@@ -16,7 +17,7 @@ export default class PScriptUtil {
biggestX: number | undefined,
biggestY: number | undefined
- canvasAPI.__selectionMap
+ canvasAPI.getState().selected
.forEach(n => {
if (!smallestX || n.x < smallestX)
smallestX = n.x
@@ -70,7 +71,7 @@ export default class PScriptUtil {
const targetIO = node.checkAgainstIO(X, Y, true)
if (targetIO?.acceptsType?.(sourceIO.type)) {
const newLink = Link.of(node, sourceNode, targetIO, sourceIO)
- canvasAPI.addLink(newLink)
+ CanvasStateUtil.addLink(canvasAPI.getId(), newLink)
} else if (targetIO) {
ToastNotificationSystem.getInstance().error(LocalizationEN.INVALID_TYPE)
}
diff --git a/src/core/util/RendererUtil.ts b/src/core/util/RendererUtil.ts
index dd6ea2d..2270d6d 100644
--- a/src/core/util/RendererUtil.ts
+++ b/src/core/util/RendererUtil.ts
@@ -1,10 +1,10 @@
-import AbstractNode from "../instances/AbstractNode"
import type AbstractLink from "../instances/AbstractLink"
import IDraggableUtil from "./IDraggableUtil"
import AbstractDraggable from "../instances/AbstractDraggable";
import CanvasRenderEngine from "../CanvasRenderEngine";
import ExecutionInput from "../instances/ExecutionInput";
import ExecutionOutput from "../instances/ExecutionOutput";
+import GlobalStyles from "../resources/GlobalStyles";
export default class RendererUtil {
@@ -35,25 +35,25 @@ export default class RendererUtil {
let label = attribute.label
if (attribute instanceof ExecutionInput) {
- ctx.strokeStyle = state.borderColor
- ctx.fillStyle = state.executionIOColor
+ ctx.strokeStyle = GlobalStyles.borderColor
+ ctx.fillStyle = GlobalStyles.executionIOColor
ctx.lineWidth = .5
- X = X + AbstractNode.IO_RADIUS * 2
- this.#drawTriangleIOExecution(linePosition.y, X + AbstractNode.IO_RADIUS, ctx);
+ X = X + GlobalStyles.IO_RADIUS * 2
+ this.#drawTriangleIOExecution(linePosition.y, X + GlobalStyles.IO_RADIUS, ctx);
} else {
- ctx.font = state.smallFont
- ctx.strokeStyle = state.borderColor
+ ctx.font = GlobalStyles.smallFont
+ ctx.strokeStyle = GlobalStyles.borderColor
ctx.beginPath()
ctx.fillStyle = IDraggableUtil.getIOColor(attribute, attribute.disabled)
ctx.lineWidth = .5
- ctx.arc(X, YA, AbstractNode.IO_RADIUS, 0, Math.PI * 2)
+ ctx.arc(X, YA, GlobalStyles.IO_RADIUS, 0, Math.PI * 2)
ctx.fill()
ctx.stroke()
}
if (!attribute.hideLabel) {
- X -= AbstractNode.IO_RADIUS
- ctx.fillStyle = state.ioTextColor
+ X -= GlobalStyles.IO_RADIUS
+ ctx.fillStyle = GlobalStyles.ioTextColor
let X_P = X + this.#LABEL_OFFSET
ctx.fillText(label, X_P, Y)
ctx.closePath()
@@ -71,40 +71,39 @@ export default class RendererUtil {
const labelSize = state.smallTextSize * label.length + this.#LABEL_OFFSET
if (attribute instanceof ExecutionOutput) {
- ctx.strokeStyle = state.borderColor
- ctx.fillStyle = state.executionIOColor
+ ctx.strokeStyle = GlobalStyles.borderColor
+ ctx.fillStyle = GlobalStyles.executionIOColor
ctx.lineWidth = .5
- this.#drawTriangleIOExecution(linePosition.y, linePosition.x - AbstractNode.IO_RADIUS, ctx);
+ this.#drawTriangleIOExecution(linePosition.y, linePosition.x - GlobalStyles.IO_RADIUS, ctx);
} else {
- ctx.font = state.smallFont
- ctx.strokeStyle = state.borderColor
+ ctx.font = GlobalStyles.smallFont
+ ctx.strokeStyle = GlobalStyles.borderColor
ctx.beginPath()
ctx.fillStyle = IDraggableUtil.getIOColor(attribute, false)
ctx.lineWidth = .5
- ctx.arc(X, YA, AbstractNode.IO_RADIUS, 0, Math.PI * 2)
+ ctx.arc(X, YA, GlobalStyles.IO_RADIUS, 0, Math.PI * 2)
ctx.fill()
ctx.stroke()
}
if (!attribute.hideLabel) {
- X -= AbstractNode.IO_RADIUS * 2
- ctx.fillStyle = state.ioTextColor
+ X -= GlobalStyles.IO_RADIUS * 2
+ ctx.fillStyle = GlobalStyles.ioTextColor
ctx.fillText(label, X - labelSize + this.#LABEL_OFFSET, Y)
ctx.closePath()
}
}
static drawDraggablePosition(ctx: CanvasRenderingContext2D, draggable: IDraggable) {
- const state = draggable.__canvas.getState()
- ctx.font = state.defaultFont
+ ctx.font = GlobalStyles.defaultFont
const coord = draggable.getTransformedCoordinates()
const TEXT = `X ${coord.x} Y ${coord.y} W ${draggable.width} H ${draggable.height}`
let Y = coord.y - 10
if (Y < 0)
Y = coord.y + draggable.height + 10
ctx.beginPath()
- ctx.fillStyle = state.textColor
+ ctx.fillStyle = GlobalStyles.textColor
ctx.fillText(TEXT, coord.x, Y)
}
@@ -114,8 +113,8 @@ export default class RendererUtil {
const coordS = S.getTransformedCoordinates()
const coordT = T.getTransformedCoordinates()
const x1 = coordS.x + S.width, x2 = coordT.x,
- y1 = coordS.y + AbstractDraggable.HEADER_HEIGHT + AbstractNode.IO_RADIUS * 3 + S.outputs.indexOf(link.output) * 20,
- y2 = coordT.y + AbstractDraggable.HEADER_HEIGHT + AbstractNode.IO_RADIUS * 3 + T.inputs.indexOf(link.input) * 20
+ y1 = coordS.y + GlobalStyles.HEADER_HEIGHT + GlobalStyles.IO_RADIUS * 3 + S.outputs.indexOf(link.output) * 20,
+ y2 = coordT.y + GlobalStyles.HEADER_HEIGHT + GlobalStyles.IO_RADIUS * 3 + T.inputs.indexOf(link.input) * 20
const isSomeoneDisabled = link.output.disabled || link.input.disabled
ctx.strokeStyle = IDraggableUtil.getIOColor(link.output, isSomeoneDisabled)
@@ -131,23 +130,22 @@ export default class RendererUtil {
state.needsUpdate = true
}
- static drawDraggableHeader(ctx: CanvasRenderingContext2D, node: IDraggable) {
- const state = node.__canvas.getState()
+ static drawDraggableHeader(ctx: CanvasRenderingContext2D, node: IDraggable, borderRadius?: number) {
const name = node.label
const color = node.colorRGBA
const coord = node.getTransformedCoordinates()
ctx.beginPath()
ctx.fillStyle = `rgb(${color})`
- ctx.strokeStyle = node.__canvas.getState().borderColor
+ ctx.strokeStyle = GlobalStyles.borderColor
ctx.lineWidth = .5
- ctx.roundRect(coord.x, coord.y, node.width, RendererUtil.#HEADER_LABEL_HEIGHT, RendererUtil.#BORDER_RADIUS)
+ ctx.roundRect(coord.x, coord.y, node.width, RendererUtil.#HEADER_LABEL_HEIGHT, borderRadius ?? RendererUtil.#BORDER_RADIUS)
ctx.stroke()
ctx.fill()
- ctx.font = state.defaultFont
+ ctx.font = GlobalStyles.defaultFont
- ctx.fillStyle = state.textColor
- ctx.fillText(name, coord.x + AbstractNode.IO_RADIUS, coord.y + RendererUtil.#OFFSET_Y_TITLE)
+ ctx.fillStyle = GlobalStyles.textColor
+ ctx.fillText(name, coord.x + GlobalStyles.IO_RADIUS, coord.y + RendererUtil.#OFFSET_Y_TITLE)
ctx.closePath()
}
@@ -164,23 +162,27 @@ export default class RendererUtil {
}
- static drawRoundedRect(ctx: CanvasRenderingContext2D, node: AbstractDraggable, r: number, isSelected: boolean, isFirstSelected: boolean, color: string) {
+ static drawDraggableBody(ctx: CanvasRenderingContext2D, node: AbstractDraggable, r: number, isSelected: boolean, isFirstSelected: boolean, color: string) {
const coord = node.getTransformedCoordinates()
- const state = node.__canvas.getState()
const w = node.width, h = node.height, x = coord.x, y = coord.y
if (w < 2 * r) r = w / 2
if (h < 2 * r) r = h / 2
- let outlineColor = state.borderColor
+ let outlineColor = GlobalStyles.borderColor
if (isSelected) {
- outlineColor = isFirstSelected ? state.firstSelectionColor : state.multiSelectionColor
+ outlineColor = isFirstSelected ? GlobalStyles.firstSelectionColor : GlobalStyles.multiSelectionColor
}
ctx.fillStyle = color
ctx.lineWidth = isSelected ? 2 : 1
ctx.strokeStyle = outlineColor
+ RendererUtil.drawRoundedRect(ctx, x, y, w, h, r)
+ }
+
+ static drawRoundedRect(ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, r: number) {
ctx.beginPath()
ctx.roundRect(x, y, w, h, r)
- ctx.stroke()
ctx.fill()
+ ctx.closePath()
+ ctx.stroke()
}
}
diff --git a/src/environment/javascript/JavascriptScriptingView.svelte b/src/environment/javascript/JavascriptScriptingView.svelte
index 9c4d0c6..2a994a2 100644
--- a/src/environment/javascript/JavascriptScriptingView.svelte
+++ b/src/environment/javascript/JavascriptScriptingView.svelte
@@ -1,23 +1,23 @@
-
-
+>
+
+
diff --git a/src/environment/javascript/all-types.ts b/src/environment/javascript/all-types.ts
new file mode 100644
index 0000000..34f2a33
--- /dev/null
+++ b/src/environment/javascript/all-types.ts
@@ -0,0 +1,7 @@
+import PropertyType from "../../core/instances/PropertyType";
+import Types, {Colors} from "./javascript.enum";
+
+export default {
+ [Types.BOOLEAN]: PropertyType.of(Types.BOOLEAN, "Boolean", Colors.BOOLEAN),
+ [Types.NUMBER]: PropertyType.of(Types.NUMBER, "Numeric", Colors.NUMBER),
+}
diff --git a/src/environment/javascript/basic-functions/Add.ts b/src/environment/javascript/basic-functions/Add.ts
index 232933e..e4e1377 100644
--- a/src/environment/javascript/basic-functions/Add.ts
+++ b/src/environment/javascript/basic-functions/Add.ts
@@ -1,12 +1,12 @@
import AbstractNode from "../../../core/instances/AbstractNode";
-import Types, {Colors, NodeTypes} from "../javascript.enum";
-
-import PropertyType from "../../../core/instances/PropertyType";
+import Types, {Colors} from "../javascript.enum";
import NodeType from "../../../core/instances/NodeType";
import Output from "../../../core/instances/Output";
import Input from "../../../core/instances/Input";
import ExecutionInput from "../../../core/instances/ExecutionInput";
import ExecutionOutput from "../../../core/instances/ExecutionOutput";
+import {NodeTypes} from "../../../core/pscript.enum";
+import AllTypes from "../all-types";
export default class Add extends AbstractNode {
nodeType = NodeType.of(NodeTypes.FUNCTION);
@@ -24,9 +24,7 @@ export default class Add extends AbstractNode {
Input.of({
key: "a",
label: "A",
- accept: [
- PropertyType.of(Types.NUMBER)
- ],
+ accept: [AllTypes[Types.NUMBER]],
disabled: false,
visibleOnNode: true,
colorRGBA: Colors.NUMBER
@@ -34,9 +32,7 @@ export default class Add extends AbstractNode {
Input.of({
key: "b",
label: "B",
- accept: [
- PropertyType.of(Types.NUMBER)
- ],
+ accept: [AllTypes[Types.NUMBER]],
disabled: false,
visibleOnNode: true,
colorRGBA: Colors.NUMBER
@@ -47,7 +43,7 @@ export default class Add extends AbstractNode {
Output.of({
key: "sum",
label: "Sum",
- type: PropertyType.of(Types.NUMBER),
+ type: AllTypes[Types.NUMBER],
disabled: false,
colorRGBA: Colors.NUMBER
})
diff --git a/src/environment/javascript/basic-functions/Do.ts b/src/environment/javascript/basic-functions/Do.ts
index 6aa1ef7..1bcad68 100644
--- a/src/environment/javascript/basic-functions/Do.ts
+++ b/src/environment/javascript/basic-functions/Do.ts
@@ -1,7 +1,7 @@
import AbstractNode from "../../../core/instances/AbstractNode";
-import {NodeTypes} from "../javascript.enum";
import NodeType from "../../../core/instances/NodeType";
import ExecutionOutput from "../../../core/instances/ExecutionOutput";
+import {NodeTypes} from "../../../core/pscript.enum";
export default class Do extends AbstractNode {
nodeType = NodeType.of(NodeTypes.FUNCTION);
diff --git a/src/environment/javascript/basic-types/BooleanVal.ts b/src/environment/javascript/basic-types/BooleanVal.ts
index 9ef8039..9ee23e0 100644
--- a/src/environment/javascript/basic-types/BooleanVal.ts
+++ b/src/environment/javascript/basic-types/BooleanVal.ts
@@ -1,11 +1,10 @@
import AbstractNode from "../../../core/instances/AbstractNode";
-import Types, {Colors, NodeTypes} from "../javascript.enum";
-import PropertyType from "../../../core/instances/PropertyType";
+import Types, {Colors} from "../javascript.enum";
import NodeType from "../../../core/instances/NodeType";
import Output from "../../../core/instances/Output";
import Input from "../../../core/instances/Input";
-import ExecutionOutput from "../../../core/instances/ExecutionOutput";
-import ExecutionInput from "../../../core/instances/ExecutionInput";
+import {NodeTypes} from "../../../core/pscript.enum";
+import AllTypes from "../all-types";
export default class BooleanVal extends AbstractNode {
@@ -20,7 +19,6 @@ export default class BooleanVal extends AbstractNode {
instance.from({
...props,
inputs: [
- ExecutionInput.of("run", "Continue"),
Input.of({
key: "truthy",
label: "Truthy",
@@ -30,11 +28,10 @@ export default class BooleanVal extends AbstractNode {
})
],
outputs: [
- ExecutionOutput.of("run", "Continue"),
Output.of({
key: "truthy",
label: "isTruthy",
- type: PropertyType.of(Types.BOOLEAN),
+ type: AllTypes[Types.BOOLEAN],
disabled: false,
colorRGBA: Colors.BOOLEAN
})
diff --git a/src/environment/javascript/basic-types/NumberVal.ts b/src/environment/javascript/basic-types/NumberVal.ts
index 583c668..e96c3de 100644
--- a/src/environment/javascript/basic-types/NumberVal.ts
+++ b/src/environment/javascript/basic-types/NumberVal.ts
@@ -1,11 +1,10 @@
import AbstractNode from "../../../core/instances/AbstractNode";
-import Types, {Colors, NodeTypes} from "../javascript.enum";
-import PropertyType from "../../../core/instances/PropertyType";
+import Types, {Colors,} from "../javascript.enum";
import NodeType from "../../../core/instances/NodeType";
import Output from "../../../core/instances/Output";
import Input from "../../../core/instances/Input";
-import ExecutionInput from "../../../core/instances/ExecutionInput";
-import ExecutionOutput from "../../../core/instances/ExecutionOutput";
+import {NodeTypes} from "../../../core/pscript.enum";
+import AllTypes from "../all-types";
export default class NumberVal extends AbstractNode {
nodeType = NodeType.of(NodeTypes.VAR);
@@ -19,7 +18,6 @@ export default class NumberVal extends AbstractNode {
instance.from({
...props,
inputs: [
- ExecutionInput.of("run", "Continue"),
Input.of({
key: "value",
label: "Value",
@@ -29,11 +27,10 @@ export default class NumberVal extends AbstractNode {
})
],
outputs: [
- ExecutionOutput.of("run", "Continue"),
Output.of({
key: "value",
label: "Value",
- type: PropertyType.of(Types.NUMBER),
+ type: AllTypes[Types.NUMBER],
disabled: false,
colorRGBA: Colors.NUMBER
})
diff --git a/src/environment/javascript/javascript-nodes.ts b/src/environment/javascript/javascript-nodes.ts
index 3af3ca2..e8d9a0a 100644
--- a/src/environment/javascript/javascript-nodes.ts
+++ b/src/environment/javascript/javascript-nodes.ts
@@ -1,4 +1,4 @@
-import Comment from "../../core/instances/Comment";
+import CommentDraggable from "../../core/instances/CommentDraggable";
import Add from "./basic-functions/Add";
import BooleanVal from "./basic-types/BooleanVal";
import NumberVal from "./basic-types/NumberVal";
@@ -20,7 +20,7 @@ export default [
{
label: "Comment",
class: "CommentDraggable",
- getInstance: (x, y, canvas) => Comment.of({
+ getInstance: (x, y, canvas) => CommentDraggable.of({
canvas,
x,
y,
diff --git a/src/environment/javascript/javascript.enum.ts b/src/environment/javascript/javascript.enum.ts
index ea91ebb..f778dd4 100644
--- a/src/environment/javascript/javascript.enum.ts
+++ b/src/environment/javascript/javascript.enum.ts
@@ -3,16 +3,10 @@ enum Types {
BOOLEAN = "boolean"
}
-enum NodeTypes {
- FUNCTION = "func",
- CONST = "const",
- VAR = "var",
- STRUCT = "struct"
-}
export default Types
-const Colors: { [key: string]: [number, number, number, number] } = Object.freeze({
+const Colors: { [key: string]: ColorRGBA } = Object.freeze({
NUMBER: [59, 171, 28, 1],
BOOLEAN: [90, 34, 139, 1],
FUNCTION: [240, 153, 60, 1],
@@ -20,6 +14,6 @@ const Colors: { [key: string]: [number, number, number, number] } = Object.freez
START: [255, 0, 0, 1]
})
-export {Colors, NodeTypes}
+export {Colors}
diff --git a/test/serialize-node.test.ts b/test/serialize-state.test.ts
similarity index 72%
rename from test/serialize-node.test.ts
rename to test/serialize-state.test.ts
index 66ae40f..342eeea 100644
--- a/test/serialize-node.test.ts
+++ b/test/serialize-state.test.ts
@@ -2,13 +2,14 @@ import {expect, test} from '@jest/globals';
import BooleanVal from "../src/environment/javascript/basic-types/BooleanVal";
import {Colors} from "../src/environment/javascript/javascript.enum";
import Serializer from "../src/core/libs/Serializer";
-import PScriptRendererState from "../src/core/libs/PScriptRendererState";
+import CanvasStateStore from "../src/core/libs/CanvasStateStore";
+import CanvasStateUtil from "../src/core/util/CanvasStateUtil";
test('Serialized node is valid', () => {
Serializer.addTypes(BooleanVal)
- const canvas = PScriptRendererState.createState("TEST")
+ const canvas = CanvasStateStore.createState("TEST")
const newNode = BooleanVal.of({canvas, x: 0, y: 0, label: "Boolean", colorRGBA: Colors.BOOLEAN})
- canvas.addDraggable(newNode)
+ CanvasStateUtil.addDraggable(canvas.getId(), newNode)
const serializedState = Serializer.serialize(canvas.getState())
const deserializedState = Serializer.deserialize(canvas, serializedState)