Log script messages to debug instead of info.

This commit is contained in:
KingRainbow44
2022-06-26 12:20:48 -04:00
parent 34f7c6e780
commit 447360594d
4 changed files with 75 additions and 75 deletions

View File

@@ -25,7 +25,7 @@ import static emu.grasscutter.Configuration.SCRIPT;
@Setter
public class SceneGroup {
public transient int block_id; // Not an actual variable in the scripts but we will keep it here for reference
public int id;
public int refresh_id;
public Position pos;
@@ -52,133 +52,133 @@ public class SceneGroup {
}
public boolean isLoaded() {
return loaded;
return this.loaded;
}
public void setLoaded(boolean loaded) {
this.loaded = loaded;
}
public int getBusinessType() {
return this.business == null ? 0 : this.business.type;
}
public List<SceneGadget> getGarbageGadgets() {
return this.garbages == null ? null : this.garbages.gadgets;
}
public CompiledScript getScript() {
return script;
return this.script;
}
public SceneSuite getSuiteByIndex(int index) {
return suites.get(index - 1);
return this.suites.get(index - 1);
}
public Bindings getBindings() {
return bindings;
return this.bindings;
}
public synchronized SceneGroup load(int sceneId){
if(loaded){
if(this.loaded){
return this;
}
// Set flag here so if there is no script, we dont call this function over and over again.
setLoaded(true);
// Set flag here so if there is no script, we don't call this function over and over again.
this.setLoaded(true);
this.bindings = ScriptLoader.getEngine().createBindings();
CompiledScript cs = ScriptLoader.getScriptByPath(
SCRIPT("Scene/" + sceneId + "/scene" + sceneId + "_group" + id + "." + ScriptLoader.getScriptType()));
SCRIPT("Scene/" + sceneId + "/scene" + sceneId + "_group" + this.id + "." + ScriptLoader.getScriptType()));
if (cs == null) {
return this;
}
this.script = cs;
// Eval script
try {
cs.eval(bindings);
cs.eval(this.bindings);
// Set
monsters = ScriptLoader.getSerializer().toList(SceneMonster.class, bindings.get("monsters")).stream()
this.monsters = ScriptLoader.getSerializer().toList(SceneMonster.class, this.bindings.get("monsters")).stream()
.collect(Collectors.toMap(x -> x.config_id, y -> y));
monsters.values().forEach(m -> m.group = this);
this.monsters.values().forEach(m -> m.group = this);
gadgets = ScriptLoader.getSerializer().toList(SceneGadget.class, bindings.get("gadgets")).stream()
this.gadgets = ScriptLoader.getSerializer().toList(SceneGadget.class, this.bindings.get("gadgets")).stream()
.collect(Collectors.toMap(x -> x.config_id, y -> y));
gadgets.values().forEach(m -> m.group = this);
this.gadgets.values().forEach(m -> m.group = this);
triggers = ScriptLoader.getSerializer().toList(SceneTrigger.class, bindings.get("triggers")).stream()
this.triggers = ScriptLoader.getSerializer().toList(SceneTrigger.class, this.bindings.get("triggers")).stream()
.collect(Collectors.toMap(x -> x.name, y -> y));
triggers.values().forEach(t -> t.currentGroup = this);
this.triggers.values().forEach(t -> t.currentGroup = this);
suites = ScriptLoader.getSerializer().toList(SceneSuite.class, bindings.get("suites"));
regions = ScriptLoader.getSerializer().toList(SceneRegion.class, bindings.get("regions")).stream()
this.suites = ScriptLoader.getSerializer().toList(SceneSuite.class, this.bindings.get("suites"));
this.regions = ScriptLoader.getSerializer().toList(SceneRegion.class, this.bindings.get("regions")).stream()
.collect(Collectors.toMap(x -> x.config_id, y -> y));
regions.values().forEach(m -> m.group = this);
this.regions.values().forEach(m -> m.group = this);
init_config = ScriptLoader.getSerializer().toObject(SceneInitConfig.class, bindings.get("init_config"));
this.init_config = ScriptLoader.getSerializer().toObject(SceneInitConfig.class, this.bindings.get("init_config"));
// Garbages TODO fix properly later
Object garbagesValue = bindings.get("garbages");
if (garbagesValue != null && garbagesValue instanceof LuaValue garbagesTable) {
garbages = new SceneGarbage();
// Garbages // TODO: fix properly later
Object garbagesValue = this.bindings.get("garbages");
if (garbagesValue instanceof LuaValue garbagesTable) {
this.garbages = new SceneGarbage();
if (garbagesTable.checktable().get("gadgets") != LuaValue.NIL) {
garbages.gadgets = ScriptLoader.getSerializer().toList(SceneGadget.class, garbagesTable.checktable().get("gadgets").checktable());
garbages.gadgets.forEach(m -> m.group = this);
this.garbages.gadgets = ScriptLoader.getSerializer().toList(SceneGadget.class, garbagesTable.checktable().get("gadgets").checktable());
this.garbages.gadgets.forEach(m -> m.group = this);
}
}
// Add variables to suite
variables = ScriptLoader.getSerializer().toList(SceneVar.class, bindings.get("variables"));
this.variables = ScriptLoader.getSerializer().toList(SceneVar.class, this.bindings.get("variables"));
// NPC in groups
npc = ScriptLoader.getSerializer().toList(SceneNPC.class, bindings.get("npcs")).stream()
this.npc = ScriptLoader.getSerializer().toList(SceneNPC.class, this.bindings.get("npcs")).stream()
.collect(Collectors.toMap(x -> x.npc_id, y -> y));
npc.values().forEach(n -> n.group = this);
this.npc.values().forEach(n -> n.group = this);
// Add monsters and gadgets to suite
for (SceneSuite suite : suites) {
for (SceneSuite suite : this.suites) {
suite.sceneMonsters = new ArrayList<>(
suite.monsters.stream()
.filter(monsters::containsKey)
.map(monsters::get)
.filter(this.monsters::containsKey)
.map(this.monsters::get)
.toList()
);
suite.sceneGadgets = new ArrayList<>(
suite.gadgets.stream()
.filter(gadgets::containsKey)
.map(gadgets::get)
.filter(this.gadgets::containsKey)
.map(this.gadgets::get)
.toList()
);
suite.sceneTriggers = new ArrayList<>(
suite.triggers.stream()
.filter(triggers::containsKey)
.map(triggers::get)
.filter(this.triggers::containsKey)
.map(this.triggers::get)
.toList()
);
suite.sceneRegions = new ArrayList<>(
suite.regions.stream()
.filter(regions::containsKey)
.map(regions::get)
.filter(this.regions::containsKey)
.map(this.regions::get)
.toList()
);
}
} catch (ScriptException e) {
Grasscutter.getLogger().error("Error loading group " + id + " in scene " + sceneId, e);
Grasscutter.getLogger().error("An error occurred while loading group " + this.id + " in scene " + sceneId + ".", e);
}
Grasscutter.getLogger().info("group {} in scene {} is loaded successfully.", id, sceneId);
Grasscutter.getLogger().debug("Successfully loaded group {} in scene {}.", this.id, sceneId);
return this;
}
public Optional<SceneBossChest> searchBossChestInGroup() {
return gadgets.values().stream()
return this.gadgets.values().stream()
.filter(g -> g.boss_chest != null && g.boss_chest.monster_config_id > 0)
.map(g -> g.boss_chest)
.findFirst();