Fix issue with NaNs when offsetting keyframes

Improve molang syntax highlighting
Prevent animations from being imported twice
Set default cancel button in MessageBox to last button
This commit is contained in:
JannisX11 2020-09-29 17:14:26 +02:00
parent 91a2d83afd
commit 2bc836d72c
10 changed files with 64 additions and 36 deletions

View File

@ -579,6 +579,9 @@
.molang_input pre .token.selector {
color: #92dcff;
}
.molang_input pre .string {
color: #e8df6a;
}

View File

@ -192,7 +192,6 @@ class Animation {
}
if (isApp && this.path && fs.existsSync(this.path)) {
//overwrite path
let data;
try {
data = fs.readFileSync(this.path, 'utf-8');
@ -224,8 +223,9 @@ class Animation {
content = data;
content.animations[this.name] = animation;
}
Blockbench.writeFile(this.path, {content: compileJSON(content)}, () => {
Blockbench.writeFile(this.path, {content: compileJSON(content)}, (real_path) => {
this.saved = true;
this.path = real_path;
});
} else {
@ -372,7 +372,9 @@ class Animation {
Blockbench.showMessageBox({
translateKey: 'delete_animation',
icon: 'movie',
buttons: ['generic.delete', 'dialog.cancel']
buttons: ['generic.delete', 'dialog.cancel'],
confirm: 0,
cancel: 1,
}, (result) => {
if (result == 0) {
let content = fs.readFileSync(this.path, 'utf-8');
@ -740,7 +742,6 @@ class BoneAnimator extends GeneralAnimator {
Blockbench.showMessageBox({
translateKey: 'duplicate_groups',
icon: 'folder',
buttons: ['dialog.ok'],
});
}
super.select();
@ -1305,34 +1306,53 @@ const Animator = {
importFile(file) {
let form = {};
let json = autoParseJSON(file.content)
let keys = [];
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;
}
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);
console.log(key)
// Test if already loaded
if (isApp && file.path) {
let is_already_loaded = false
for (var anim of Animation.all) {
if (anim.path == file.path && anim.name == key) {
is_already_loaded = true;
break;
}
}
Undo.initEdit({animations: []})
let new_animations = Animator.loadFile(file, names);
Undo.finishEdit('import animations', {animations: new_animations})
if (is_already_loaded) {console.log(`${key} already exists`);continue;}
}
})
dialog.show();
form[key.hashCode()] = {label: key, type: 'checkbox', value: true};
keys.push(key);
}
console.log(keys.join(', '))
file.json = json;
if (keys.length == 0) {
Blockbench.showQuickMessage('message.no_animation_to_import');
} else if (keys.length == 1) {
Undo.initEdit({animations: []})
let new_animations = Animator.loadFile(file, keys);
Undo.finishEdit('import animations', {animations: new_animations})
} else {
let dialog = new Dialog({
id: 'animation_import',
title: 'dialog.animation_import.title',
form,
onConfirm(form_result) {
dialog.hide();
let names = [];
for (var key of keys) {
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();
}
},
exportAnimationFile(path) {
let filter_path = path || '';

View File

@ -114,7 +114,7 @@ class Keyframe {
this.set(axis, value+amount, data_point)
return value+amount
}
var start = value.match(/^-?\s*\d*(\.\d+)?\s*(\+|-)/)
var start = value.match(/^-?\s*\d+(\.\d+)?\s*(\+|-)/)
if (start) {
var number = parseFloat( start[0].substr(0, start[0].length-1) ) + amount
value = trimFloatNumber(number) + value.substr(start[0].length-1)

View File

@ -145,7 +145,7 @@ const Blockbench = {
showMessageBox(options, cb) {
if (options.confirm === undefined) options.confirm = 0
if (options.cancel === undefined) options.cancel = 0
if (options.cancel === undefined) options.cancel = options?.buttons?.length ? options.buttons.length-1 : 0;
if (!options.buttons) options.buttons = [tl('dialog.ok')]
if (options.translateKey) {

View File

@ -84,7 +84,6 @@ const EditSession = {
Blockbench.showMessageBox({
translateKey: 'invalid_session',
icon: 'cloud_off',
buttons: [tl('dialog.ok')],
}, result => {
showDialog('edit_sessions');
})
@ -98,7 +97,6 @@ const EditSession = {
Blockbench.showMessageBox({
translateKey: 'invalid_session',
icon: 'cloud_off',
buttons: [tl('dialog.ok')],
})
EditSession.quit()
})

View File

@ -156,7 +156,9 @@ var codec = new Codec('java_block', {
translateKey: 'model_clipping',
icon: 'settings_overscan',
message: tl('message.model_clipping.message', [overflow_cubes.length]),
buttons: ['dialog.scale.select_overflow', 'dialog.ok']
buttons: ['dialog.scale.select_overflow', 'dialog.ok'],
confirm: 1,
cancel: 1,
}, (result) => {
if (result == 0) {
selected.splice(0, Infinity, ...overflow_cubes)

View File

@ -884,7 +884,9 @@ class Preview {
Blockbench.showMessageBox({
translateKey: 'drag_background',
icon: 'open_with',
buttons: ['dialog.ok', 'dialog.dontshowagain']
buttons: ['dialog.ok', 'dialog.dontshowagain'],
confirm: 0,
cancel: 0,
}, function(r) {
if (r === 1) {
settings.dialog_drag_background.value = false

View File

@ -1520,7 +1520,9 @@ BARS.defineActions(function() {
title: tl('message.cleared_blank_faces.title'),
icon: 'rotate_right',
message: tl('message.cleared_blank_faces.message', [empty_cubes.length]),
buttons: ['generic.remove', 'dialog.cancel']
buttons: ['generic.remove', 'dialog.cancel'],
confirm: 0,
cancel: 1,
}, function(r) {
empty_cubes.forEach(cube => {
if (r == 0) {

View File

@ -213,6 +213,7 @@
"message.add_to_palette": "Added to palette",
"message.size_modifiers": "Hold down Ctrl or Shift to transform in smaller increments.",
"message.reset_keybindings": "Are you sure you want to reset all keybindings?",
"message.no_animation_to_import": "No animations to import",
"message.wireframe.enabled": "Wireframe view enabled",
"message.wireframe.disabled": "Wireframe view disabled",

View File

@ -4,7 +4,7 @@ Prism.languages.molang = {
'selector': /\b(?!\d)(query|variable|temp|math)\.\w+/i,
'boolean': /\b(?:true|false)\b/i,
'number': /(?:\b\d+(?:\.\d+)?(?:[ed][+-]\d+)?|&h[a-f\d]+)\b[%&!#]?/i,
'operator': /--|\+\+|>>=?|<<=?|<>|[-+*/\\<>]=?|[:^=?]|\b(?:and|mod|not|or)\b/i,
'operator': /&&|\|\||[-+*/!<>]=?|[:?=]/i,
'keyword': /\b(Return)\b/i,
'punctuation': /[.,;()[\]{}]/,
};