Commit 44736059 authored by KingRainbow44's avatar KingRainbow44
Browse files

Log script messages to `debug` instead of `info`.

parent 34f7c6e7
...@@ -109,7 +109,7 @@ public class ScriptLoader { ...@@ -109,7 +109,7 @@ public class ScriptLoader {
return sc.get(); return sc.get();
} }
Grasscutter.getLogger().info("Loading script " + path); Grasscutter.getLogger().debug("Loading script " + path);
File file = new File(path); File file = new File(path);
......
...@@ -32,7 +32,7 @@ public class SceneBlock { ...@@ -32,7 +32,7 @@ public class SceneBlock {
private transient boolean loaded; // Not an actual variable in the scripts either private transient boolean loaded; // Not an actual variable in the scripts either
public boolean isLoaded() { public boolean isLoaded() {
return loaded; return this.loaded;
} }
public void setLoaded(boolean loaded) { public void setLoaded(boolean loaded) {
...@@ -40,19 +40,19 @@ public class SceneBlock { ...@@ -40,19 +40,19 @@ public class SceneBlock {
} }
public boolean contains(Position pos) { public boolean contains(Position pos) {
return pos.getX() <= max.getX() && pos.getX() >= min.getX() && return pos.getX() <= this.max.getX() && pos.getX() >= this.min.getX() &&
pos.getZ() <= max.getZ() && pos.getZ() >= min.getZ(); pos.getZ() <= this.max.getZ() && pos.getZ() >= this.min.getZ();
} }
public SceneBlock load(int sceneId, Bindings bindings){ public SceneBlock load(int sceneId, Bindings bindings){
if(loaded){ if(this.loaded){
return this; return this;
} }
this.sceneId = sceneId; this.sceneId = sceneId;
setLoaded(true); this.setLoaded(true);
CompiledScript cs = ScriptLoader.getScriptByPath( CompiledScript cs = ScriptLoader.getScriptByPath(
SCRIPT("Scene/" + sceneId + "/scene" + sceneId + "_block" + id + "." + ScriptLoader.getScriptType())); SCRIPT("Scene/" + sceneId + "/scene" + sceneId + "_block" + this.id + "." + ScriptLoader.getScriptType()));
if (cs == null) { if (cs == null) {
return null; return null;
...@@ -63,19 +63,19 @@ public class SceneBlock { ...@@ -63,19 +63,19 @@ public class SceneBlock {
cs.eval(bindings); cs.eval(bindings);
// Set groups // Set groups
groups = ScriptLoader.getSerializer().toList(SceneGroup.class, bindings.get("groups")).stream() this.groups = ScriptLoader.getSerializer().toList(SceneGroup.class, bindings.get("groups")).stream()
.collect(Collectors.toMap(x -> x.id, y -> y)); .collect(Collectors.toMap(x -> x.id, y -> y));
groups.values().forEach(g -> g.block_id = id); this.groups.values().forEach(g -> g.block_id = this.id);
this.sceneGroupIndex = SceneIndexManager.buildIndex(3, groups.values(), g -> g.pos.toPoint()); this.sceneGroupIndex = SceneIndexManager.buildIndex(3, this.groups.values(), g -> g.pos.toPoint());
} catch (ScriptException e) { } catch (ScriptException exception) {
Grasscutter.getLogger().error("Error loading block " + id + " in scene " + sceneId, e); Grasscutter.getLogger().error("An error occurred while loading block " + this.id + " in scene " + sceneId, exception);
} }
Grasscutter.getLogger().info("scene {} block {} is loaded successfully.", sceneId, id); Grasscutter.getLogger().debug("Successfully loaded block {} in scene {}.", this.id, sceneId);
return this; return this;
} }
public Rectangle toRectangle() { public Rectangle toRectangle() {
return Rectangle.create(min.toXZDoubleArray(), max.toXZDoubleArray()); return Rectangle.create(this.min.toXZDoubleArray(), this.max.toXZDoubleArray());
} }
} }
\ No newline at end of file
...@@ -52,7 +52,7 @@ public class SceneGroup { ...@@ -52,7 +52,7 @@ public class SceneGroup {
} }
public boolean isLoaded() { public boolean isLoaded() {
return loaded; return this.loaded;
} }
public void setLoaded(boolean loaded) { public void setLoaded(boolean loaded) {
...@@ -68,28 +68,28 @@ public class SceneGroup { ...@@ -68,28 +68,28 @@ public class SceneGroup {
} }
public CompiledScript getScript() { public CompiledScript getScript() {
return script; return this.script;
} }
public SceneSuite getSuiteByIndex(int index) { public SceneSuite getSuiteByIndex(int index) {
return suites.get(index - 1); return this.suites.get(index - 1);
} }
public Bindings getBindings() { public Bindings getBindings() {
return bindings; return this.bindings;
} }
public synchronized SceneGroup load(int sceneId){ public synchronized SceneGroup load(int sceneId){
if(loaded){ if(this.loaded){
return this; return this;
} }
// Set flag here so if there is no script, we dont call this function over and over again. // Set flag here so if there is no script, we don't call this function over and over again.
setLoaded(true); this.setLoaded(true);
this.bindings = ScriptLoader.getEngine().createBindings(); this.bindings = ScriptLoader.getEngine().createBindings();
CompiledScript cs = ScriptLoader.getScriptByPath( 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) { if (cs == null) {
return this; return this;
...@@ -99,86 +99,86 @@ public class SceneGroup { ...@@ -99,86 +99,86 @@ public class SceneGroup {
// Eval script // Eval script
try { try {
cs.eval(bindings); cs.eval(this.bindings);
// Set // 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)); .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)); .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)); .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")); this.suites = ScriptLoader.getSerializer().toList(SceneSuite.class, this.bindings.get("suites"));
regions = ScriptLoader.getSerializer().toList(SceneRegion.class, bindings.get("regions")).stream() this.regions = ScriptLoader.getSerializer().toList(SceneRegion.class, this.bindings.get("regions")).stream()
.collect(Collectors.toMap(x -> x.config_id, y -> y)); .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 // Garbages // TODO: fix properly later
Object garbagesValue = bindings.get("garbages"); Object garbagesValue = this.bindings.get("garbages");
if (garbagesValue != null && garbagesValue instanceof LuaValue garbagesTable) { if (garbagesValue instanceof LuaValue garbagesTable) {
garbages = new SceneGarbage(); this.garbages = new SceneGarbage();
if (garbagesTable.checktable().get("gadgets") != LuaValue.NIL) { if (garbagesTable.checktable().get("gadgets") != LuaValue.NIL) {
garbages.gadgets = ScriptLoader.getSerializer().toList(SceneGadget.class, garbagesTable.checktable().get("gadgets").checktable()); this.garbages.gadgets = ScriptLoader.getSerializer().toList(SceneGadget.class, garbagesTable.checktable().get("gadgets").checktable());
garbages.gadgets.forEach(m -> m.group = this); this.garbages.gadgets.forEach(m -> m.group = this);
} }
} }
// Add variables to suite // 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 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)); .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 // Add monsters and gadgets to suite
for (SceneSuite suite : suites) { for (SceneSuite suite : this.suites) {
suite.sceneMonsters = new ArrayList<>( suite.sceneMonsters = new ArrayList<>(
suite.monsters.stream() suite.monsters.stream()
.filter(monsters::containsKey) .filter(this.monsters::containsKey)
.map(monsters::get) .map(this.monsters::get)
.toList() .toList()
); );
suite.sceneGadgets = new ArrayList<>( suite.sceneGadgets = new ArrayList<>(
suite.gadgets.stream() suite.gadgets.stream()
.filter(gadgets::containsKey) .filter(this.gadgets::containsKey)
.map(gadgets::get) .map(this.gadgets::get)
.toList() .toList()
); );
suite.sceneTriggers = new ArrayList<>( suite.sceneTriggers = new ArrayList<>(
suite.triggers.stream() suite.triggers.stream()
.filter(triggers::containsKey) .filter(this.triggers::containsKey)
.map(triggers::get) .map(this.triggers::get)
.toList() .toList()
); );
suite.sceneRegions = new ArrayList<>( suite.sceneRegions = new ArrayList<>(
suite.regions.stream() suite.regions.stream()
.filter(regions::containsKey) .filter(this.regions::containsKey)
.map(regions::get) .map(this.regions::get)
.toList() .toList()
); );
} }
} catch (ScriptException e) { } 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; return this;
} }
public Optional<SceneBossChest> searchBossChestInGroup() { 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) .filter(g -> g.boss_chest != null && g.boss_chest.monster_config_id > 0)
.map(g -> g.boss_chest) .map(g -> g.boss_chest)
.findFirst(); .findFirst();
......
...@@ -43,18 +43,18 @@ public class SceneMeta { ...@@ -43,18 +43,18 @@ public class SceneMeta {
} }
// Create bindings // Create bindings
context = ScriptLoader.getEngine().createBindings(); this.context = ScriptLoader.getEngine().createBindings();
// Eval script // Eval script
try { try {
cs.eval(context); cs.eval(this.context);
this.config = ScriptLoader.getSerializer().toObject(SceneConfig.class, context.get("scene_config")); this.config = ScriptLoader.getSerializer().toObject(SceneConfig.class, this.context.get("scene_config"));
// TODO optimize later // TODO optimize later
// Create blocks // Create blocks
List<Integer> blockIds = ScriptLoader.getSerializer().toList(Integer.class, context.get("blocks")); List<Integer> blockIds = ScriptLoader.getSerializer().toList(Integer.class, this.context.get("blocks"));
List<SceneBlock> blocks = ScriptLoader.getSerializer().toList(SceneBlock.class, context.get("block_rects")); List<SceneBlock> blocks = ScriptLoader.getSerializer().toList(SceneBlock.class, this.context.get("block_rects"));
for (int i = 0; i < blocks.size(); i++) { for (int i = 0; i < blocks.size(); i++) {
SceneBlock block = blocks.get(i); SceneBlock block = blocks.get(i);
...@@ -65,11 +65,11 @@ public class SceneMeta { ...@@ -65,11 +65,11 @@ public class SceneMeta {
this.blocks = blocks.stream().collect(Collectors.toMap(b -> b.id, b -> b)); this.blocks = blocks.stream().collect(Collectors.toMap(b -> b.id, b -> b));
this.sceneBlockIndex = SceneIndexManager.buildIndex(2, blocks, SceneBlock::toRectangle); this.sceneBlockIndex = SceneIndexManager.buildIndex(2, blocks, SceneBlock::toRectangle);
} catch (ScriptException e) { } catch (ScriptException exception) {
Grasscutter.getLogger().error("Error running script", e); Grasscutter.getLogger().error("An error occurred while running a script.", exception);
return null; return null;
} }
Grasscutter.getLogger().info("scene {} metadata is loaded successfully.", sceneId); Grasscutter.getLogger().debug("Successfully loaded metadata in scene {}.", sceneId);
return this; return this;
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment