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