From 5d11899da40e7d2cab6c91078518fb6e05d44923 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Mon, 12 Oct 2020 14:30:30 +0200 Subject: [PATCH] Fix saving animation over other file not merging Fix deleting keyframes not marking animation as unsaved --- js/animations/animation.js | 87 ++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 37 deletions(-) diff --git a/js/animations/animation.js b/js/animations/animation.js index 54cc1b62..368f9616 100644 --- a/js/animations/animation.js +++ b/js/animations/animation.js @@ -184,52 +184,69 @@ class Animation { return ani_tag; } save() { + if (isApp && !this.path) { + Blockbench.export({ + resource_id: 'animation', + type: 'JSON Animation', + extensions: ['json'], + name: (Project.geometry_name||'model')+'.animation', + startpath: this.path, + custom_writer: (content, path) => { + if (!path) return + this.path = path; + this.save(); + } + }) + return; + } let content = { format_version: '1.8.0', animations: { [this.name]: this.compileBedrockAnimation() } } - if (isApp && this.path && fs.existsSync(this.path)) { - //overwrite path - let data; - try { - data = fs.readFileSync(this.path, 'utf-8'); - data = autoParseJSON(data, false); - if (typeof data.animations !== 'object') { - throw 'Incompatible format' - } + if (isApp && this.path) { + if (fs.existsSync(this.path)) { + //overwrite path + let data; + try { + data = fs.readFileSync(this.path, 'utf-8'); + data = autoParseJSON(data, false); + if (typeof data.animations !== 'object') { + throw 'Incompatible format' + } - } 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; + } 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; } } - - if (data) { - let animation = content.animations[this.name]; - content = data; - content.animations[this.name] = animation; - } + // Write Blockbench.writeFile(this.path, {content: compileJSON(content)}, (real_path) => { this.saved = true; this.path = real_path; }); } else { - //Download + // Web Download Blockbench.export({ resource_id: 'animation', type: 'JSON Animation', @@ -568,12 +585,8 @@ Blockbench.on('finish_edit', event => { 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; - } - }) + if (event.aspects.keyframes && event.aspects.keyframes instanceof Array && Animation.selected) { + Animation.selected.saved = false; } })