Saving animations
This commit is contained in:
parent
50aca07743
commit
21863eebcd
@ -172,57 +172,58 @@ class Animation {
|
||||
return ani_tag;
|
||||
}
|
||||
save() {
|
||||
if (isApp) {
|
||||
let content = {
|
||||
format_version: '1.8.0',
|
||||
animations: {
|
||||
[this.name]: this.compileBedrockAnimation()
|
||||
}
|
||||
}
|
||||
if (isApp && this.path && fs.existsSync(this.path)) {
|
||||
//overwrite path
|
||||
if (scope.mode === 'link') {
|
||||
var image = nativeImage.createFromPath(scope.source.replace(/\?\d+$/, '')).toPNG()
|
||||
} else {
|
||||
var image = nativeImage.createFromDataURL(scope.source).toPNG()
|
||||
}
|
||||
tex_version++;
|
||||
if (!as && this.path && fs.existsSync(this.path)) {
|
||||
fs.writeFile(this.path, image, function (err) {
|
||||
scope.fromPath(scope.path)
|
||||
})
|
||||
} else {
|
||||
var find_path;
|
||||
if (Format.bone_rig && Project.geometry_name) {
|
||||
find_path = BedrockEntityManager.findEntityTexture(Project.geometry_name, true)
|
||||
|
||||
let data;
|
||||
try {
|
||||
data = fs.readFileSync(this.path, 'utf-8');
|
||||
data = autoParseJSON(data, false);
|
||||
if (typeof data.animations !== 'object') {
|
||||
throw 'Incompatible format'
|
||||
}
|
||||
if (!find_path && ModelMeta.export_path) {
|
||||
var arr = ModelMeta.export_path.split(osfs);
|
||||
var index = arr.lastIndexOf('models');
|
||||
if (index > 1) arr.splice(index, 256, 'textures')
|
||||
if (scope.folder) arr = arr.concat(scope.folder.split('/'));
|
||||
arr.push(scope.name)
|
||||
find_path = arr.join(osfs)
|
||||
}
|
||||
Blockbench.export({
|
||||
resource_id: 'texture',
|
||||
type: 'PNG Texture',
|
||||
extensions: ['png'],
|
||||
name: scope.name,
|
||||
content: image,
|
||||
startpath: find_path,
|
||||
savetype: 'image'
|
||||
}, function(path) {
|
||||
scope.fromPath(path)
|
||||
|
||||
} catch (err) {
|
||||
data = null;
|
||||
var answer = ElecDialogs.showMessageBox(currentwindow, {
|
||||
type: 'warning',
|
||||
buttons: [
|
||||
tl('message.bedrock_overwrite_error.overwrite'),
|
||||
tl('dialog.cancel')
|
||||
],
|
||||
title: 'Blockbench',
|
||||
message: tl('message.bedrock_overwrite_error.message'),
|
||||
detail: err+'',
|
||||
noLink: false
|
||||
})
|
||||
if (answer === 1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (data) {
|
||||
let animation = content.animations[this.name];
|
||||
content = data;
|
||||
content.animations[this.name] = animation;
|
||||
}
|
||||
Blockbench.writeFile(this.path, {content: compileJSON(content)}, () => {
|
||||
this.saved = true;
|
||||
});
|
||||
|
||||
} else {
|
||||
//Download
|
||||
let content = {
|
||||
format_version: '1.8.0',
|
||||
animations: {
|
||||
[this.name]: this.compileBedrockAnimation()
|
||||
}
|
||||
}
|
||||
Blockbench.export({
|
||||
resource_id: 'animation',
|
||||
type: 'JSON Animation',
|
||||
extensions: ['json'],
|
||||
name: (Project.geometry_name||'model')+'.animation',
|
||||
startpath: path,
|
||||
startpath: this.path,
|
||||
content: compileJSON(content),
|
||||
}, () => {
|
||||
this.saved = true;
|
||||
@ -408,6 +409,14 @@ class Animation {
|
||||
animation.editUpdateVariable()
|
||||
}},
|
||||
'_',
|
||||
{
|
||||
name: 'menu.animation.save',
|
||||
id: 'save',
|
||||
icon: 'save',
|
||||
click(animation) {
|
||||
animation.save();
|
||||
}
|
||||
},
|
||||
'duplicate',
|
||||
'rename',
|
||||
'delete',
|
||||
@ -415,6 +424,20 @@ class Animation {
|
||||
new Property(Animation, 'boolean', 'saved', {default: true})
|
||||
new Property(Animation, 'string', 'path')
|
||||
|
||||
Blockbench.on('finish_edit', event => {
|
||||
if (event.aspects.animations && event.aspects.animations.length) {
|
||||
event.aspects.animations.forEach(animation => {
|
||||
animation.saved = false;
|
||||
})
|
||||
}
|
||||
if (event.aspects.keyframes && event.aspects.keyframes.length) {
|
||||
event.aspects.keyframes.forEach(kf => {
|
||||
if (kf.animator && kf.animator.animation) {
|
||||
kf.animator.animation.saved = false;
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
class GeneralAnimator {
|
||||
constructor(uuid, animation) {
|
||||
|
@ -497,7 +497,7 @@ const Timeline = {
|
||||
let new_time = (Animator.selected && Animator.selected.anim_time_update)
|
||||
? Molang.parse(Animator.selected.anim_time_update)
|
||||
: Timeline.time + (1/60);
|
||||
Timeline.setTime(new_time * (Timeline.playback_speed/100));
|
||||
Timeline.setTime(Timeline.time + (new_time - Timeline.time) * (Timeline.playback_speed/100));
|
||||
|
||||
} else {
|
||||
if (Animator.selected.loop == 'once') {
|
||||
|
@ -311,6 +311,15 @@ function setupPanels() {
|
||||
toggle(key) {
|
||||
this.files_folded[key] = !this.files_folded[key];
|
||||
this.$forceUpdate();
|
||||
},
|
||||
saveFile(key, file) {
|
||||
if (key && isApp) {
|
||||
file.animations.forEach(animation => {
|
||||
animation.save();
|
||||
})
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -320,8 +329,10 @@ function setupPanels() {
|
||||
let key = animation.path || '';
|
||||
if (!files[key]) files[key] = {
|
||||
animations: [],
|
||||
name: animation.path ? pathToName(animation.path, true) : 'Unsaved'
|
||||
name: animation.path ? pathToName(animation.path, true) : 'Unsaved',
|
||||
saved: true
|
||||
};
|
||||
if (!animation.saved) files[key].saved = false;
|
||||
files[key].animations.push(animation);
|
||||
})
|
||||
return files;
|
||||
@ -332,9 +343,12 @@ function setupPanels() {
|
||||
<div class="toolbar_wrapper animations"></div>
|
||||
<ul id="animations_list" class="list">
|
||||
<li v-for="(file, key) in files" :key="key" class="animation_file">
|
||||
<div class="animation_file_head" v-on:dblclick.stop="toggle(key)">
|
||||
<div class="animation_file_head" v-on:click.stop="toggle(key)">
|
||||
<i v-on:click.stop="toggle(key)" class="icon-open-state fa" :class=\'{"fa-angle-right": files_folded[key], "fa-angle-down": !files_folded[key]}\'></i>
|
||||
{{ file.name }}
|
||||
<div class="animation_file_save_button" v-if="!file.saved" v-on:click.stop="saveFile(key, file)">
|
||||
<i class="material-icons">save</i>
|
||||
</div>
|
||||
</div>
|
||||
<ul v-if="!files_folded[key]">
|
||||
<li
|
||||
|
@ -1098,6 +1098,7 @@
|
||||
"menu.animation.loop.loop": "Loop",
|
||||
"menu.animation.override": "Override",
|
||||
"menu.animation.anim_time_update": "Update Variable",
|
||||
"menu.animation.save": "Save",
|
||||
|
||||
"menu.keyframe.quaternion": "Quaternion",
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user