Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metascript Updates Aug 2023 #1795

Merged
merged 11 commits into from
Aug 28, 2023
1,431 changes: 1,431 additions & 0 deletions Fetch/2.0.9/Fetch.js

Large diffs are not rendered by default.

188 changes: 133 additions & 55 deletions Fetch/Fetch.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Fetch/script.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Fetch",
"script": "Fetch.js",
"version": "2.0.8",
"version": "2.0.9",
"description": "Fetch is a meta-script and part of the Meta-Toolbox. Fetch offers a unified syntax to expand the amount of things that can be retrieved with simple token or sheet calls. You can retrieve any token property, character property, sheet attribute, repeating attribute, ability, or macro with syntax that is intentionally very similar to Roll20 Galactic Standard syntax structures. As of v2.0.0, you can also retrieve page properties, player properties, campaign properties, token marker properties, or statusmarker properties.\r\rToken property : @(selected.currentside)\rSheet Attribute: @(selected.Strength)\rSheet Attribute: @(Bob the Hirsute.Strength.max)\rRepeating Attr : *(Englebert Slaptiback.spells.[spell_name~Fireball prepared].spell_roll)\r\rIt also expands the source of the returned sheet item to include 'speaker'.\r\r@(speaker.Strength.max) ... and can return the rowID of a repeating attribute, the row number ($0), or the name of either brand of reference.\r\rNot only do these offer the advantage of not breaking the chat message if they don't exist (the way a standard token or sheet item call would), they also give you the ability to substitute in a default value should the one you are looking for not exist: \r\r@(The President of Burundi.Coffee[default value here]) \r\rFor more information, see the original API forum thread:\r\rhttps://app.roll20.net/forum/post/10005732/meta-script-fetch-retrieve-attributes-repeating-attributes-abilities-or-token-properties)\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)",
"authors": "timmaugh",
"roll20userid": "5962076",
Expand All @@ -15,7 +15,7 @@
"attribute.name": "read",
"attribute.type": "read"
},
"dependencies": [ "Messenger", "libTokenMarkers" ],
"dependencies": [ "Messenger", "libTokenMarkers", "checkLightLevel" ],
"conflicts": [],
"previousversions": [
"1.0.4",
Expand All @@ -33,7 +33,8 @@
"2.0.4",
"2.0.5",
"2.0.6",
"2.0.7"
"2.0.7",
"2.0.8"
]

}
234 changes: 234 additions & 0 deletions MetaScriptToolbox/0.0.1/MetaScriptToolbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
/*
=========================================================
Name : MetaScriptToolbox
GitHub :
Roll20 Contact : timmaugh
Version : 1.0.0
Last Update : 8/8/2023
=========================================================
*/
var API_Meta = API_Meta || {};
API_Meta.MetaScriptToolbox = { offset: Number.MAX_SAFE_INTEGER, lineCount: -1 };
{ try { throw new Error(''); } catch (e) { API_Meta.MetaScriptToolbox.offset = (parseInt(e.stack.split(/\n/)[1].replace(/^.*:(\d+):.*$/, '$1'), 10) - (12)); } }

