darkness-dependent-vision/src/hooks/updateToken.js

19 lines
565 B
JavaScript

// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
export default function registerForUpdateTokenHook() {
Hooks.on('updateToken', onUpdateToken);
}
function onUpdateToken(token, change) {
const shouldUpdateVisionSource = [
'dimVisionDarknessMin',
'dimVisionDarknessMax',
'brightVisionDarknessMin',
'brightVisionDarknessMax',
].some((flagKey) => `flags.darkness-dependent-vision.${flagKey}` in foundry.utils.flattenObject(change));
if (shouldUpdateVisionSource) {
token.object.updateVisionSource();
}
}