MCPcopy Index your code
hub / github.com/MrNothing/AI-Blocks / loadParams

Method loadParams

Sources/src/Model/Objects/Script.js:35–111  ·  view source on GitHub ↗
(filepath)

Source from the content-addressed store, hash-verified

33 }
34
35 loadParams(filepath)
36 {
37 let context = this;
38
39 let data = fs.readFileSync(filepath);
40
41 let array = data.toString().split("\n");
42
43 let next_is_param = false;
44 let type = 'string';
45 let condition = "";
46
47 for(let i in array) {
48
49 let line = array[i];
50
51 if(line.indexOf("#description")==0)
52 {
53 this.description += line.substring(13, line.length)+"\n";
54 }
55
56 if(line.indexOf("#icon")==0)
57 {
58 this.icon = line.substring(6, line.length).trim();
59 }
60
61 if(line.indexOf("#zone")==0)
62 condition = line.replace("#zone", "").trim()
63
64 if(line.indexOf("#endzone")==0)
65 condition = "";
66
67 if(next_is_param==true)
68 {
69 let param = line.split('=')[0].replace(/\s/g, '');
70 let value = line.split('=')[1].replace('"', '').replace('"', '').replace("\n", "");
71 if(type.indexOf("array|")==0)
72 {
73
74 try
75 {
76 let vals = JSON.parse(line.split('=')[1])
77 value = ""
78 for(let v in vals)
79 {
80 if(v!=vals.length-1)
81 value+=vals[v]+";";
82 else
83 value+=vals[v];
84 }
85 }
86 catch(e)
87 {
88 window.service.log("Could not parse array! "+this.source+" at line: "+i, e.message, 1);
89 }
90
91 }
92

Callers 1

compileAllScriptsMethod · 0.95

Calls 1

logMethod · 0.80

Tested by

no test coverage detected