Adv item search: pass item data to query functions

This commit is contained in:
phantamanta44 2021-03-14 11:34:29 -05:00
parent 1ed397dd70
commit 62cd641a80

View file

@ -171,7 +171,7 @@ const itemQueryProps = (function() {
const itemQueryFuncs = { const itemQueryFuncs = {
max: { max: {
type: 'number', type: 'number',
fn: function(args) { fn: function(item, itemExp, args) {
if (args.length < 1) throw new Error('Not enough args to max()'); if (args.length < 1) throw new Error('Not enough args to max()');
let runningMax = -Infinity; let runningMax = -Infinity;
for (let i = 0; i < args.length; i++) { for (let i = 0; i < args.length; i++) {
@ -182,7 +182,7 @@ const itemQueryFuncs = {
}, },
min: { min: {
type: 'number', type: 'number',
fn: function(args) { fn: function(item, itemExp, args) {
if (args.length < 1) throw new Error('Not enough args to min()'); if (args.length < 1) throw new Error('Not enough args to min()');
let runningMin = Infinity; let runningMin = Infinity;
for (let i = 0; i < args.length; i++) { for (let i = 0; i < args.length; i++) {
@ -193,49 +193,49 @@ const itemQueryFuncs = {
}, },
floor: { floor: {
type: 'number', type: 'number',
fn: function(args) { fn: function(item, itemExp, args) {
if (args.length < 1) throw new Error('Not enough args to floor()'); if (args.length < 1) throw new Error('Not enough args to floor()');
return Math.floor(checkNum(args[0])); return Math.floor(checkNum(args[0]));
} }
}, },
ceil: { ceil: {
type: 'number', type: 'number',
fn: function(args) { fn: function(item, itemExp, args) {
if (args.length < 1) throw new Error('Not enough args to ceil()'); if (args.length < 1) throw new Error('Not enough args to ceil()');
return Math.ceil(checkNum(args[0])); return Math.ceil(checkNum(args[0]));
} }
}, },
round: { round: {
type: 'number', type: 'number',
fn: function(args) { fn: function(item, itemExp, args) {
if (args.length < 1) throw new Error('Not enough args to round()'); if (args.length < 1) throw new Error('Not enough args to round()');
return Math.round(checkNum(args[0])); return Math.round(checkNum(args[0]));
} }
}, },
sqrt: { sqrt: {
type: 'number', type: 'number',
fn: function(args) { fn: function(item, itemExp, args) {
if (args.length < 1) throw new Error('Not enough args to sqrt()'); if (args.length < 1) throw new Error('Not enough args to sqrt()');
return Math.sqrt(checkNum(args[0])); return Math.sqrt(checkNum(args[0]));
} }
}, },
abs: { abs: {
type: 'number', type: 'number',
fn: function(args) { fn: function(item, itemExp, args) {
if (args.length < 1) throw new Error('Not enough args to abs()'); if (args.length < 1) throw new Error('Not enough args to abs()');
return Math.abs(checkNum(args[0])); return Math.abs(checkNum(args[0]));
} }
}, },
contains: { contains: {
type: 'boolean', type: 'boolean',
fn: function(args) { fn: function(item, itemExp, args) {
if (args.length < 2) throw new Error('Not enough args to contains()'); if (args.length < 2) throw new Error('Not enough args to contains()');
return checkStr(args[0]).toLowerCase().includes(checkStr(args[1]).toLowerCase()); return checkStr(args[0]).toLowerCase().includes(checkStr(args[1]).toLowerCase());
} }
}, },
atkspdmod: { atkspdmod: {
type: 'number', type: 'number',
fn: function(args) { fn: function(item, itemExp, args) {
if (args.length < 1) throw new Error('Not enough args to atkSpdMod()'); if (args.length < 1) throw new Error('Not enough args to atkSpdMod()');
switch (checkNum(args[0])) { switch (checkNum(args[0])) {
case 2: case 2:
@ -492,7 +492,7 @@ class FnCallTerm extends Term {
for (const argExpr of this.argExprs) { for (const argExpr of this.argExprs) {
argVals.push(argExpr.resolve(item, itemExt)); argVals.push(argExpr.resolve(item, itemExt));
} }
return this.fn.fn(argVals); return this.fn.fn(item, itemExt, argVals);
} }
} }