Skip to content

Commit 015547d

Browse files
authored
Update base.js
1 parent 3acdcee commit 015547d

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

src/nodes/base.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,8 @@
529529
GraphInput.title = "Input";
530530
GraphInput.desc = "Input of the graph";
531531

532-
GraphInput.prototype.onConfigure = function()
532+
GraphInput.prototype.onConfigure = function()
533+
533534
{
534535
this.updateType();
535536
}
@@ -983,6 +984,48 @@
983984

984985
LiteGraph.registerNodeType("basic/file", ConstantFile);
985986

987+
988+
//to store json objects
989+
function JSONParse() {
990+
this.addInput("parse", LiteGraph.ACTION);
991+
this.addInput("json", "string");
992+
this.addOutput("done", LiteGraph.EVENT);
993+
this.addOutput("object", "object");
994+
this.widget = this.addWidget("button","parse","",this.parse.bind(this));
995+
this._str = null;
996+
this._obj = null;
997+
}
998+
999+
JSONParse.title = "JSON Parse";
1000+
JSONParse.desc = "Parses JSON String into object";
1001+
1002+
JSONParse.prototype.parse = function()
1003+
{
1004+
if(!this._str)
1005+
return;
1006+
1007+
try {
1008+
this._str = this.getInputData(1);
1009+
this._obj = JSON.parse(this._str);
1010+
this.boxcolor = "#AEA";
1011+
this.triggerSlot(0);
1012+
} catch (err) {
1013+
this.boxcolor = "red";
1014+
}
1015+
}
1016+
1017+
JSONParse.prototype.onExecute = function() {
1018+
this._str = this.getInputData(1);
1019+
this.setOutputData(1, this._obj);
1020+
};
1021+
1022+
JSONParse.prototype.onAction = function(name) {
1023+
if(name == "parse")
1024+
this.parse();
1025+
}
1026+
1027+
LiteGraph.registerNodeType("basic/jsonparse", JSONParse);
1028+
9861029
//to store json objects
9871030
function ConstantData() {
9881031
this.addOutput("data", "object");

0 commit comments

Comments
 (0)