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

43 lines
1.4 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 registerHandlebarsPartials from '../handlebars-partials';
2021-06-29 20:40:54 +02:00
import logger from '../logger';
import registerSettings from '../setiings';
2021-06-29 20:40:54 +02:00
import { libWrapper } from '../shims/libWrapperShim';
2021-12-04 12:06:03 +01:00
import { getBrightRadius, getDimRadius, updateVisionSource } from '../wrappers/token';
2021-06-29 20:40:54 +02:00
export default function registerForInitHook() {
Hooks.on('init', onInit);
}
async function onInit() {
2021-06-29 20:40:54 +02:00
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);
}
2021-06-29 22:12:03 +02:00
const brightRadiusTarget = 'Token.prototype.brightRadius';
2021-06-29 20:40:54 +02:00
try {
libWrapper.register(packageName, brightRadiusTarget, getBrightRadius, 'OVERRIDE');
} catch (e) {
logger.warn(`Failed to override ${brightRadiusTarget}, some things might not work correctly:`, e);
}
2021-12-04 12:06:03 +01:00
const updateVisionSourceTarget = 'Token.prototype.updateVisionSource';
try {
libWrapper.register(packageName, updateVisionSourceTarget, updateVisionSource, 'OVERRIDE');
} catch (e) {
logger.warn(`Failed to override ${updateVisionSourceTarget}, some things might not work correctly:`, e);
}
registerSettings();
await registerHandlebarsPartials();
2021-06-29 20:40:54 +02:00
}