Automatically reload particles on file change

This commit is contained in:
JannisX11 2021-02-14 23:24:32 +01:00
parent 994d955820
commit cd47331a67

View File

@ -1408,6 +1408,19 @@ const Animator = {
config: new Wintersky.Config(json_content, {path}),
emitters: {}
};
if (isApp) {
let timeout;
this.watcher = fs.watch(path, (eventType) => {
if (eventType == 'change') {
if (timeout) clearTimeout(timeout)
timeout = setTimeout(() => {
Blockbench.read(path, {errorbox: false}, (files) => {
Animator.loadParticleEmitter(path, files[0].content);
})
}, 60)
}
})
}
}
},
loadFile(file, animation_filter) {
@ -1654,6 +1667,15 @@ Blockbench.on('update_camera_position', e => {
Animator.updateMotionTrailScale();
}
})
Blockbench.on('reset_project', () => {
for (let path in Animator.particle_effects) {
let effect = Animator.particle_effects[path];
if (isApp && effect.watcher) {
effect.watcher.close()
}
delete Animator.particle_effects[path];
}
})
Animator.MolangParser.global_variables = {
'true': 1,