20 lines
547 B
JavaScript
20 lines
547 B
JavaScript
|
// 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();
|
||
|
}
|
||
|
}
|