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

33 lines
1 KiB
JavaScript
Raw Normal View History

2021-06-29 20:40:54 +02:00
// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
import { packageName } from '../config';
import logger from '../logger';
import { libWrapper } from '../shims/libWrapperShim';
import { getBrightRadius, getDimRadius, updateSource } from '../wrappers/token';
export default function registerForInitHook() {
Hooks.on('init', onInit);
}
function onInit() {
logger.info(`Initializing ${packageName}`);
const dimRadiusTarget = 'Token.prototype.dimRadius';
try {
libWrapper.register(packageName, dimRadiusTarget, getDimRadius, 'OVERRIDE');
} catch (e) {
logger.warn(`Failed to override ${dimRadiusTarget}, some things might not work correctly:`, e);
}
const brightRadiusTarget = 'Token.prototype.dimRadius';
try {
libWrapper.register(packageName, brightRadiusTarget, getBrightRadius, 'OVERRIDE');
} catch (e) {
logger.warn(`Failed to override ${brightRadiusTarget}, some things might not work correctly:`, e);
}
libWrapper.register(packageName, 'Token.prototype.updateSource', updateSource, 'WRAPPER');
}