|
529 | 529 | GraphInput.title = "Input"; |
530 | 530 | GraphInput.desc = "Input of the graph"; |
531 | 531 |
|
532 | | - GraphInput.prototype.onConfigure = function() |
| 532 | + GraphInput.prototype.onConfigure = function() |
| 533 | + |
533 | 534 | { |
534 | 535 | this.updateType(); |
535 | 536 | } |
|
983 | 984 |
|
984 | 985 | LiteGraph.registerNodeType("basic/file", ConstantFile); |
985 | 986 |
|
| 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 | + |
986 | 1029 | //to store json objects |
987 | 1030 | function ConstantData() { |
988 | 1031 | this.addOutput("data", "object"); |
|
0 commit comments