MCPcopy Create free account
hub / github.com/Frontrooms/3.0-GC / load

Method load

src/main/java/emu/grasscutter/scripts/data/SceneMeta.java:35–74  ·  view source on GitHub ↗
(int sceneId)

Source from the content-addressed store, hash-verified

33 }
34
35 public SceneMeta load(int sceneId){
36 // Get compiled script if cached
37 CompiledScript cs = ScriptLoader.getScriptByPath(
38 SCRIPT("Scene/" + sceneId + "/scene" + sceneId + "." + ScriptLoader.getScriptType()));
39
40 if (cs == null) {
41 Grasscutter.getLogger().warn("No script found for scene " + sceneId);
42 return null;
43 }
44
45 // Create bindings
46 this.context = ScriptLoader.getEngine().createBindings();
47
48 // Eval script
49 try {
50 cs.eval(this.context);
51
52 this.config = ScriptLoader.getSerializer().toObject(SceneConfig.class, this.context.get("scene_config"));
53
54 // TODO optimize later
55 // Create blocks
56 List<Integer> blockIds = ScriptLoader.getSerializer().toList(Integer.class, this.context.get("blocks"));
57 List<SceneBlock> blocks = ScriptLoader.getSerializer().toList(SceneBlock.class, this.context.get("block_rects"));
58
59 for (int i = 0; i < blocks.size(); i++) {
60 SceneBlock block = blocks.get(i);
61 block.id = blockIds.get(i);
62
63 }
64
65 this.blocks = blocks.stream().collect(Collectors.toMap(b -> b.id, b -> b));
66 this.sceneBlockIndex = SceneIndexManager.buildIndex(2, blocks, SceneBlock::toRectangle);
67
68 } catch (ScriptException exception) {
69 Grasscutter.getLogger().error("An error occurred while running a script.", exception);
70 return null;
71 }
72 Grasscutter.getLogger().debug("Successfully loaded metadata in scene {}.", sceneId);
73 return this;
74 }
75}

Callers 3

loadBlockFromScriptMethod · 0.45
loadGroupFromScriptMethod · 0.45
ofMethod · 0.45

Calls 12

getScriptByPathMethod · 0.95
getScriptTypeMethod · 0.95
getLoggerMethod · 0.95
getEngineMethod · 0.95
getSerializerMethod · 0.95
buildIndexMethod · 0.95
SCRIPTMethod · 0.80
getMethod · 0.80
toMapMethod · 0.80
toObjectMethod · 0.65
toListMethod · 0.65
sizeMethod · 0.45

Tested by

no test coverage detected