This commit is contained in:
TheGiddyLimit
2024-01-01 19:34:49 +00:00
parent 332769043f
commit 8117ebddc5
1748 changed files with 2544409 additions and 1 deletions

24
js/genutils.js Normal file
View File

@@ -0,0 +1,24 @@
"use strict";
class GenUtil {
/**
* @param table An array of objects with a `min` and optional `max` per item.
* @param roll The roll to look up.
* @param maxZero A value to convert `max` values of `0` to.
*/
static getFromTable (table, roll, maxZero = 100) {
const it = {};
Object.assign(it, table.find(it => {
return it.min === roll || (it.max != null && roll >= it.min && roll <= (it.max === 0 ? maxZero : it.max));
}));
Object.keys(it).forEach(k => {
if (typeof it[k] === "function") {
it[k] = it[k]();
}
});
if (it.display && !it.result) it.result = it.display;
if (it.display) it.display = Renderer.get().render(it.display);
if (it.result) it.result = Renderer.get().render(it.result);
return it;
}
}