const MetaScriptToolbox = (() => { // eslint-disable-line no-unused-vars
const apiproject = 'MetaScriptToolbox';
const version = '1.0.0';
const schemaVersion = 0.1;
API_Meta[apiproject].version = version;
const vd = new Date(1655476169424);
const versionInfo = () => {
log(`\u0166\u0166 ${apiproject} v${API_Meta[apiproject].version}, ${vd.getFullYear()}/${vd.getMonth() + 1}/${vd.getDate()} \u0166\u0166 -- offset ${API_Meta[apiproject].offset}`);
};
const logsig = () => {
// initialize shared namespace for all signed projects, if needed
state.torii = state.torii || {};
// initialize siglogged check, if needed
state.torii.siglogged = state.torii.siglogged || false;
state.torii.sigtime = state.torii.sigtime || Date.now() - 3001;
if (!state.torii.siglogged || Date.now() - state.torii.sigtime > 3000) {
const logsig = '\n' +
' _____________________________________________ ' + '\n' +
' )_________________________________________( ' + '\n' +
' )_____________________________________( ' + '\n' +
' ___| |_______________| |___ ' + '\n' +
' |___ _______________ ___| ' + '\n' +
' | | | | ' + '\n' +
' | | | | ' + '\n' +
' | | | | ' + '\n' +
' | | | | ' + '\n' +
' | | | | ' + '\n' +
'______________|_|_______________|_|_______________' + '\n' +
' ' + '\n';
log(`${logsig}`);
state.torii.siglogged = true;
state.torii.sigtime = Date.now();
}
return;
};
const checkInstall = () => {
if (!state.hasOwnProperty(apiproject) || state[apiproject].version !== schemaVersion) {
log(` > Updating ${apiproject} Schema to v${schemaVersion} <`);
switch (state[apiproject] && state[apiproject].version) {

case 0.1:
/* falls through */

case 'UpdateSchemaVersion':
state[apiproject].version = schemaVersion;
break;

default:
state[apiproject] = {
settings: {},
defaults: {},
version: schemaVersion
}
break;
}
}
};
let stateReady = false;
const assureState = () => {
if (!stateReady) {
checkInstall();
stateReady = true;
}
};

const checkDependencies = (deps) => {
/* pass array of objects like
{ name: 'ModName', version: '#.#.#' || '', mod: ModName || undefined, checks: [ [ExposedItem, type], [ExposedItem, type] ] }
*/
const dependencyEngine = (deps) => {
const versionCheck = (mv, rv) => {
let modv = [...mv.split('.'), ...Array(4).fill(0)].slice(0, 4);
let reqv = [...rv.split('.'), ...Array(4).fill(0)].slice(0, 4);
return reqv.reduce((m, v, i) => {
if (m.pass || m.fail) return m;
if (i < 3) {
if (parseInt(modv[i]) > parseInt(reqv[i])) m.pass = true;
else if (parseInt(modv[i]) < parseInt(reqv[i])) m.fail = true;
} else {
// all betas are considered below the release they are attached to
if (reqv[i] === 0 && modv[i] === 0) m.pass = true;
else if (modv[i] === 0) m.pass = true;
else if (reqv[i] === 0) m.fail = true;
else if (parseInt(modv[i].slice(1)) >= parseInt(reqv[i].slice(1))) m.pass = true;
}
return m;
}, { pass: false, fail: false }).pass;
};

let result = { passed: true, failures: {}, optfailures: {} };
deps.forEach(d => {
let failObj = d.optional ? result.optfailures : result.failures;
if (!d.mod) {
if (!d.optional) result.passed = false;
failObj[d.name] = 'Not found';
return;
}
if (d.version && d.version.length) {
if (!(API_Meta[d.name].version && API_Meta[d.name].version.length && versionCheck(API_Meta[d.name].version, d.version))) {
if (!d.optional) result.passed = false;
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.'}`;
return;
}
}
d.checks.reduce((m, c) => {
if (!m.passed) return m;
let [pname, ptype] = c;
if (!d.mod.hasOwnProperty(pname) || typeof d.mod[pname] !== ptype) {
if (!d.optional) m.passed = false;
failObj[d.name] = `Incorrect version.`;
}
return m;
}, result);
});
return result;
};
let depCheck = dependencyEngine(deps);
let failures = '', contents = '', msg = '';
if (Object.keys(depCheck.optfailures).length) { // optional components were missing
failures = Object.keys(depCheck.optfailures).map(k => `&bull; <code>${k}</code> : ${depCheck.optfailures[k]}`).join('<br>');
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}`;
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>`;
sendChat(apiproject, `/w gm ${msg}`);
}
if (!depCheck.passed) {
failures = Object.keys(depCheck.failures).map(k => `&bull; <code>${k}</code> : ${depCheck.failures[k]}`).join('<br>');
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}`;
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>`;
sendChat(apiproject, `/w gm ${msg}`);
return false;
}
return true;
};

on('ready', () => {
versionInfo();
assureState();
logsig();
let reqs = [
{
name: 'ZeroFrame',
version: `1.1.6`,
mod: typeof ZeroFrame !== 'undefined' ? ZeroFrame : undefined,
checks: [['RegisterMetaOp', 'function']],
},
{
name: 'APILogic',
version: `2.0.8`,
mod: typeof APILogic !== 'undefined' ? APILogic : undefined,
checks: [],
},
{
name: 'Fetch',
version: `2.0.9`,
mod: typeof Fetch !== 'undefined' ? Fetch : undefined,
checks: [],
},
{
name: 'SelectManager',
version: `1.1.0`,
mod: typeof SelectManager !== 'undefined' ? SelectManager : undefined,
checks: [['GetPlayerID', 'function'], ['GetSelected', 'function'], ['GetWho', 'function']],
},
{
name: 'Muler',
version: `2.0.1`,
mod: typeof Muler !== 'undefined' ? Muler : undefined,
checks: [],
},
{
name: 'Plugger',
version: `1.0.6`,
mod: typeof Plugger !== 'undefined' ? Plugger : undefined,
checks: [],
},
{
name: 'MathOps',
version: `1.0.8`,
mod: typeof MathOps !== 'undefined' ? MathOps : undefined,
checks: [['MathProcessor', 'function']],
},
{
name: 'libTokenMarkers',
version: `0.1.2`,
mod: typeof libTokenMarkers !== 'undefined' ? libTokenMarkers : undefined,
checks: [['getStatus', 'function'], ['getStatuses', 'function'], ['getOrderedList', 'function']]
},
{
name: 'libTable',
version: `1.0.0`,
mod: typeof libTable !== 'undefined' ? libTable : undefined,
checks: [
['getTable', 'function'],
['getTables', 'function'],
['getItems', 'function'],
['getItemsByIndex', 'function'],
['getItemsByName', 'function'],
['getItemsByWeight', 'function'],
['getItemsByWeightedIndex', 'function']
]
},
{
name: 'checkLightLevel',
// version: `1.0.0.b3`,
mod: typeof checkLightLevel !== 'undefined' ? checkLightLevel : undefined,
checks: [['isLitBy', 'function']],
optional: true
},
{
name: 'Messenger',
version: `1.0.0`,
mod: typeof Messenger !== 'undefined' ? Messenger : undefined,
checks: [['Button', 'function'], ['MsgBox', 'function'], ['HE', 'function'], ['Html', 'function'], ['Css', 'function']]
}
];
if (!checkDependencies(reqs)) return;
});
return {};
})();

{ try { throw new Error(''); } catch (e) { API_Meta.MetaScriptToolbox.lineCount = (parseInt(e.stack.split(/\n/)[1].replace(/^.*:(\d+):.*$/, '$1'), 10) - API_Meta.MetaScriptToolbox.offset); } }
Loading
Loading