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

20 lines
547 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) {
const shouldUpdateSource = [
'dimVisionDarknessMin',
'dimVisionDarknessMax',
'brightVisionDarknessMin',
'brightVisionDarknessMax',
].some((flagKey) => `flags.darkness-dependent-vision.${flagKey}` in foundry.utils.flattenObject(change));
if (shouldUpdateSource) {
token.object.updateSource();
}
}