-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJSHelperFuncs.js
108 lines (93 loc) · 2.53 KB
/
JSHelperFuncs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Helper functions used in JS. These are automatically added to the top of all script files. Put stuff here you want all scripts to have.
function exists(comp)
{
for(let i = 0; i < accessedComponents.length; ++i) {
if (accessedComponents[i].ID == comp.ID && accessedComponents[i].ComponentType == comp.ComponentType) {
return true;
}
}
return false;
}
function addComponent(name)
{
return me.addComponent(name);
}
function getComponent(name)
{
return me.getComponent(name);
}
function playSound()
{
return me.playSound();
}
function destringify(obj)
{
return Function('"use strict"; return (' + obj + ')')();
}
function deleteUnusedVariables(args)
{
for (let i = accessedComponents.length - 1; 0 < i; --i)
{
let removeComp = true;
for (argIndex in args)
{
let variable = destringify(args[argIndex]);
if (variable === undefined)
continue;
if (variable.ComponentType === accessedComponents[i].ComponentType && variable.ID === accessedComponents[i].ID)
{
removeComp = false;
break;
}
}
if (removeComp)
{
accessedComponents.splice(i, 1);
}
}
}
function updateLoop(instructions)
{
if (!Array.isArray(instructions))
{
console.log("instructions isn't an array!");
return;
}
// const compsBefore = accessedComponents.splice();
for (i = 0; i < instructions.length; ++i)
{
if (typeof instructions[i] === "undefined")
continue;
if (typeof instructions[i].func === "function")
{
if (typeof instructions[i].params !== "undefined")
instructions[i].func(instructions[i].params);
else
instructions[i].func();
}
else if (typeof instructions[i].func === "string")
{
let func = destringify(instructions[i].func);
if (typeof instructions[i].params !== "undefined")
func(instructions[i].params);
else
func();
}
}
// let returnVals = [];
//
// for (i in accessedComponents)
// {
// let changed = true;
// for (j in compsBefore)
// {
// if (compsBefore[j] == accessedComponents[i])
// changed = false;
// }
//
// if (changed)
// returnVals.push(accessedComponents[i]);
// }
//
// return returnVals;
}