Added field for running logic code upon objective completion

This commit is contained in:
Anuken
2026-02-06 22:46:17 -05:00
parent 7d88eeee77
commit 67d3a9feb0
4 changed files with 39 additions and 20 deletions

View File

@@ -67,6 +67,28 @@ public class LExecutor{
Events.on(ResetEvent.class, e -> unitTimeouts.clear());
}
public static void runLogicScript(String code){
runLogicScript(code, 100_000, false);
}
public static void runLogicScript(String code, int maxInstructions, boolean loop){
LExecutor executor = new LExecutor();
executor.privileged = true;
try{
//assembler has no variables, all the standard ones are null
executor.load(LAssembler.assemble(code, true));
}catch(Throwable ignored){
return;
}
//executions are limited to prevent a game freeze
for(int i = 1; i < maxInstructions; i++){
if((!loop && executor.counter.numval >= executor.instructions.length || executor.counter.numval < 0) || executor.yield) break;
executor.runOnce();
}
}
boolean timeoutDone(Unit unit, float delay){
return Time.time >= unitTimeouts.get(unit.id) + delay;
}