Add global vars to RPN

This commit is contained in:
kwaroran
2024-06-28 08:23:51 +09:00
parent eaa9bfa94e
commit 1e4fb7633e

View File

@@ -1,4 +1,4 @@
import { getChatVar } from "../parser";
import { getChatVar, getGlobalChatVar } from "../parser";
function toRPN(expression:string) {
let outputQueue = '';
@@ -114,6 +114,13 @@ function executeRPNCalculation(text:string) {
return "0"
}
return parsed.toString()
}).replace(/\@([a-zA-Z0-9_]+)/g, (_, p1) => {
const v = getGlobalChatVar(p1)
const parsed = parseFloat(v)
if(isNaN(parsed)){
return "0"
}
return parsed.toString()
}).replace(/&&/g, '&').replace(/\|\|/g, '|').replace(/<=/g, '≤').replace(/>=/g, '≥').replace(/==/g, '=').replace(/null/gi, '0')
const expression = toRPN(text);
const evaluated = calculateRPN(expression);