Let's you get a number from the stack to use in dice
This commit is contained in:
@@ -23,14 +23,18 @@ export class TTCQueryResolver {
|
||||
}
|
||||
|
||||
public resolve(resolver: string, onDemand?: boolean) {
|
||||
const resList = resolver.split(",");
|
||||
for (const res of resList) {
|
||||
this.stack.push(this.parseResolver(res));
|
||||
}
|
||||
const last = this.stack.at(-1);
|
||||
if (typeof last === "function" && !onDemand) return last();
|
||||
try {
|
||||
const resList = resolver.split(",");
|
||||
for (const res of resList) {
|
||||
this.stack.push(this.parseResolver(res));
|
||||
}
|
||||
const last = this.stack.at(-1);
|
||||
if (typeof last === "function" && !onDemand) return last();
|
||||
|
||||
return last;
|
||||
return last;
|
||||
} catch (e) {
|
||||
return e?.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private parseResolver(resolver: string) {
|
||||
@@ -51,8 +55,20 @@ export class TTCQueryResolver {
|
||||
const [_, idx, q] = query.match(/^(\$\d+)\.(.*)/) || [];
|
||||
if (!_) throw "Detected stack query but did not match the regex";
|
||||
const stackItem = this.getFromStack(idx);
|
||||
if (typeof stackItem === "string" && Dice.isDice(stackItem)) {
|
||||
return this.handleDice(stackItem, q);
|
||||
if (
|
||||
typeof stackItem === "string" &&
|
||||
Dice.isDice(
|
||||
stackItem.replace(/\$\d+/g, (e) =>
|
||||
this.getFromStack<number>(e).toString()
|
||||
)
|
||||
)
|
||||
) {
|
||||
return this.handleDice(
|
||||
stackItem.replace(/\$\d+/g, (e) =>
|
||||
this.getFromStack<number>(e).toString()
|
||||
),
|
||||
q
|
||||
);
|
||||
}
|
||||
|
||||
return this.parser.search(q, stackItem as QueryableObject);
|
||||
@@ -68,7 +84,7 @@ export class TTCQueryResolver {
|
||||
const d = new Dice(dice);
|
||||
const [method, n] = query.split(":");
|
||||
let num = Number(n);
|
||||
if (n && n.startsWith("$")) num = this.getFromStack(n);
|
||||
// if (n && n.startsWith("$")) num = this.getFromStack(n);
|
||||
switch (method) {
|
||||
case "roll":
|
||||
return () => d.roll().total;
|
||||
|
Reference in New Issue
Block a user