Skip to content

Commit

Permalink
v9 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
unsoluble committed Sep 30, 2021
1 parent 20dbdbb commit 791d76a
Showing 1 changed file with 44 additions and 17 deletions.
61 changes: 44 additions & 17 deletions scripts/quickscale.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,26 +428,53 @@ async function updateSize(key, largeStep) {
// Update hovered light.
const hoveredLight = canvas.lighting._hover?.document;
if (hoveredLight) {
const currentDim = hoveredLight.data.dim;
const currentBright = hoveredLight.data.bright;
let newBright = Math.ceil(currentBright - 5);
if (largeStep) {
if (Math.ceil(currentDim - 5) > 0 && newBright < 0) {
newBright = 0;
// Two different data paths for v8 and v9.
if (isNewerVersion(game.data.version, '9')) {
let currentDim = hoveredLight.data.config.dim;
let currentBright = hoveredLight.data.config.bright;

let newBright = Math.ceil(currentBright - 5);
if (largeStep) {
if (Math.ceil(currentDim - 5) > 0 && newBright < 0) {
newBright = 0;
}
await hoveredLight.update({
'config.dim': increase ? Math.floor(currentDim + 5) : Math.ceil(currentDim - 5),
'config.bright': increase ? Math.floor(currentBright + 5) : newBright,
});
} else {
newBright = Math.ceil(currentBright - 1);
if (Math.ceil(currentDim - 1) > 0 && newBright < 0) {
newBright = 0;
}
await hoveredLight.update({
'config.dim': increase ? Math.floor(currentDim + 1) : Math.ceil(currentDim - 1),
'config.bright': increase ? Math.floor(currentBright + 1) : newBright,
});
}
await hoveredLight.update({
dim: increase ? Math.floor(currentDim + 5) : Math.ceil(currentDim - 5),
bright: increase ? Math.floor(currentBright + 5) : newBright,
});
} else {
newBright = Math.ceil(currentBright - 1);
if (Math.ceil(currentDim - 1) > 0 && newBright < 0) {
newBright = 0;
let currentDim = hoveredLight.data.dim;
let currentBright = hoveredLight.data.bright;

let newBright = Math.ceil(currentBright - 5);
if (largeStep) {
if (Math.ceil(currentDim - 5) > 0 && newBright < 0) {
newBright = 0;
}
await hoveredLight.update({
dim: increase ? Math.floor(currentDim + 5) : Math.ceil(currentDim - 5),
bright: increase ? Math.floor(currentBright + 5) : newBright,
});
} else {
newBright = Math.ceil(currentBright - 1);
if (Math.ceil(currentDim - 1) > 0 && newBright < 0) {
newBright = 0;
}
await hoveredLight.update({
dim: increase ? Math.floor(currentDim + 1) : Math.ceil(currentDim - 1),
bright: increase ? Math.floor(currentBright + 1) : newBright,
});
}
await hoveredLight.update({
dim: increase ? Math.floor(currentDim + 1) : Math.ceil(currentDim - 1),
bright: increase ? Math.floor(currentBright + 1) : newBright,
});
}
}

Expand Down

0 comments on commit 791d76a

Please sign in to comment.