Improve automatic animation loading

This commit is contained in:
JannisX11 2024-08-28 19:40:03 +02:00
parent ab0187faac
commit 13e0d08571
3 changed files with 35 additions and 6 deletions

View File

@ -170,6 +170,9 @@
.dialog_bar > .molang_input {
width: calc(100% - var(--max_label_width));
}
.dialog_bar.form_bar.small_text {
word-break: break-word;
}
/*.dialog_bar::after {
content: "";
clear: both;
@ -2079,6 +2082,15 @@
right: 0;
background: var(--color-back);
}
/* Animation import */
dialog#animation_import .form_bar__path {
padding: 2px;
color: var(--color-subtle_text);
overflow-x: auto;
white-space: nowrap;
text-align: right;
direction: rtl;
}
/* Texture Edit */
div.texture_adjust_previews {

View File

@ -26,7 +26,7 @@ const Animator = {
if (paths.length) {
Blockbench.read(paths, {}, files => {
files.forEach(file => {
Animator.importFile(file);
Animator.importFile(file, true);
})
})
}
@ -689,8 +689,11 @@ const Animator = {
animation_controllers: controllers
}
},
importFile(file) {
importFile(file, auto_loaded) {
let form = {};
if (auto_loaded && file.path) {
form['_path'] = {type: 'info', text: file.path};
}
let json = autoParseJSON(file.content)
let keys = [];
let is_controller = !!json.animation_controllers;
@ -707,7 +710,7 @@ const Animator = {
}
if (is_already_loaded) continue;
}
form[key.hashCode()] = {label: key, type: 'checkbox', value: true, nocolon: true};
form['anim' + key.hashCode()] = {label: key, type: 'checkbox', value: true, nocolon: true};
keys.push(key);
}
file.json = json;
@ -721,15 +724,21 @@ const Animator = {
} else {
return new Promise(resolve => {
let buttons = ['dialog.ok', 'dialog.ignore'];
if (auto_loaded && Project?.memory_animation_files_to_load?.length > 1) {
buttons.push('dialog.ignore_all');
}
let dialog = new Dialog({
id: 'animation_import',
title: 'dialog.animation_import.title',
form,
buttons,
cancelIndex: 1,
onConfirm(form_result) {
this.hide();
let names = [];
for (var key of keys) {
if (form_result[key.hashCode()]) {
if (form_result['anim' + key.hashCode()]) {
names.push(key);
}
}
@ -738,7 +747,14 @@ const Animator = {
Undo.finishEdit('Import animations', {animations: new_animations})
resolve();
},
onCancel() {
onCancel(index) {
Project.memory_animation_files_to_load.remove(file.path);
resolve();
},
onButton(index) {
if (auto_loaded && index == 2) {
Project.memory_animation_files_to_load.empty();
}
resolve();
}
});
@ -747,7 +763,7 @@ const Animator = {
buttons: ['generic.select_all', 'generic.select_none'],
click(index) {
let values = {};
keys.forEach(key => values[key.hashCode()] = (index == 0));
keys.forEach(key => values['anim' + key.hashCode()] = (index == 0));
dialog.setFormValues(values);
}
}

View File

@ -12,6 +12,7 @@
"dialog.discard": "Discard",
"dialog.continue": "Continue",
"dialog.ignore": "Ignore",
"dialog.ignore_all": "Ignore All",
"dialog.dontshowagain": "Don't Show Again",
"dialog.copy_to_clipboard": "Copy to clipboard",
"dialog.open_url": "Open URL",