optimized the Lua func binding so that the script will not eval again

This commit is contained in:
Akka
2022-05-19 11:15:40 +08:00
committed by Melledy
parent a8f38ad995
commit bad853573c
7 changed files with 89 additions and 79 deletions

View File

@@ -10,12 +10,11 @@ import javax.script.Bindings;
import javax.script.CompiledScript;
import javax.script.ScriptException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static emu.grasscutter.Configuration.*;
import static emu.grasscutter.Configuration.SCRIPT;
@ToString
@Setter
@@ -40,6 +39,7 @@ public class SceneGroup {
private transient boolean loaded; // Not an actual variable in the scripts either
private transient CompiledScript script;
private transient Bindings bindings;
public boolean isLoaded() {
return loaded;
@@ -65,13 +65,19 @@ public class SceneGroup {
return suites.get(index - 1);
}
public SceneGroup load(int sceneId, Bindings bindings){
public Bindings getBindings() {
return bindings;
}
public SceneGroup load(int sceneId){
if(loaded){
return this;
}
// Set flag here so if there is no script, we dont call this function over and over again.
setLoaded(true);
this.bindings = ScriptLoader.getEngine().createBindings();
CompiledScript cs = ScriptLoader.getScriptByPath(
SCRIPT("Scene/" + sceneId + "/scene" + sceneId + "_group" + id + "." + ScriptLoader.getScriptType()));