Merge branch 'v9-compatibility' into 'master'
Update to Foundry V9 See merge request ghost/darkness-dependent-vision!8
This commit is contained in:
commit
b2a5116cab
7 changed files with 33 additions and 30 deletions
|
@ -10,8 +10,8 @@
|
|||
"email": "johannes.loher@fg4f.de"
|
||||
}
|
||||
],
|
||||
"minimumCoreVersion": "0.8.8",
|
||||
"compatibleCoreVersion": "0.8.9",
|
||||
"minimumCoreVersion": "9.236",
|
||||
"compatibleCoreVersion": "9",
|
||||
"esmodules": ["module/darkness-dependent-vision.js"],
|
||||
"languages": [
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@ import registerHandlebarsPartials from '../handlebars-partials';
|
|||
import logger from '../logger';
|
||||
import registerSettings from '../setiings';
|
||||
import { libWrapper } from '../shims/libWrapperShim';
|
||||
import { getBrightRadius, getDimRadius, updateSource } from '../wrappers/token';
|
||||
import { getBrightRadius, getDimRadius, updateVisionSource } from '../wrappers/token';
|
||||
|
||||
export default function registerForInitHook() {
|
||||
Hooks.on('init', onInit);
|
||||
|
@ -30,7 +30,12 @@ async function onInit() {
|
|||
logger.warn(`Failed to override ${brightRadiusTarget}, some things might not work correctly:`, e);
|
||||
}
|
||||
|
||||
libWrapper.register(packageName, 'Token.prototype.updateSource', updateSource, 'WRAPPER');
|
||||
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();
|
||||
|
|
|
@ -16,6 +16,6 @@ async function onRenderTokenConfig(app, html, data) {
|
|||
'modules/darkness-dependent-vision/templates/darkness-dependent-vision-config-form-groups.hbs',
|
||||
data,
|
||||
);
|
||||
html.find(`div[data-tab="vision"] .form-group input[name="brightSight"]`).parent().after(contents);
|
||||
html.find(`div[data-tab="vision"] .form-group`).last().after(contents);
|
||||
app.setPosition({ height: 'auto' });
|
||||
}
|
||||
|
|
|
@ -8,6 +8,6 @@ export default function registerForUpdateSceneHook() {
|
|||
|
||||
function onUpdateScene(scene, change) {
|
||||
if (change.darkness != null) {
|
||||
scene.getEmbeddedCollection('Token').forEach((tokenDocument) => tokenDocument.object.updateSource());
|
||||
scene.getEmbeddedCollection('Token').forEach((tokenDocument) => tokenDocument.object.updateVisionSource());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,13 +7,13 @@ export default function registerForUpdateTokenHook() {
|
|||
}
|
||||
|
||||
function onUpdateToken(token, change) {
|
||||
const shouldUpdateSource = [
|
||||
const shouldUpdateVisionSource = [
|
||||
'dimVisionDarknessMin',
|
||||
'dimVisionDarknessMax',
|
||||
'brightVisionDarknessMin',
|
||||
'brightVisionDarknessMax',
|
||||
].some((flagKey) => `flags.darkness-dependent-vision.${flagKey}` in foundry.utils.flattenObject(change));
|
||||
if (shouldUpdateSource) {
|
||||
token.object.updateSource();
|
||||
if (shouldUpdateVisionSource) {
|
||||
token.object.updateVisionSource();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,23 +25,19 @@ export function getBrightRadius() {
|
|||
}
|
||||
|
||||
/**
|
||||
* Update the light and vision source objects associated with this Token
|
||||
* @typedef {({defer, deleted, noUpdateFog}?: {defer?: boolean, deleted?: boolean, noUpdateFog?: boolean}) => void} UpdateSourceFunction
|
||||
* @param {UpdateSourceFunction} wrapped The function that is wrapped by this function and needs to be called next in the chain
|
||||
* @param {boolean} [defer] Defer refreshing the SightLayer to manually call that refresh later.
|
||||
* @param {boolean} [deleted] Indicate that this light source has been deleted.
|
||||
* @param {boolean} [noUpdateFog] Never update the Fog exploration progress for this update.
|
||||
* Update an Token vision source associated for this token.
|
||||
* @param {boolean} [defer] Defer refreshing the LightingLayer to manually call that refresh later.
|
||||
* @param {boolean} [deleted] Indicate that this vision source has been deleted.
|
||||
* @param {boolean} [skipUpdateFog] Never update the Fog exploration progress for this update.
|
||||
*/
|
||||
export function updateSource(wrapped, { defer = false, deleted = false, noUpdateFog = false } = {}) {
|
||||
wrapped({ defer, deleted, noUpdateFog });
|
||||
|
||||
// Prepare some common data
|
||||
export function updateVisionSource({ defer = false, deleted = false, skipUpdateFog = false } = {}) {
|
||||
// Prepare data
|
||||
const origin = this.getSightOrigin();
|
||||
const sourceId = this.sourceId;
|
||||
const d = canvas.dimensions;
|
||||
|
||||
// Update vision source
|
||||
const isVisionSource = this._isVisionSource();
|
||||
|
||||
// Initialize vision source
|
||||
if (isVisionSource && !deleted) {
|
||||
const dimSight = getDimVision.call(this);
|
||||
const brightSight = getBrightVision.call(this);
|
||||
|
@ -56,14 +52,16 @@ export function updateSource(wrapped, { defer = false, deleted = false, noUpdate
|
|||
rotation: this.data.rotation,
|
||||
});
|
||||
canvas.sight.sources.set(sourceId, this.vision);
|
||||
if (!defer) {
|
||||
this.vision.drawLight();
|
||||
canvas.sight.refresh({ noUpdateFog });
|
||||
}
|
||||
} else {
|
||||
canvas.sight.sources.delete(sourceId);
|
||||
if (isVisionSource && !defer) canvas.sight.refresh();
|
||||
}
|
||||
|
||||
// Remove vision source
|
||||
else canvas.sight.sources.delete(sourceId);
|
||||
|
||||
// Schedule a perception update
|
||||
if (!defer && (isVisionSource || deleted))
|
||||
canvas.perception.schedule({
|
||||
sight: { refresh: true, skipUpdateFog },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,7 @@ SPDX-FileCopyrightText: 2021 Johannes Loher
|
|||
SPDX-License-Identifier: MIT
|
||||
--}}
|
||||
|
||||
<div class="form-group">
|
||||
<div class="form-group slim">
|
||||
<label>{{ localize 'DarknessDependentVision.DimVisionDarknessRange' }}</label>
|
||||
<div class="form-fields">
|
||||
<label for="flags.darkness-dependent-vision.dimVisionDarknessMin">{{ localize "Between" }}</label>
|
||||
|
@ -19,7 +19,7 @@ SPDX-License-Identifier: MIT
|
|||
<p class="hint">{{ localize "DarknessDependentVision.DimVisionDarknessRangeHint" }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="form-group slim">
|
||||
<label>{{ localize 'DarknessDependentVision.BrightVisionDarknessRange' }}</label>
|
||||
<div class="form-fields">
|
||||
<label for="flags.darkness-dependent-vision.brightVisionDarknessMin">{{ localize "Between" }}</label>
|
||||
|
|
Loading…
Reference in a new issue