Implement lazy loading of scripts when they enter a new block

This commit is contained in:
Melledy
2022-04-29 02:07:25 -07:00
parent 3af5d20473
commit 1a5d4cf466
3 changed files with 29 additions and 8 deletions

View File

@@ -482,8 +482,8 @@ public class Scene {
for (SceneBlock block : visible) {
if (!this.getLoadedBlocks().contains(block)) {
this.getLoadedBlocks().add(block);
this.onLoadBlock(block);
this.getLoadedBlocks().add(block);
}
}
}
@@ -491,11 +491,17 @@ public class Scene {
// TODO optimize
public void onLoadBlock(SceneBlock block) {
for (SceneGroup group : block.groups) {
// We load the script files for the groups here
if (!group.isLoaded()) {
this.getScriptManager().loadGroupFromScript(group);
}
group.triggers.forEach(getScriptManager()::registerTrigger);
}
// Spawn gadgets AFTER triggers are added
for (SceneGroup group : block.groups) {
this.getScriptManager().spawnGadgetsInGroup(block, group);
this.getScriptManager().spawnGadgetsInGroup(group);
}
}