(function(global) { var LiteGraph = global.LiteGraph; function Selector() { this.addInput("sel", "number"); this.addInput("A"); this.addInput("B"); this.addInput("C"); this.addInput("D"); this.addOutput("out"); this.selected = 0; } Selector.title = "Selector"; Selector.desc = "selects an output"; Selector.prototype.onDrawBackground = function(ctx) { if (this.flags.collapsed) { return; } ctx.fillStyle = "#AFB"; var y = (this.selected + 1) * LiteGraph.NODE_SLOT_HEIGHT + 6; ctx.beginPath(); ctx.moveTo(50, y); ctx.lineTo(50, y + LiteGraph.NODE_SLOT_HEIGHT); ctx.lineTo(34, y + LiteGraph.NODE_SLOT_HEIGHT * 0.5); ctx.fill(); }; Selector.prototype.onExecute = function() { var sel = this.getInputData(0); if (sel == null || sel.constructor !== Number) sel = 0; this.selected = sel = Math.round(sel) % (this.inputs.length - 1); var v = this.getInputData(sel + 1); if (v !== undefined) { this.setOutputData(0, v); } }; Selector.prototype.onGetInputs = function() { return [["E", 0], ["F", 0], ["G", 0], ["H", 0]]; }; LiteGraph.registerNodeType("logic/selector", Selector); function Sequence() { this.properties = { sequence: "A,B,C" }; this.addInput("index", "number"); this.addInput("seq"); this.addOutput("out"); this.index = 0; this.values = this.properties.sequence.split(","); } Sequence.title = "Sequence"; Sequence.desc = "select one element from a sequence from a string"; Sequence.prototype.onPropertyChanged = function(name, value) { if (name == "sequence") { this.values = value.split(","); } }; Sequence.prototype.onExecute = function() { var seq = this.getInputData(1); if (seq && seq != this.current_sequence) { this.values = seq.split(","); this.current_sequence = seq; } var index = this.getInputData(0); if (index == null) { index = 0; } this.index = index = Math.round(index) % this.values.length; this.setOutputData(0, this.values[index]); }; LiteGraph.registerNodeType("logic/sequence", Sequence); })(this);