From 8ca83517293f8562d7c3a7e8de05c1a6a2437ad0 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Sat, 23 Jan 2021 23:24:14 +0100 Subject: [PATCH] Add "onUpdateTo Version" system --- js/api.js | 14 +++++++++--- js/blockbench.js | 47 --------------------------------------- js/boot_loader.js | 2 ++ js/interface/actions.js | 5 ++--- js/io/project.js | 49 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 53 deletions(-) diff --git a/js/api.js b/js/api.js index fbdbe74e..18570324 100644 --- a/js/api.js +++ b/js/api.js @@ -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) { diff --git a/js/blockbench.js b/js/blockbench.js index 8db91a72..f5bcf6cb 100644 --- a/js/blockbench.js +++ b/js/blockbench.js @@ -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 = {}) { diff --git a/js/boot_loader.js b/js/boot_loader.js index ab1f8877..987415b1 100644 --- a/js/boot_loader.js +++ b/js/boot_loader.js @@ -105,6 +105,8 @@ if (isApp) { initializeWebApp(); } +localStorage.setItem('last_version', Blockbench.version); + Modes.options.start.select() loadInstalledPlugins().then(plugins => { diff --git a/js/interface/actions.js b/js/interface/actions.js index e7f8bbbc..72e2f76b 100644 --- a/js/interface/actions.js +++ b/js/interface/actions.js @@ -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: [ diff --git a/js/io/project.js b/js/io/project.js index 72a7ba07..b7baf4c1 100644 --- a/js/io/project.js +++ b/js/io/project.js @@ -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() {