mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-27 01:33:16 +00:00
Log script messages to debug
instead of info
.
This commit is contained in:
parent
ca27c3917f
commit
6ea556896a
@ -109,7 +109,7 @@ public class ScriptLoader {
|
||||
return sc.get();
|
||||
}
|
||||
|
||||
Grasscutter.getLogger().info("Loading script " + path);
|
||||
Grasscutter.getLogger().debug("Loading script " + path);
|
||||
|
||||
File file = new File(path);
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class SceneBlock {
|
||||
private transient boolean loaded; // Not an actual variable in the scripts either
|
||||
|
||||
public boolean isLoaded() {
|
||||
return loaded;
|
||||
return this.loaded;
|
||||
}
|
||||
|
||||
public void setLoaded(boolean loaded) {
|
||||
@ -40,19 +40,19 @@ public class SceneBlock {
|
||||
}
|
||||
|
||||
public boolean contains(Position pos) {
|
||||
return pos.getX() <= max.getX() && pos.getX() >= min.getX() &&
|
||||
pos.getZ() <= max.getZ() && pos.getZ() >= min.getZ();
|
||||
return pos.getX() <= this.max.getX() && pos.getX() >= this.min.getX() &&
|
||||
pos.getZ() <= this.max.getZ() && pos.getZ() >= this.min.getZ();
|
||||
}
|
||||
|
||||
public SceneBlock load(int sceneId, Bindings bindings){
|
||||
if(loaded){
|
||||
if(this.loaded){
|
||||
return this;
|
||||
}
|
||||
this.sceneId = sceneId;
|
||||
setLoaded(true);
|
||||
this.setLoaded(true);
|
||||
|
||||
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) {
|
||||
return null;
|
||||
@ -63,19 +63,19 @@ public class SceneBlock {
|
||||
cs.eval(bindings);
|
||||
|
||||
// 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));
|
||||
|
||||
groups.values().forEach(g -> g.block_id = id);
|
||||
this.sceneGroupIndex = SceneIndexManager.buildIndex(3, groups.values(), g -> g.pos.toPoint());
|
||||
} catch (ScriptException e) {
|
||||
Grasscutter.getLogger().error("Error loading block " + id + " in scene " + sceneId, e);
|
||||
this.groups.values().forEach(g -> g.block_id = this.id);
|
||||
this.sceneGroupIndex = SceneIndexManager.buildIndex(3, this.groups.values(), g -> g.pos.toPoint());
|
||||
} catch (ScriptException exception) {
|
||||
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;
|
||||
}
|
||||
|
||||
public Rectangle toRectangle() {
|
||||
return Rectangle.create(min.toXZDoubleArray(), max.toXZDoubleArray());
|
||||
return Rectangle.create(this.min.toXZDoubleArray(), this.max.toXZDoubleArray());
|
||||
}
|
||||
}
|
@ -52,7 +52,7 @@ public class SceneGroup {
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return loaded;
|
||||
return this.loaded;
|
||||
}
|
||||
|
||||
public void setLoaded(boolean loaded) {
|
||||
@ -68,28 +68,28 @@ public class SceneGroup {
|
||||
}
|
||||
|
||||
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;
|
||||
@ -99,86 +99,86 @@ public class SceneGroup {
|
||||
|
||||
// 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();
|
||||
|
@ -43,18 +43,18 @@ public class SceneMeta {
|
||||
}
|
||||
|
||||
// Create bindings
|
||||
context = ScriptLoader.getEngine().createBindings();
|
||||
this.context = ScriptLoader.getEngine().createBindings();
|
||||
|
||||
// Eval script
|
||||
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
|
||||
// Create blocks
|
||||
List<Integer> blockIds = ScriptLoader.getSerializer().toList(Integer.class, context.get("blocks"));
|
||||
List<SceneBlock> blocks = ScriptLoader.getSerializer().toList(SceneBlock.class, context.get("block_rects"));
|
||||
List<Integer> blockIds = ScriptLoader.getSerializer().toList(Integer.class, this.context.get("blocks"));
|
||||
List<SceneBlock> blocks = ScriptLoader.getSerializer().toList(SceneBlock.class, this.context.get("block_rects"));
|
||||
|
||||
for (int i = 0; i < blocks.size(); i++) {
|
||||
SceneBlock block = blocks.get(i);
|
||||
@ -65,11 +65,11 @@ public class SceneMeta {
|
||||
this.blocks = blocks.stream().collect(Collectors.toMap(b -> b.id, b -> b));
|
||||
this.sceneBlockIndex = SceneIndexManager.buildIndex(2, blocks, SceneBlock::toRectangle);
|
||||
|
||||
} catch (ScriptException e) {
|
||||
Grasscutter.getLogger().error("Error running script", e);
|
||||
} catch (ScriptException exception) {
|
||||
Grasscutter.getLogger().error("An error occurred while running a script.", exception);
|
||||
return null;
|
||||
}
|
||||
Grasscutter.getLogger().info("scene {} metadata is loaded successfully.", sceneId);
|
||||
Grasscutter.getLogger().debug("Successfully loaded metadata in scene {}.", sceneId);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user