Load animations only when switching to the tab

This commit is contained in:
JannisX11 2020-10-09 22:12:26 +02:00
parent d59510da30
commit a3479578ce
3 changed files with 46 additions and 35 deletions

View File

@ -1136,6 +1136,10 @@ const Animator = {
get selected() {return Animation.selected},
MolangParser: new Molang(),
join() {
if ((Format.id == 'bedrock' || Format.id == 'bedrock_old') && !BedrockEntityManager.initialized_animations) {
BedrockEntityManager.initAnimations();
}
Animator.open = true;
selected.empty()

View File

@ -130,45 +130,51 @@ window.BedrockEntityManager = {
}
}
// Animations
var anim_list = BedrockEntityManager.client_entity.description.animations
if (anim_list instanceof Object) {
let animation_names = [];
for (var key in anim_list) {
if (anim_list[key].match && anim_list[key].match(/^animation\./)) {
animation_names.push(anim_list[key]);
}
}
// get all paths in folder
let anim_files = [];
function searchFolder(path) {
try {
var files = fs.readdirSync(path);
for (var name of files) {
var new_path = path + osfs + name;
if (name.match(/\.json$/)) {
anim_files.push(new_path);
} else if (!name.includes('.')) {
searchFolder(new_path);
}
}
} catch (err) {}
}
searchFolder(PathModule.join(BedrockEntityManager.root_path, 'animations'));
anim_files.forEach(path => {
try {
let content = fs.readFileSync(path, 'utf8');
Animator.loadFile({path, content}, animation_names);
} catch (err) {}
})
}
} else {
BedrockEntityManager.findEntityTexture(Project.geometry_name)
}
},
initAnimations() {
var anim_list = BedrockEntityManager.client_entity.description.animations
if (anim_list instanceof Object) {
let animation_names = [];
for (var key in anim_list) {
if (anim_list[key].match && anim_list[key].match(/^animation\./)) {
animation_names.push(anim_list[key]);
}
}
// get all paths in folder
let anim_files = [];
function searchFolder(path) {
try {
var files = fs.readdirSync(path);
for (var name of files) {
var new_path = path + osfs + name;
if (name.match(/\.json$/)) {
anim_files.push(new_path);
} else if (!name.includes('.')) {
searchFolder(new_path);
}
}
} catch (err) {}
}
searchFolder(PathModule.join(BedrockEntityManager.root_path, 'animations'));
anim_files.forEach(path => {
try {
let content = fs.readFileSync(path, 'utf8');
Animator.loadFile({path, content}, animation_names);
} catch (err) {}
})
}
BedrockEntityManager.initialized_animations = true;
},
reset() {
delete BedrockEntityManager.initialized_animations;
delete BedrockEntityManager.client_entity;
delete BedrockEntityManager.root_path;
},
findEntityTexture(mob, return_path) {
if (!mob) return;
var textures = {

View File

@ -41,6 +41,7 @@ class ModelProject {
if (Toolbox.selected.id !== 'move_tool') BarItems.move_tool.select();
Screencam.stopTimelapse();
BedrockEntityManager.reset();
Format = 0;
for (var uuid in OutlinerElement.uuids) {