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

20 lines
565 B
JavaScript
Raw Normal View History

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