mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-19 16:24:06 +01:00
Fixed to use Foundry's measuring instead.
This commit is contained in:
parent
b80f598625
commit
9baaa0c01f
6 changed files with 28 additions and 82 deletions
|
|
@ -6,7 +6,7 @@ import * as dice from './module/dice/_module.mjs';
|
||||||
import * as fields from './module/data/fields/_module.mjs';
|
import * as fields from './module/data/fields/_module.mjs';
|
||||||
import RegisterHandlebarsHelpers from './module/helpers/handlebarsHelper.mjs';
|
import RegisterHandlebarsHelpers from './module/helpers/handlebarsHelper.mjs';
|
||||||
import { enricherConfig, enricherRenderSetup } from './module/enrichers/_module.mjs';
|
import { enricherConfig, enricherRenderSetup } from './module/enrichers/_module.mjs';
|
||||||
import { compareValues, getCommandTarget, rollCommandToJSON } from './module/helpers/utils.mjs';
|
import { getCommandTarget, rollCommandToJSON } from './module/helpers/utils.mjs';
|
||||||
import { NarrativeCountdowns } from './module/applications/ui/countdowns.mjs';
|
import { NarrativeCountdowns } from './module/applications/ui/countdowns.mjs';
|
||||||
import { DualityRollColor } from './module/data/settings/Appearance.mjs';
|
import { DualityRollColor } from './module/data/settings/Appearance.mjs';
|
||||||
import { DHRoll, DualityRoll, D20Roll, DamageRoll, DualityDie } from './module/dice/_module.mjs';
|
import { DHRoll, DualityRoll, D20Roll, DamageRoll, DualityDie } from './module/dice/_module.mjs';
|
||||||
|
|
@ -242,47 +242,25 @@ Hooks.on('moveToken', async (movedToken, data) => {
|
||||||
|
|
||||||
const rangeDependantEffects = movedToken.actor.effects.filter(effect => effect.system.rangeDependence.enabled);
|
const rangeDependantEffects = movedToken.actor.effects.filter(effect => effect.system.rangeDependence.enabled);
|
||||||
|
|
||||||
const { x, y, height, width } = data.destination;
|
const updateEffects = async (disposition, token, effects, effectUpdates) => {
|
||||||
const getDimensions = (x, y, height, width) => {
|
|
||||||
const heightModifier = Math.max(Math.round(height) - 1, 0);
|
|
||||||
const widthModifier = Math.max(Math.round(width) - 1, 0);
|
|
||||||
|
|
||||||
return {
|
|
||||||
minX: x - widthModifier,
|
|
||||||
maxX: x + widthModifier,
|
|
||||||
minY: y - heightModifier,
|
|
||||||
maxY: y + widthModifier
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const { minX: dMinX, maxX: dMaxX, minY: dMinY, maxY: dMaxY } = getDimensions(x, y, height, width);
|
|
||||||
|
|
||||||
const updateEffects = async (token, dimensions, effects, effectUpdates) => {
|
|
||||||
const { minX, maxX, minY, maxY } = dimensions;
|
|
||||||
|
|
||||||
const rangeMeasurement = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.RangeMeasurement);
|
const rangeMeasurement = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.RangeMeasurement);
|
||||||
|
|
||||||
for (let effect of effects.filter(x => x.system.rangeDependence.enabled)) {
|
for (let effect of effects.filter(x => x.system.rangeDependence.enabled)) {
|
||||||
const { target, range, type } = effect.system.rangeDependence;
|
const { target, range, type } = effect.system.rangeDependence;
|
||||||
if (
|
if ((target === 'friendly' && disposition !== 1) || (target === 'hostile' && disposition !== -1))
|
||||||
(target === 'friendly' && token.disposition !== 1) ||
|
|
||||||
(target === 'hostile' && token.disposition !== -1)
|
|
||||||
)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const distance = rangeMeasurement[range] * 20; // x/y scale is 100. Grid in feet is 5.
|
const distanceBetween = canvas.grid.measurePath([
|
||||||
const xOkay =
|
{ ...movedToken.toObject(), x: data.destination.x, y: data.destination.y },
|
||||||
compareValues(Math.abs(minX - dMinX), distance, type) ||
|
token
|
||||||
compareValues(Math.abs(maxX - dMaxX), distance, type);
|
]).distance;
|
||||||
const yOkay =
|
const distance = rangeMeasurement[range];
|
||||||
compareValues(Math.abs(minY - dMinY), distance, type) ||
|
|
||||||
compareValues(Math.abs(maxY - dMaxY), distance, type);
|
|
||||||
|
|
||||||
const reverse = ['moreThan', 'moreThanEqual'].includes(type);
|
const reverse = type === CONFIG.DH.GENERAL.rangeInclusion.outsideRange.id;
|
||||||
const newDisabled = reverse ? !xOkay && !yOkay : !xOkay || !yOkay;
|
const newDisabled = reverse ? distanceBetween <= distance : distanceBetween > distance;
|
||||||
const oldDisabled = effectUpdates[effect.uuid] ? effectUpdates[effect.uuid].disabled : newDisabled;
|
const oldDisabled = effectUpdates[effect.uuid] ? effectUpdates[effect.uuid].disabled : newDisabled;
|
||||||
effectUpdates[effect.uuid] = {
|
effectUpdates[effect.uuid] = {
|
||||||
disabled: reverse ? oldDisabled || newDisabled : oldDisabled && newDisabled,
|
disabled: oldDisabled || newDisabled,
|
||||||
value: effect
|
value: effect
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -290,14 +268,11 @@ Hooks.on('moveToken', async (movedToken, data) => {
|
||||||
|
|
||||||
const effectUpdates = {};
|
const effectUpdates = {};
|
||||||
for (let token of game.scenes.find(x => x.active).tokens) {
|
for (let token of game.scenes.find(x => x.active).tokens) {
|
||||||
if (token.id === movedToken.id) continue;
|
if (token.id !== movedToken.id) {
|
||||||
|
await updateEffects(token.disposition, token, rangeDependantEffects, effectUpdates);
|
||||||
|
}
|
||||||
|
|
||||||
const { x, y, height, width } = token;
|
if (token.actor) await updateEffects(movedToken.disposition, token, token.actor.effects, effectUpdates);
|
||||||
const dimensions = getDimensions(x, y, height, width);
|
|
||||||
|
|
||||||
await updateEffects(token, dimensions, rangeDependantEffects, effectUpdates);
|
|
||||||
|
|
||||||
if (token.actor) await updateEffects(token, dimensions, token.actor.effects, effectUpdates);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let key in effectUpdates) {
|
for (let key in effectUpdates) {
|
||||||
|
|
|
||||||
|
|
@ -633,12 +633,9 @@
|
||||||
"oneHanded": "One-Handed",
|
"oneHanded": "One-Handed",
|
||||||
"twoHanded": "Two-Handed"
|
"twoHanded": "Two-Handed"
|
||||||
},
|
},
|
||||||
"CompareOperator": {
|
"RangeInclusion": {
|
||||||
"lessThan": "Less Than",
|
"withinRange": "Within Range",
|
||||||
"lessThanEqual": "Less Than Equal",
|
"outsideRange": "Outside Range"
|
||||||
"equal": "Equal",
|
|
||||||
"moreThanEqual": "More Than Equal",
|
|
||||||
"moreThan": "More Than"
|
|
||||||
},
|
},
|
||||||
"Condition": {
|
"Condition": {
|
||||||
"dead": {
|
"dead": {
|
||||||
|
|
|
||||||
|
|
@ -43,26 +43,14 @@ export const range = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const compareOperator = {
|
export const rangeInclusion = {
|
||||||
lessThan: {
|
withinRange: {
|
||||||
id: 'lessThan',
|
id: 'withinRange',
|
||||||
label: 'DAGGERHEART.CONFIG.CompareOperator.lessThan'
|
label: 'DAGGERHEART.CONFIG.RangeInclusion.withinRange'
|
||||||
},
|
},
|
||||||
lessThanEqual: {
|
outsideRange: {
|
||||||
id: 'lessThanEqual',
|
id: 'outsideRange',
|
||||||
label: 'DAGGERHEART.CONFIG.CompareOperator.lessThanEqual'
|
label: 'DAGGERHEART.CONFIG.RangeInclusion.outsideRange'
|
||||||
},
|
|
||||||
equal: {
|
|
||||||
id: 'equal',
|
|
||||||
label: 'DAGGERHEART.CONFIG.CompareOperator.equal'
|
|
||||||
},
|
|
||||||
moreThanEqual: {
|
|
||||||
id: 'moreThanEqual',
|
|
||||||
label: 'DAGGERHEART.CONFIG.CompareOperator.moreThanEqual'
|
|
||||||
},
|
|
||||||
moreThan: {
|
|
||||||
id: 'moreThan',
|
|
||||||
label: 'DAGGERHEART.CONFIG.CompareOperator.moreThan'
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ export default class BaseEffect extends foundry.abstract.TypeDataModel {
|
||||||
}),
|
}),
|
||||||
type: new fields.StringField({
|
type: new fields.StringField({
|
||||||
required: true,
|
required: true,
|
||||||
choices: CONFIG.DH.GENERAL.compareOperator,
|
choices: CONFIG.DH.GENERAL.rangeInclusion,
|
||||||
initial: CONFIG.DH.GENERAL.compareOperator.lessThanEqual.id,
|
initial: CONFIG.DH.GENERAL.rangeInclusion.withinRange.id,
|
||||||
label: 'DAGGERHEART.GENERAL.type'
|
label: 'DAGGERHEART.GENERAL.type'
|
||||||
}),
|
}),
|
||||||
target: new fields.StringField({
|
target: new fields.StringField({
|
||||||
|
|
|
||||||
|
|
@ -321,18 +321,3 @@ export const arraysEqual = (a, b) =>
|
||||||
[...new Set([...a, ...b])].every(v => a.filter(e => e === v).length === b.filter(e => e === v).length);
|
[...new Set([...a, ...b])].every(v => a.filter(e => e === v).length === b.filter(e => e === v).length);
|
||||||
|
|
||||||
export const setsEqual = (a, b) => a.size === b.size && [...a].every(value => b.has(value));
|
export const setsEqual = (a, b) => a.size === b.size && [...a].every(value => b.has(value));
|
||||||
|
|
||||||
export function compareValues(a, b, compare) {
|
|
||||||
switch (compare) {
|
|
||||||
case CONFIG.DH.GENERAL.compareOperator.lessThan.id:
|
|
||||||
return a < b;
|
|
||||||
case CONFIG.DH.GENERAL.compareOperator.lessThanEqual.id:
|
|
||||||
return a <= b;
|
|
||||||
case CONFIG.DH.GENERAL.compareOperator.equal.id:
|
|
||||||
return a === b;
|
|
||||||
case CONFIG.DH.GENERAL.compareOperator.moreThanEqual.id:
|
|
||||||
return a >= b;
|
|
||||||
case CONFIG.DH.GENERAL.compareOperator.moreThan.id:
|
|
||||||
return a > b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
{{formGroup settingFields.schema.fields.close value=settingFields._source.close localize=true}}
|
{{formGroup settingFields.schema.fields.close value=settingFields._source.close localize=true}}
|
||||||
{{formGroup settingFields.schema.fields.far value=settingFields._source.far localize=true}}
|
{{formGroup settingFields.schema.fields.far value=settingFields._source.far localize=true}}
|
||||||
{{formGroup settingFields.schema.fields.veryFar value=settingFields._source.veryFar localize=true}}
|
{{formGroup settingFields.schema.fields.veryFar value=settingFields._source.veryFar localize=true}}
|
||||||
|
{{formGroup settingFields.schema.fields.diagonalMeasuring value=settingFields._source.diagonalMeasuring localize=true}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer class="form-footer">
|
<footer class="form-footer">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue