Improvements to Import and delete animations

This commit is contained in:
JannisX11 2020-09-15 12:12:07 +02:00
parent 18107f62f3
commit ffa476145b
3 changed files with 73 additions and 25 deletions

View File

@ -382,7 +382,25 @@ class Animation {
}
Animator.animations.remove(this)
if (undo) {
Undo.finishEdit('remove animation', {animation: null})
Undo.finishEdit('remove animation', {animations: []})
if (isApp && this.path && fs.existsSync(this.path)) {
Blockbench.showMessageBox({
translateKey: 'delete_animation',
icon: 'movie',
buttons: ['generic.delete', 'dialog.cancel']
}, (result) => {
if (result == 0) {
let content = fs.readFileSync(this.path, 'utf-8');
let json = autoParseJSON(content, false);
if (json && json.animations && json.animations[this.name]) {
delete json.animations[this.name];
Blockbench.writeFile(this.path, {content: compileJSON(json)});
Undo.history.last().before.animations[this.uuid].saved = false
}
}
})
}
}
Blockbench.dispatchEvent('remove_animation', {animations: [this]})
return this;
@ -532,6 +550,15 @@ class Animation {
animation.save();
}
},
{
name: 'menu.animation.open_location',
id: 'open_location',
icon: 'folder',
condition(animation) {return isApp && animation.path && fs.existsSync(animation.path)},
click(animation) {
shell.showItemInFolder(animation.path);
}
},
'duplicate',
'delete',
'_',
@ -1138,6 +1165,7 @@ const Animator = {
loadFile(file, animation_filter) {
var json = file.json || autoParseJSON(file.content);
let path = file.path;
let new_animations = [];
if (json && typeof json.animations === 'object') {
for (var ani_name in json.animations) {
if (animation_filter && !animation_filter.includes(ani_name)) continue;
@ -1236,8 +1264,10 @@ const Animator = {
if (!Animator.selected) {
animation.select()
}
new_animations.push(animation)
}
}
return new_animations
},
buildFile(options) {
if (typeof options !== 'object') {
@ -1252,6 +1282,39 @@ const Animator = {
format_version: '1.8.0',
animations: animations
}
},
importFile(file) {
let form = {};
let json = autoParseJSON(file.content)
for (var key in json.animations) {
form[key.hashCode()] = {label: key, type: 'checkbox', value: true}
}
file.json = json;
if (Object.keys(json.animations) <= 1) {
Undo.initEdit({animations: []})
let new_animations = Animator.loadFile(file);
Undo.finishEdit('import animations', {animations: new_animations})
return;
}
console.log(form)
let dialog = new Dialog({
id: 'animation_import',
title: 'dialog.animation_import.title',
form,
onConfirm(form_result) {
dialog.hide();
let names = [];
for (var key in json.animations) {
if (form_result[key.hashCode()]) {
names.push(key);
}
}
Undo.initEdit({animations: []})
let new_animations = Animator.loadFile(file, names);
Undo.finishEdit('import animations', {animations: new_animations})
}
})
dialog.show();
}
}
@ -1288,7 +1351,8 @@ Blockbench.addDragHandler('animation', {
readtype: 'text',
condition: {modes: ['animate']},
}, function(files) {
Animator.loadFile(files[0])
console.log(files)
Animator.importFile(files[0])
})
BARS.defineActions(function() {
@ -1322,7 +1386,7 @@ BARS.defineActions(function() {
type: 'JSON Animation',
startpath: path
}, function(files) {
Animator.loadFile(files[0])
Animator.importFile(files[0])
})
}
})

View File

@ -4,27 +4,6 @@ const Outliner = {
elements: elements,
selected: selected,
buttons: {
/*
remove: {
id: 'remove',
title: tl('generic.delete'),
icon: ' fa fa-times',
icon_off: ' fa fa-times',
advanced_option: false,
click: function(obj) {
if (obj.type === 'group') {
obj.remove(true);
return;
}
Undo.initEdit({elements: obj.forSelected(), outliner: true, selection: true})
obj.forSelected().slice().forEach(cube => {
cube.remove();
})
updateSelection()
Undo.finishEdit('remove', {elements: [], outliner: true, selection: true})
}
},
*/
visibility: {
id: 'visibility',
title: tl('switches.visibility'),

View File

@ -177,6 +177,9 @@
"message.image_editor_missing.title": "Default Image Editor",
"message.image_editor_missing.message": "Select the executable file of your image editor.",
"message.image_editor_missing.detail": "Blockbench couldn't find an image editor on your computer. Select the executable file of your preferred image editor.",
"message.delete_animation.title": "Delete Animation",
"message.delete_animation.message": "The animation was removed from Blockbench. Do you also want to delete the animation from the file that is was saved in?",
"message.display_skin.title": "Display Skin",
"message.display_skin.message": "Select a skin file from your computer or enter a player name",
@ -246,7 +249,6 @@
"dialog.texture.variable": "Variable",
"dialog.texture.namespace": "Namespace",
"dialog.texture.folder": "Folder",
"dialog.resize_texture.fill": "Fill with",
"dialog.resize_texture.fill.transparent": "Transparent",
@ -304,6 +306,8 @@
"dialog.entitylist.text": "Select the model you want to import",
"dialog.entitylist.bones": "Bones",
"dialog.entitylist.cubes": "Cubes",
"dialog.animation_import.title": "Select Animations to Import",
"dialog.create_texture.folder": "Folder",
"dialog.create_texture.template": "Template",
@ -1103,6 +1107,7 @@
"menu.animation.properties": "Properties...",
"menu.animation.file": "File",
"menu.animation.snapping": "Snapping",
"menu.animation.open_location": "Open File Location",
"menu.keyframe.quaternion": "Quaternion",