2023-10-20 02:34:07 +02:00
|
|
|
import { SYSTEM_RDD } from "../constants.js";
|
|
|
|
|
|
|
|
export const AUTO_ADJUST_DARKNESS = "auto-adjust-darkness";
|
|
|
|
|
|
|
|
export class AutoAdjustDarkness {
|
|
|
|
|
2024-10-14 03:46:09 +02:00
|
|
|
static initSettings() {
|
2023-10-20 02:34:07 +02:00
|
|
|
game.settings.register(SYSTEM_RDD, AUTO_ADJUST_DARKNESS, {
|
|
|
|
name: AUTO_ADJUST_DARKNESS,
|
|
|
|
scope: "world",
|
|
|
|
config: false,
|
|
|
|
default: true,
|
|
|
|
type: Boolean
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static async adjust(darkness) {
|
2024-11-08 01:52:19 +01:00
|
|
|
if (game.user.isGM && AutoAdjustDarkness.isAuto()) {
|
2023-10-20 02:34:07 +02:00
|
|
|
const scene = game.scenes.viewed;
|
2024-06-07 11:12:00 +02:00
|
|
|
if (scene?.environment?.globalLight?.enabled && scene?.tokenVision) {
|
2023-10-20 02:34:07 +02:00
|
|
|
await scene.update({ darkness });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static isAuto() {
|
|
|
|
return game.settings.get(SYSTEM_RDD, AUTO_ADJUST_DARKNESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static async toggle() {
|
|
|
|
const previous = AutoAdjustDarkness.isAuto();
|
|
|
|
await game.settings.set(SYSTEM_RDD, AUTO_ADJUST_DARKNESS, !previous)
|
|
|
|
}
|
|
|
|
}
|