Fix issues with importing projects with same UUIDs

Improve error messages when trying to generate Box UV template with meshes
Fix font awesome icon display in messsage boxes
Fix area select not working ideally with Ctrl keybinding
This commit is contained in:
JannisX11 2022-01-28 21:56:48 +01:00
parent 5dac8ce0ad
commit d5ec1571af
5 changed files with 65 additions and 11 deletions

View File

@ -285,10 +285,13 @@
font-size: 40pt;
float: left;
padding-right: 8px;
height: 54px;
min-width: 61px;
max-height: 54px;
max-width: 62px;
}
.dialog .message_box_icon.fa {
font-size: 35pt;
}
.dialog img.message_box_icon {
min-width: auto;
}

View File

@ -338,6 +338,8 @@ var codec = new Codec('project', {
this.dispatchEvent('merge', {model})
Project.added_models++;
let uuid_map = {};
let tex_uuid_map = {};
let new_elements = [];
let new_textures = [];
let new_animations = [];
@ -363,8 +365,12 @@ var codec = new Codec('project', {
let height = model.resolution.height || Project.texture_height;
function loadTexture(tex) {
if (isApp && Texture.all.find(tex2 => tex.path == tex2.path)) {
return Texture.all.find(tex2 => tex.path == tex2.path)
if (isApp && Texture.all.find(tex2 => tex.path && tex.path == tex2.path)) {
return Texture.all.find(tex2 => tex.path && tex.path == tex2.path)
}
if (Texture.all.find(tex2 => tex2.uuid == tex.uuid)) {
tex_uuid_map[tex.uuid] = guid();
tex.uuid = tex_uuid_map[tex.uuid];
}
var tex_copy = new Texture(tex, tex.uuid).add(false);
if (isApp && tex.path && fs.existsSync(tex.path) && !model.meta.backup) {
@ -394,6 +400,11 @@ var codec = new Codec('project', {
model.elements.forEach(function(element) {
if (!OutlinerElement.isTypePermitted(element.type)) return;
if (Outliner.elements.find(el => el.uuid == element.uuid)) {
let uuid = guid();
uuid_map[element.uuid] = uuid;
element.uuid = uuid;
}
var copy = OutlinerElement.fromSave(element, true)
if (copy instanceof Cube) {
for (var face in copy.faces) {
@ -433,11 +444,41 @@ var codec = new Codec('project', {
})
}
if (model.outliner) {
// Handle existing UUIDs
function processList(list) {
list.forEach((node, i) => {
if (typeof node == 'string') {
// element
if (uuid_map[node]) {
list[i] = uuid_map[node];
}
} else if (node && node.uuid) {
// Group
if (Group.all.find(g => g.uuid == node.uuid)) {
node.uuid = uuid_map[node.uuid] = guid();
}
if (node.children) processList(node.children);
}
})
}
processList(model.outliner);
parseGroups(model.outliner, true);
}
if (model.animations && Format.animation_mode) {
model.animations.forEach(ani => {
var base_ani = new Animation()
var base_ani = new Animation();
if (Animation.all.find(a => a.uuid == ani.uuid)) {
ani.uuid = guid();
}
if (base_ani.animators) {
for (let key in animators) {
if (uuid_map[key]) {
animators[uuid_map[key]] = animators[key];
delete animators[key];
}
}
}
base_ani.uuid = ani.uuid;
base_ani.extend(ani).add();
new_animations.push(base_ani);

View File

@ -1081,7 +1081,8 @@ class Preview {
let vector = new THREE.Vector3();
let rect_start = [c.ax, c.ay];
let rect_end = [c.bx, c.by];
let extend_selection = (event.shiftKey || event.ctrlOrCmd || Pressing.overrides.ctrl || Pressing.overrides.shift)
let extend_selection = (event.shiftKey || Pressing.overrides.shift) ||
((event.ctrlOrCmd || Pressing.overrides.ctrl) && !Keybinds.extra.preview_area_select.keybind.ctrl)
let selection_mode = BarItems.selection_mode.value;
let widthHalf = 0.5 * scope.canvas.width / window.devicePixelRatio;

View File

@ -66,7 +66,8 @@ const TextureGenerator = {
results.resolution = results.resolution_vec;
}
dialog.hide()
TextureGenerator.addBitmap(results)
TextureGenerator.addBitmap(results);
return false;
}
}).show()
},
@ -109,9 +110,6 @@ const TextureGenerator = {
}
if (options.type == 'template') {
if (Project.box_uv || options.box_uv) {
if (Mesh.selected[0]) {
Blockbench.showQuickMessage('message.box_uv_for_meshes', 1600);
}
TextureGenerator.generateTemplate(options, makeTexture);
} else {
TextureGenerator.generateFaceTemplate(options, makeTexture);
@ -200,8 +198,19 @@ const TextureGenerator = {
}
//Cancel if no cubes
if (templates.length == 0) {
Blockbench.showMessage('message.no_valid_elements', 'center')
if (Mesh.selected.length) {
Blockbench.showMessageBox({
title: 'message.no_valid_elements',
message: 'message.meshes_and_box_uv',
icon: 'fa-gem'
})
} else {
Blockbench.showMessage('message.no_valid_elements', 'center');
}
return;
} else if (Mesh.selected.length) {
Blockbench.showMessage('message.meshes_and_box_uv', 'center');
}
templates.sort(function(a,b) {
return b.template_size - a.template_size;

View File

@ -266,7 +266,7 @@
"message.keymap_loaded": "Keymap loaded",
"message.no_animation_to_import": "No animations to import",
"message.copy_paste_tool_viewport": "This tool can only be used in the UV panel",
"message.box_uv_for_meshes": "Meshes cannot be used in box UV templates",
"message.meshes_and_box_uv": "Meshes are not compatible with Box UV. Go to File > Project... and switch to Per-face UV.",
"message.no_valid_elements": "No valid elements selected...",
"message.wireframe.enabled": "Wireframe view enabled",