-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadaptationLib.js
More file actions
109 lines (109 loc) · 3 KB
/
adaptationLib.js
File metadata and controls
109 lines (109 loc) · 3 KB
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
109
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: green; icon-glyph: magic;
//adaptive variables with recalc support
const VERSION = "1.1.0";
class adaptiveVariable {
#name;#equation;#value;#getName;
constructor(name, equation) {
this.#name = name;
this.#equation = equation;
this.#value=eval(equation);
}
access(){
return eval(this.#equation);
}
lightAccess(){
return this.#value;
}
recalc(){
this.#value=eval(this.#equation);
}
changeEquation(newEquation){
this.#equation = newEquation;
this.recalc();
}
jankyNewEquation(newEquation){
this.#equation = newEquation;
}
}
class adaptiveVariableManager {
#variables;
constructor(){
this.#variables = {};
}
createVariable(name, equation){
if(this.#variables[name]){
log(`Variable with name ${name} already exists. Overwriting...`);
this.#variables[name].changeEquation(equation);
return;
}
this.#variables[name] = new adaptiveVariable(name, equation);
}
cVar(name, equation){
this.createVariable(name, equation);
}
getVariable(name){
if(!this.#variables[name]){
log(`Variable with name ${name} does not exist.`);
return null;
}
else{
return this.#variables[name].access();
}
}
gVar(name){
return this.getVariable(name);
}
getVariableLight(name){
if(!this.#variables[name]){
log(`Variable with name ${name} does not exist.`);
return null;
}
else{
return this.#variables[name].lightAccess();
}
}
gVarL(name){
return this.getVariableLight(name);
}
recalcVariable(name){
if(!this.#variables[name]){
log(`Variable with name ${name} does not exist.`);
return;
}
else{
this.#variables[name].recalc();
}
}
rVar(name){
this.recalcVariable(name);
}
changeVariableEquation(name, newEquation){
if(!this.#variables[name]){
log(`Variable with name ${name} does not exist.`);
return;
}
else{
this.#variables[name].changeEquation(newEquation);
}
}
cVEq(name, newEquation){
this.changeVariableEquation(name, newEquation);
}
jankyChangeVariableEquation(name, newEquation){
if(!this.#variables[name]){
log(`Variable with name ${name} does not exist.`);
return;
}
else{
this.#variables[name].jankyNewEquation(newEquation);
}
}
jankyCVEq(name, newEquation){
this.jankyChangeVariableEquation(name, newEquation);
}
}
module.exports = {
adaptiveVariable,adaptiveVariableManager,VERSION
}