Skip to content

Commit b99e047

Browse files
committed
Script Updates Sept 6
ZeroFrame Version Fix MTB - dependencies updated APIL - recursive parser bug fix
1 parent 088c651 commit b99e047

File tree

9 files changed

+2402
-32
lines changed

9 files changed

+2402
-32
lines changed

APILogic/2.0.9/APILogic.js

+778
Large diffs are not rendered by default.

APILogic/APILogic.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
Name : APILogic
44
GitHub : https://github.com/TimRohr22/Cauldron/tree/master/APILogic
55
Roll20 Contact : timmaugh
6-
Version : 2.0.8
7-
Last Update : 26 Jan 2023
6+
Version : 2.0.9
7+
Last Update : 5 SEP 2024
88
=========================================================
99
*/
1010
var API_Meta = API_Meta || {};
@@ -18,9 +18,9 @@ const APILogic = (() => {
1818
// VERSION
1919
// ==================================================
2020
const apiproject = 'APILogic';
21-
API_Meta[apiproject].version = '2.0.8';
21+
API_Meta[apiproject].version = '2.0.9';
2222
const schemaVersion = 0.1;
23-
const vd = new Date(1674771283027);
23+
const vd = new Date(1725559091022);
2424
const versionInfo = () => {
2525
log(`\u0166\u0166 ${apiproject} v${API_Meta[apiproject].version}, ${vd.getFullYear()}/${vd.getMonth() + 1}/${vd.getDate()} \u0166\u0166 -- offset ${API_Meta[apiproject].offset}`);
2626
if (!state.hasOwnProperty(apiproject) || state[apiproject].version !== schemaVersion) {
@@ -76,14 +76,14 @@ const APILogic = (() => {
7676
elserx = /(\()?{&\s*else\s*(?=})/i,
7777
endrx = /(\()?{&\s*end\s*}((?<=\({&\s*end\s*})\)|\1)/i;
7878
// FORMERLY in IFTREEPARSER =============================
79-
const groupopenrx = /^\s*(?<negation>!?)\s*\(\s*/,
79+
const groupopenrx = /^\s*(?<negation>!?)\s*\((?!{&\d+}\))\s*/,
8080
namerx = /^\[(?<groupname>[^\s]+?)]\s*/i,
8181
comprx = /^(?<operator>(?:>=|<=|~|!~|=|!=|<|>))\s*/,
8282
operatorrx = /^(?<operator>(?:&&|\|\|))\s*/,
8383
groupendrx = /^\)\s*/,
8484
ifendrx = /^\s*}/,
8585
ifendparenrx = /^\s*}\)/,
86-
textrx = /^(?<negation>!?)\s*(`|'|"?)(?<argtext>.+?)\2\s*(?=!=|!~|>=|<=|[=~><]|&&|\|\||\)|})/;
86+
textrx = /^(?<negation>!?)\s*(`|'|"?)(?<argtext>\({&\d+}\)|.+?)\2\s*(?=!=|!~|>=|<=|[=~><]|&&|\|\||\)|})/;
8787
// TOKEN MARKERS ========================================
8888
const iftm = { rx: ifrx, type: 'if' },
8989
elseiftm = { rx: elseifrx, type: 'elseif' },
@@ -583,7 +583,9 @@ const APILogic = (() => {
583583
item.metavalue = true;
584584
switch (item.type) {
585585
case 'text':
586-
item.groups.argtext = item.groups.argtext.replace(/\$\[\[(\d+)]]/g, ((r, g1) => o.parsedinline[g1].value || 0));
586+
item.groups.argtext = item.groups.argtext
587+
.replace(/\$\[\[(\d+)]]/g, ((r, g1) => o.parsedinline[g1].value || 0))
588+
.replace(/\({&(\d+)}\)/, ((r, g1) => o.parsedinline[g1].value || 0));
587589
if (grouplib.hasOwnProperty(item.groups.argtext)) {
588590
if (grouplib[item.groups.argtext]) item.value = true;
589591
else {
@@ -619,6 +621,8 @@ const APILogic = (() => {
619621
let logcolor = 'lightseagreen';
620622
let groupname = '';
621623
let negate = false;
624+
let res;
625+
c.memo = c.hasOwnProperty("memo") ? c.memo : { value: false, next: '||' };
622626
nestlog(`CONDITIONS TEST BEGINS`, c.indent, logcolor, msgstate.logging);
623627
let o = c.tokens.reduce((m, v, i) => {
624628
if ((!m.value && m.next === '&&') || (m.value && m.next === '||')) {
@@ -628,22 +632,24 @@ const APILogic = (() => {
628632
nestlog(`==AND-GROUP DETECTED: ${v.name || 'no name'}`, c.indent, logcolor, msgstate.logging);
629633
groupname = v.name;
630634
negate = v.negate;
631-
v = areConditionsTruthy({ tokens: v.contents, indent: c.indent + 1 });
635+
res = areConditionsTruthy({ tokens: v.contents, indent: c.indent + 1, memo: { ...m } });
636+
v.value = res.value;
632637
if (groupname) {
633638
grouplib[groupname] = v.value;
634639
}
635640
if (negate) v.value = !v.value;
636641
} else {
637642
nestlog(`==AND-CONDITION DETECTED: lhs>${v.contents[0]} type>${v.type} rhs>${v.contents[1] || ''}`, c.indent, logcolor, msgstate.logging);
638-
v = resolveCondition(v);
643+
ret = resolveCondition(v);
644+
v.value = ret.value;
639645
}
640646
nestlog(`==VALUE: ${v.value}`, c.indent, logcolor, msgstate.logging);
641647
m.value = m.next === '&&' ? m.value && v.value : m.value || v.value;
642648
}
643-
nestlog(`==LOOP END MEMO VALUE: ${m.value}, ${m.next}`, c.indent, logcolor, msgstate.logging);
644649
m.next = v.next;
650+
nestlog(`==LOOP END MEMO VALUE: ${m.value}, ${m.next}`, c.indent, logcolor, msgstate.logging);
645651
return m;
646-
}, { value: false, next: '||' });
652+
}, c.memo);
647653

648654
nestlog(`CONDITIONS TEST ENDS: Conditions are ${o.value}, ${o.next}`, c.indent, logcolor, msgstate.logging);
649655
return o;

APILogic/script.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "APILogic",
33
"script": "APILogic.js",
4-
"version": "2.0.8",
4+
"version": "2.0.9",
55
"description": "APILogic is a meta-script and part of the Meta-Toolbox. APILogic provides chat input logical constructs for shaping the command line, including IF, ELSEIF, and ELSE. It provides a way to define terms for text-replacment operations, or to name condition sets to re-use later in the logical processing. \r\rFor more information, see the original API forum thread:\r\r[APILogic Forum Thread](https://app.roll20.net/forum/post/9771314/script-apilogic-gives-if-slash-elseif-slash-else-processing-to-other-scripts/)\r\rOr read about the full set of meta-scripts available: \r\r[Meta Toolbox Forum Thread](https://app.roll20.net/forum/post/10005695/script-set-the-meta-toolbox)",
66
"authors": "timmaugh",
77
"roll20userid": "5962076",
@@ -29,6 +29,7 @@
2929
"2.0.4",
3030
"2.0.5",
3131
"2.0.6",
32-
"2.0.7"
32+
"2.0.7",
33+
"2.0.8"
3334
]
3435
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
/*
2+
=========================================================
3+
Name : MetaScriptToolbox
4+
GitHub :
5+
Roll20 Contact : timmaugh
6+
Version : 0.0.2
7+
Last Update : 6 SEP 2024
8+
=========================================================
9+
*/
10+
var API_Meta = API_Meta || {};
11+
API_Meta.MetaScriptToolbox = { offset: Number.MAX_SAFE_INTEGER, lineCount: -1 };
12+
{ try { throw new Error(''); } catch (e) { API_Meta.MetaScriptToolbox.offset = (parseInt(e.stack.split(/\n/)[1].replace(/^.*:(\d+):.*$/, '$1'), 10) - (12)); } }
13+
14+
const MetaScriptToolbox = (() => { // eslint-disable-line no-unused-vars
15+
const apiproject = 'MetaScriptToolbox';
16+
const version = '0.0.2';
17+
const schemaVersion = 0.1;
18+
API_Meta[apiproject].version = version;
19+
const vd = new Date(1725630209434);
20+
const versionInfo = () => {
21+
log(`\u0166\u0166 ${apiproject} v${API_Meta[apiproject].version}, ${vd.getFullYear()}/${vd.getMonth() + 1}/${vd.getDate()} \u0166\u0166 -- offset ${API_Meta[apiproject].offset}`);
22+
};
23+
const logsig = () => {
24+
// initialize shared namespace for all signed projects, if needed
25+
state.torii = state.torii || {};
26+
// initialize siglogged check, if needed
27+
state.torii.siglogged = state.torii.siglogged || false;
28+
state.torii.sigtime = state.torii.sigtime || Date.now() - 3001;
29+
if (!state.torii.siglogged || Date.now() - state.torii.sigtime > 3000) {
30+
const logsig = '\n' +
31+
' _____________________________________________ ' + '\n' +
32+
' )_________________________________________( ' + '\n' +
33+
' )_____________________________________( ' + '\n' +
34+
' ___| |_______________| |___ ' + '\n' +
35+
' |___ _______________ ___| ' + '\n' +
36+
' | | | | ' + '\n' +
37+
' | | | | ' + '\n' +
38+
' | | | | ' + '\n' +
39+
' | | | | ' + '\n' +
40+
' | | | | ' + '\n' +
41+
'______________|_|_______________|_|_______________' + '\n' +
42+
' ' + '\n';
43+
log(`${logsig}`);
44+
state.torii.siglogged = true;
45+
state.torii.sigtime = Date.now();
46+
}
47+
return;
48+
};
49+
const checkInstall = () => {
50+
if (!state.hasOwnProperty(apiproject) || state[apiproject].version !== schemaVersion) {
51+
log(` > Updating ${apiproject} Schema to v${schemaVersion} <`);
52+
switch (state[apiproject] && state[apiproject].version) {
53+
54+
case 0.1:
55+
/* falls through */
56+
57+
case 'UpdateSchemaVersion':
58+
state[apiproject].version = schemaVersion;
59+
break;
60+
61+
default:
62+
state[apiproject] = {
63+
settings: {},
64+
defaults: {},
65+
version: schemaVersion
66+
}
67+
break;
68+
}
69+
}
70+
};
71+
let stateReady = false;
72+
const assureState = () => {
73+
if (!stateReady) {
74+
checkInstall();
75+
stateReady = true;
76+
}
77+
};
78+
79+
const checkDependencies = (deps) => {
80+
/* pass array of objects like
81+
{ name: 'ModName', version: '#.#.#' || '', mod: ModName || undefined, checks: [ [ExposedItem, type], [ExposedItem, type] ] }
82+
*/
83+
const dependencyEngine = (deps) => {
84+
const versionCheck = (mv, rv) => {
85+
let modv = [...mv.split('.'), ...Array(4).fill(0)].slice(0, 4);
86+
let reqv = [...rv.split('.'), ...Array(4).fill(0)].slice(0, 4);
87+
return reqv.reduce((m, v, i) => {
88+
if (m.pass || m.fail) return m;
89+
if (i < 3) {
90+
if (parseInt(modv[i]) > parseInt(reqv[i])) m.pass = true;
91+
else if (parseInt(modv[i]) < parseInt(reqv[i])) m.fail = true;
92+
} else {
93+
// all betas are considered below the release they are attached to
94+
if (reqv[i] === 0 && modv[i] === 0) m.pass = true;
95+
else if (modv[i] === 0) m.pass = true;
96+
else if (reqv[i] === 0) m.fail = true;
97+
else if (parseInt(modv[i].slice(1)) >= parseInt(reqv[i].slice(1))) m.pass = true;
98+
}
99+
return m;
100+
}, { pass: false, fail: false }).pass;
101+
};
102+
103+
let result = { passed: true, failures: {}, optfailures: {} };
104+
deps.forEach(d => {
105+
let failObj = d.optional ? result.optfailures : result.failures;
106+
if (!d.mod) {
107+
if (!d.optional) result.passed = false;
108+
failObj[d.name] = 'Not found';
109+
return;
110+
}
111+
if (d.version && d.version.length) {
112+
if (!(API_Meta[d.name].version && API_Meta[d.name].version.length && versionCheck(API_Meta[d.name].version, d.version))) {
113+
if (!d.optional) result.passed = false;
114+
failObj[d.name] = `Incorrect version. Required v${d.version}. ${API_Meta[d.name].version && API_Meta[d.name].version.length ? `Found v${API_Meta[d.name].version}` : 'Unable to tell version of current.'}`;
115+
return;
116+
}
117+
}
118+
d.checks.reduce((m, c) => {
119+
if (!m.passed) return m;
120+
let [pname, ptype] = c;
121+
if (!d.mod.hasOwnProperty(pname) || typeof d.mod[pname] !== ptype) {
122+
if (!d.optional) m.passed = false;
123+
failObj[d.name] = `Incorrect version.`;
124+
}
125+
return m;
126+
}, result);
127+
});
128+
return result;
129+
};
130+
let depCheck = dependencyEngine(deps);
131+
let failures = '', contents = '', msg = '';
132+
if (Object.keys(depCheck.optfailures).length) { // optional components were missing
133+
failures = Object.keys(depCheck.optfailures).map(k => `&bull; <code>${k}</code> : ${depCheck.optfailures[k]}`).join('<br>');
134+
contents = `<span style="font-weight: bold">${apiproject}</span> utilizies one or more other scripts for optional features, and works best with those scripts installed. You can typically find these optional scripts in the 1-click Mod Library:<br>${failures}`;
135+
msg = `<div style="width: 100%;border: none;border-radius: 0px;min-height: 60px;display: block;text-align: left;white-space: pre-wrap;overflow: hidden"><div style="font-size: 14px;font-family: &quot;Segoe UI&quot;, Roboto, Ubuntu, Cantarell, &quot;Helvetica Neue&quot;, sans-serif"><div style="background-color: #000000;border-radius: 6px 6px 0px 0px;position: relative;border-width: 2px 2px 0px 2px;border-style: solid;border-color: black;"><div style="border-radius: 18px;width: 35px;height: 35px;position: absolute;left: 3px;top: 2px;"><img style="background-color: transparent ; float: left ; border: none ; max-height: 40px" src="${typeof apilogo !== 'undefined' ? apilogo : 'https://i.imgur.com/kxkuQFy.png'}"></div><div style="background-color: #c94d4d;font-weight: bold;font-size: 18px;line-height: 36px;border-radius: 6px 6px 0px 0px;padding: 4px 4px 0px 43px;color: #ffffff;min-height: 38px;">MISSING MOD DETECTED</div></div><div style="background-color: white;padding: 4px 8px;border: 2px solid #000000;border-bottom-style: none;color: #404040;">${contents}</div><div style="background-color: white;text-align: right;padding: 4px 8px;border: 2px solid #000000;border-top-style: none;border-radius: 0px 0px 6px 6px"></div></div></div>`;
136+
sendChat(apiproject, `/w gm ${msg}`);
137+
}
138+
if (!depCheck.passed) {
139+
failures = Object.keys(depCheck.failures).map(k => `&bull; <code>${k}</code> : ${depCheck.failures[k]}`).join('<br>');
140+
contents = `<span style="font-weight: bold">${apiproject}</span> requires other scripts to work. Please use the 1-click Mod Library to correct the listed problems:<br>${failures}`;
141+
msg = `<div style="width: 100%;border: none;border-radius: 0px;min-height: 60px;display: block;text-align: left;white-space: pre-wrap;overflow: hidden"><div style="font-size: 14px;font-family: &quot;Segoe UI&quot;, Roboto, Ubuntu, Cantarell, &quot;Helvetica Neue&quot;, sans-serif"><div style="background-color: #000000;border-radius: 6px 6px 0px 0px;position: relative;border-width: 2px 2px 0px 2px;border-style: solid;border-color: black;"><div style="border-radius: 18px;width: 35px;height: 35px;position: absolute;left: 3px;top: 2px;"><img style="background-color: transparent ; float: left ; border: none ; max-height: 40px" src="${typeof apilogo !== 'undefined' ? apilogo : 'https://i.imgur.com/kxkuQFy.png'}"></div><div style="background-color: #c94d4d;font-weight: bold;font-size: 18px;line-height: 36px;border-radius: 6px 6px 0px 0px;padding: 4px 4px 0px 43px;color: #ffffff;min-height: 38px;">MISSING MOD DETECTED</div></div><div style="background-color: white;padding: 4px 8px;border: 2px solid #000000;border-bottom-style: none;color: #404040;">${contents}</div><div style="background-color: white;text-align: right;padding: 4px 8px;border: 2px solid #000000;border-top-style: none;border-radius: 0px 0px 6px 6px"></div></div></div>`;
142+
sendChat(apiproject, `/w gm ${msg}`);
143+
return false;
144+
}
145+
return true;
146+
};
147+
148+
on('ready', () => {
149+
versionInfo();
150+
assureState();
151+
logsig();
152+
let reqs = [
153+
{
154+
name: 'ZeroFrame',
155+
version: `1.2.2`,
156+
mod: typeof ZeroFrame !== 'undefined' ? ZeroFrame : undefined,
157+
checks: [['RegisterMetaOp', 'function']],
158+
},
159+
{
160+
name: 'APILogic',
161+
version: `2.0.9`,
162+
mod: typeof APILogic !== 'undefined' ? APILogic : undefined,
163+
checks: [],
164+
},
165+
{
166+
name: 'Fetch',
167+
version: `2.1.1`,
168+
mod: typeof Fetch !== 'undefined' ? Fetch : undefined,
169+
checks: [],
170+
},
171+
{
172+
name: 'SelectManager',
173+
version: `1.1.8`,
174+
mod: typeof SelectManager !== 'undefined' ? SelectManager : undefined,
175+
checks: [['GetPlayerID', 'function'], ['GetSelected', 'function'], ['GetWho', 'function']],
176+
},
177+
{
178+
name: 'Muler',
179+
version: `2.0.2`,
180+
mod: typeof Muler !== 'undefined' ? Muler : undefined,
181+
checks: [],
182+
},
183+
{
184+
name: 'Plugger',
185+
version: `1.0.9`,
186+
mod: typeof Plugger !== 'undefined' ? Plugger : undefined,
187+
checks: [],
188+
},
189+
{
190+
name: 'MathOps',
191+
version: `1.0.8`,
192+
mod: typeof MathOps !== 'undefined' ? MathOps : undefined,
193+
checks: [['MathProcessor', 'function']],
194+
},
195+
{
196+
name: 'libTokenMarkers',
197+
version: `0.1.2`,
198+
mod: typeof libTokenMarkers !== 'undefined' ? libTokenMarkers : undefined,
199+
checks: [['getStatus', 'function'], ['getStatuses', 'function'], ['getOrderedList', 'function']]
200+
},
201+
{
202+
name: 'libTable',
203+
version: `1.0.0`,
204+
mod: typeof libTable !== 'undefined' ? libTable : undefined,
205+
checks: [
206+
['getTable', 'function'],
207+
['getTables', 'function'],
208+
['getItems', 'function'],
209+
['getItemsByIndex', 'function'],
210+
['getItemsByName', 'function'],
211+
['getItemsByWeight', 'function'],
212+
['getItemsByWeightedIndex', 'function']
213+
]
214+
},
215+
{
216+
name: 'checkLightLevel',
217+
// version: `1.0.0.b3`,
218+
mod: typeof checkLightLevel !== 'undefined' ? checkLightLevel : undefined,
219+
checks: [['isLitBy', 'function']],
220+
optional: true
221+
},
222+
{
223+
name: 'Messenger',
224+
version: `1.0.1`,
225+
mod: typeof Messenger !== 'undefined' ? Messenger : undefined,
226+
checks: [['Button', 'function'], ['MsgBox', 'function'], ['HE', 'function'], ['Html', 'function'], ['Css', 'function']]
227+
}
228+
];
229+
if (!checkDependencies(reqs)) return;
230+
});
231+
return {};
232+
})();
233+
234+
{ try { throw new Error(''); } catch (e) { API_Meta.MetaScriptToolbox.lineCount = (parseInt(e.stack.split(/\n/)[1].replace(/^.*:(\d+):.*$/, '$1'), 10) - API_Meta.MetaScriptToolbox.offset); } }

0 commit comments

Comments
 (0)