Fix #2592 Fit to frame property in bedrock display settings is not supported

Bedrock display settings now only export modified slots
This commit is contained in:
JannisX11 2024-12-23 00:18:09 +01:00
parent 3e37689c16
commit 90f210c1c2
3 changed files with 55 additions and 13 deletions

View File

@ -9,6 +9,7 @@ const DisplayMode = {};
class DisplaySlot {
constructor(id, data) {
this.slot_id = id;
this.default()
if (data) this.extend(data)
}
@ -19,6 +20,7 @@ class DisplaySlot {
this.rotation_pivot = [0, 0, 0];
this.scale_pivot = [0, 0, 0];
this.mirror = [false, false, false]
this.fit_to_frame = false;
return this;
}
copy() {
@ -51,6 +53,32 @@ class DisplaySlot {
return build;
}
}
exportBedrock() {
let has_data = !this.rotation.allEqual(0)
|| !this.translation.allEqual(0)
|| !this.scale.allEqual(1)
|| !this.mirror.allEqual(false)
|| !this.rotation_pivot.allEqual(0)
|| !this.scale_pivot.allEqual(0);
if (!has_data) return;
let build = {
rotation: this.rotation.slice(),
translation: this.translation.slice(),
scale: this.scale.slice(),
rotation_pivot: this.rotation_pivot,
scale_pivot: this.scale_pivot,
}
if (this.slot_id == 'gui') {
build.fit_to_frame = this.fit_to_frame;
}
if (!this.mirror.allEqual(false)) {
for (let i = 0; i < 3; i++) {
build.scale[i] *= this.mirror[i] ? -1 : 1;
}
}
return build;
}
extend(data) {
if (!data) return this;
for (var i = 0; i < 3; i++) {
@ -63,6 +91,7 @@ class DisplaySlot {
this.scale[i] = Math.abs(this.scale[i])
if (data.scale && data.scale[i] < 0) this.mirror[i] = true;
}
if (typeof data.fit_to_frame == 'boolean') this.fit_to_frame = data.fit_to_frame;
this.update()
return this;
}
@ -1419,7 +1448,7 @@ DisplayMode.applyPreset = function(preset, all) {
Undo.initEdit({display_slots: slots})
slots.forEach(function(sl) {
if (!Project.display_settings[sl]) {
Project.display_settings[sl] = new DisplaySlot()
Project.display_settings[sl] = new DisplaySlot(sl)
}
let preset_values = preset.areas[sl];
if (preset_values) {
@ -1437,7 +1466,7 @@ DisplayMode.applyPreset = function(preset, all) {
DisplayMode.loadJSON = function(data) {
for (var slot in data) {
if (displayReferenceObjects.slots.includes(slot)) {
Project.display_settings[slot] = new DisplaySlot().extend(data[slot])
Project.display_settings[slot] = new DisplaySlot(slot).extend(data[slot])
}
}
}
@ -1498,7 +1527,7 @@ function loadDisp(key) { //Loads The Menu and slider values, common for all Radi
display_preview.camPers.setFocalLength(45)
if (Project.display_settings[key] == undefined) {
Project.display_settings[key] = new DisplaySlot()
Project.display_settings[key] = new DisplaySlot(key)
}
display_preview.force_locked_angle = false;
DisplayMode.vue._data.slot = Project.display_settings[key]
@ -1919,7 +1948,7 @@ Interface.definePanels(function() {
axes: [0, 1, 2],
reference_model: 'player',
pose_angle: 0,
slot: new DisplaySlot(),
slot: new DisplaySlot(''),
allow_mirroring: Settings.get('allow_display_slot_mirror')
}},
watch: {
@ -1987,14 +2016,20 @@ Interface.definePanels(function() {
DisplayMode.slot.update()
Undo.finishEdit('Mirror display setting')
},
start: (axis, channel) => {
start: () => {
Undo.initEdit({display_slots: [display_slot]});
Interface.addSuggestedModifierKey('shift', 'modifier_actions.uniform_scaling');
},
save: (axis, channel) => {
save: () => {
Undo.finishEdit('Change display setting');
Interface.removeSuggestedModifierKey('shift', 'modifier_actions.uniform_scaling');
},
toggleFitToFrame() {
Undo.initEdit({display_slots: [display_slot]});
this.slot.fit_to_frame = !this.slot.fit_to_frame;
Undo.finishEdit('Change display setting fit-to-frame property');
Interface.removeSuggestedModifierKey('shift', 'modifier_actions.uniform_scaling');
},
showMirroringSetting() {
Settings.openDialog({search_term: tl('settings.allow_display_slot_mirror')});
},
@ -2074,6 +2109,10 @@ Interface.definePanels(function() {
value="0" @input="change(axis, 'scale')" @mousedown="start(axis, 'scale')" @change="save(axis, 'scale')">
<numeric-input class="tool disp_text" v-model.number="slot.scale[axis]" :min="0" :max="4" :step="0.01" @input="change(axis, 'scale')" @focusout="focusout(axis, 'scale');save()" @mousedown="start()" />
</div>
<div class="bar" v-if="isBedrockStyle() && slot.slot_id == 'gui'" @click="toggleFitToFrame()">
<input type="checkbox" :checked="slot.fit_to_frame == true">
<label style="padding-top: 3px;">Fit to Frame</label>
</div>
<template v-if="reference_model == 'player'">
<div class="bar display_slot_section_bar">

View File

@ -718,6 +718,11 @@ function calculateVisibleBox() {
if (data.object.item_display_transforms !== undefined) {
DisplayMode.loadJSON(data.object.item_display_transforms)
if (data.object.item_display_transforms.gui) {
if (data.object.item_display_transforms.gui.fit_to_frame == undefined) {
Project.display_settings.gui.fit_to_frame = true;
}
}
}
var bones = {}
@ -1033,7 +1038,6 @@ let entity_file_codec = new Codec('bedrock_entity_file', {
function getFormatVersion() {
if (Format.display_mode) {
let has_new_displays = false;
for (let i in DisplayMode.slots) {
let key = DisplayMode.slots[i]
if (Project.display_settings[key] && Project.display_settings[key].export) {
@ -1150,15 +1154,14 @@ var codec = new Codec('bedrock', {
}
let new_display = {};
let has_new_displays = false;
for (let i in DisplayMode.slots) {
let key = DisplayMode.slots[i]
if (Project.display_settings[key] && Project.display_settings[key].export) {
new_display[key] = Project.display_settings[key].export();
if (new_display[key]) has_new_displays = true;
if (Project.display_settings[key] && Project.display_settings[key].exportBedrock) {
let data = Project.display_settings[key].exportBedrock();
if (data) new_display[key] = data;
}
}
if (has_new_displays) {
if (Object.keys(new_display).length) {
entitymodel.item_display_transforms = new_display
}

View File

@ -520,7 +520,7 @@ class UndoSystem {
let data = save.display_slots[slot]
if (!Project.display_settings[slot] && data) {
Project.display_settings[slot] = new DisplaySlot()
Project.display_settings[slot] = new DisplaySlot(slot)
} else if (data === null && Project.display_settings[slot]) {
Project.display_settings[slot].default()
}