mirror of
https://github.com/JannisX11/blockbench.git
synced 2024-11-21 01:13:37 +08:00
Add "onUpdateTo Version" system
This commit is contained in:
parent
7e64a11848
commit
8ca8351729
14
js/api.js
14
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) {
|
||||
|
@ -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 = {}) {
|
||||
|
@ -105,6 +105,8 @@ if (isApp) {
|
||||
initializeWebApp();
|
||||
}
|
||||
|
||||
localStorage.setItem('last_version', Blockbench.version);
|
||||
|
||||
Modes.options.start.select()
|
||||
|
||||
loadInstalledPlugins().then(plugins => {
|
||||
|
@ -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: [
|
||||
|
@ -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() {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user