Add "onUpdateTo Version" system

This commit is contained in:
JannisX11 2021-01-23 23:24:14 +01:00
parent 7e64a11848
commit 8ca8351729
5 changed files with 64 additions and 53 deletions

View File

@ -1,3 +1,5 @@
const LastVersion = localStorage.getItem('last_version') || localStorage.getItem('welcomed_version') || appVersion;
const Blockbench = {
isWeb: !isApp,
isMobile: !isApp && window.innerWidth <= 640,
@ -307,14 +309,20 @@ const Blockbench = {
if (!this.events[event_name]) return;
this.events[event_name].remove(cb);
},
onUpdateTo(version, callback) {
if (version.split('.').length == 2) {
version += '.999'
}
if (compareVersions(version, LastVersion) && !Blockbench.isOlderThan(version)) {
callback(LastVersion);
}
}
};
(function() {
var last_welcome = localStorage.getItem('welcomed_version');
if (!last_welcome || last_welcome.replace(/.\d+$/, '') != appVersion.replace(/.\d+$/, '')) {
if (!LastVersion || LastVersion.replace(/.\d+$/, '') != appVersion.replace(/.\d+$/, '')) {
Blockbench.addFlag('after_update');
}
localStorage.setItem('welcomed_version', appVersion);
})();
if (isApp) {

View File

@ -91,53 +91,6 @@ function updateNslideValues() {
BarItems.animated_texture_frame.update();
}
}
function setProjectResolution(width, height, modify_uv) {
if (Project.texture_width / width != Project.texture_width / height) {
modify_uv = false;
}
Undo.initEdit({uv_mode: true, elements: Cube.all, uv_only: true})
let old_res = {
x: Project.texture_width,
y: Project.texture_height
}
Project.texture_width = width;
Project.texture_height = height;
if (modify_uv) {
var multiplier = [
Project.texture_width/old_res.x,
Project.texture_height/old_res.y
]
function shiftCube(cube, axis) {
if (Project.box_uv) {
cube.uv_offset[axis] *= multiplier[axis];
} else {
for (var face in cube.faces) {
var uv = cube.faces[face];
uv[axis] *= multiplier[axis];
uv[axis+2] *= multiplier[axis];
}
}
}
if (old_res.x != Project.texture_width && Math.areMultiples(old_res.x, Project.texture_width)) {
Cube.all.forEach(cube => shiftCube(cube, 0));
}
if (old_res.y != Project.texture_height && Math.areMultiples(old_res.x, Project.texture_width)) {
Cube.all.forEach(cube => shiftCube(cube, 1));
}
}
Undo.finishEdit('Changed project resolution')
Canvas.updateAllUVs()
if (selected.length) {
main_uv.loadData()
}
}
function updateProjectResolution() {
$('#project_resolution_status').text(`${Project.texture_width}${Project.texture_height}`);
}
//Selections
function updateSelection(options = {}) {

View File

@ -105,6 +105,8 @@ if (isApp) {
initializeWebApp();
}
localStorage.setItem('last_version', Blockbench.version);
Modes.options.start.select()
loadInstalledPlugins().then(plugins => {

View File

@ -1750,10 +1750,9 @@ const BARS = {
'lock_motion_trail'
]
})
// update 3.7
if (!Toolbars.main_tools.children.includes(BarItems.lock_motion_trail)) {
Blockbench.onUpdateTo('3.5', () => {
Toolbars.main_tools.add(BarItems.lock_motion_trail, -1)
}
})
Toolbars.brush = new Toolbar({
id: 'brush',
children: [

View File

@ -160,6 +160,55 @@ function newProject(format, force) {
}
}
// Resolution
function setProjectResolution(width, height, modify_uv) {
if (Project.texture_width / width != Project.texture_width / height) {
modify_uv = false;
}
Undo.initEdit({uv_mode: true, elements: Cube.all, uv_only: true})
let old_res = {
x: Project.texture_width,
y: Project.texture_height
}
Project.texture_width = width;
Project.texture_height = height;
if (modify_uv) {
var multiplier = [
Project.texture_width/old_res.x,
Project.texture_height/old_res.y
]
function shiftCube(cube, axis) {
if (Project.box_uv) {
cube.uv_offset[axis] *= multiplier[axis];
} else {
for (var face in cube.faces) {
var uv = cube.faces[face];
uv[axis] *= multiplier[axis];
uv[axis+2] *= multiplier[axis];
}
}
}
if (old_res.x != Project.texture_width && Math.areMultiples(old_res.x, Project.texture_width)) {
Cube.all.forEach(cube => shiftCube(cube, 0));
}
if (old_res.y != Project.texture_height && Math.areMultiples(old_res.x, Project.texture_width)) {
Cube.all.forEach(cube => shiftCube(cube, 1));
}
}
Undo.finishEdit('Changed project resolution')
Canvas.updateAllUVs()
if (selected.length) {
main_uv.loadData()
}
}
function updateProjectResolution() {
document.querySelector('#project_resolution_status').textContent = `${Project.texture_width}${Project.texture_height}`;
}
BARS.defineActions(function() {