From 015547db2ebf11843b8548a3e0a2a47fb4b76dc5 Mon Sep 17 00:00:00 2001 From: Javi Agenjo Date: Fri, 27 Oct 2023 10:28:34 +0200 Subject: [PATCH] Update base.js --- src/nodes/base.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/nodes/base.js b/src/nodes/base.js index 6b68db124..bc6c2cd1b 100755 --- a/src/nodes/base.js +++ b/src/nodes/base.js @@ -529,7 +529,8 @@ GraphInput.title = "Input"; GraphInput.desc = "Input of the graph"; - GraphInput.prototype.onConfigure = function() + GraphInput.prototype.onConfigure = function() + { this.updateType(); } @@ -983,6 +984,48 @@ LiteGraph.registerNodeType("basic/file", ConstantFile); + +//to store json objects +function JSONParse() { + this.addInput("parse", LiteGraph.ACTION); + this.addInput("json", "string"); + this.addOutput("done", LiteGraph.EVENT); + this.addOutput("object", "object"); + this.widget = this.addWidget("button","parse","",this.parse.bind(this)); + this._str = null; + this._obj = null; +} + +JSONParse.title = "JSON Parse"; +JSONParse.desc = "Parses JSON String into object"; + +JSONParse.prototype.parse = function() +{ + if(!this._str) + return; + + try { + this._str = this.getInputData(1); + this._obj = JSON.parse(this._str); + this.boxcolor = "#AEA"; + this.triggerSlot(0); + } catch (err) { + this.boxcolor = "red"; + } +} + +JSONParse.prototype.onExecute = function() { + this._str = this.getInputData(1); + this.setOutputData(1, this._obj); +}; + +JSONParse.prototype.onAction = function(name) { + if(name == "parse") + this.parse(); +} + +LiteGraph.registerNodeType("basic/jsonparse", JSONParse); + //to store json objects function ConstantData() { this.addOutput("data", "object");