From 2a72c8ac83e4787217614e7c8bca38b3498205d9 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Tue, 8 Jul 2025 23:37:18 +0200 Subject: [PATCH] Changed to keep the original Cone function --- daggerheart.mjs | 1 - module/canvas/placeables/templateLayer.mjs | 54 ++++++++++++++-- module/data/actor/character.mjs | 3 +- module/documents/actor.mjs | 72 ++++++++++++---------- 4 files changed, 88 insertions(+), 42 deletions(-) diff --git a/daggerheart.mjs b/daggerheart.mjs index dcbe7740..4f411b0f 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -56,7 +56,6 @@ Hooks.once('init', () => { CONFIG.Dice.rolls = [...CONFIG.Dice.rolls, ...[DHRoll, DualityRoll, D20Roll, DamageRoll]]; CONFIG.MeasuredTemplate.objectClass = placeables.DhMeasuredTemplate; - CONFIG.MeasuredTemplate.defaults.angle = 180; CONFIG.Item.documentClass = documents.DHItem; diff --git a/module/canvas/placeables/templateLayer.mjs b/module/canvas/placeables/templateLayer.mjs index 8c0370e2..551a06cc 100644 --- a/module/canvas/placeables/templateLayer.mjs +++ b/module/canvas/placeables/templateLayer.mjs @@ -1,6 +1,6 @@ -export default class DhTemplateLayer extends TemplateLayer { +export default class DhTemplateLayer extends foundry.canvas.layers.TemplateLayer { static prepareSceneControls() { - const sc = SceneControls; + const sc = foundry.applications.ui.SceneControls; return { name: 'templates', order: 2, @@ -26,6 +26,17 @@ export default class DhTemplateLayer extends TemplateLayer { cone: { name: 'cone', order: 2, + title: 'CONTROLS.MeasureCone', + icon: 'fa-solid fa-angle-left', + toolclip: { + src: 'toolclips/tools/measure-cone.webm', + heading: 'CONTROLS.MeasureCone', + items: sc.buildToolclipItems(['create', 'move', 'edit', 'hide', 'delete', 'rotate']) + } + }, + inFront: { + name: 'inFront', + order: 3, title: 'CONTROLS.inFront', icon: 'fa-solid fa-eye', toolclip: { @@ -36,7 +47,7 @@ export default class DhTemplateLayer extends TemplateLayer { }, rect: { name: 'rect', - order: 3, + order: 4, title: 'CONTROLS.MeasureRect', icon: 'fa-regular fa-square', toolclip: { @@ -47,7 +58,7 @@ export default class DhTemplateLayer extends TemplateLayer { }, ray: { name: 'ray', - order: 4, + order: 5, title: 'CONTROLS.MeasureRay', icon: 'fa-solid fa-up-down', toolclip: { @@ -58,7 +69,7 @@ export default class DhTemplateLayer extends TemplateLayer { }, clear: { name: 'clear', - order: 5, + order: 6, title: 'CONTROLS.MeasureClear', icon: 'fa-solid fa-trash', visible: game.user.isGM, @@ -69,4 +80,37 @@ export default class DhTemplateLayer extends TemplateLayer { activeTool: 'circle' }; } + + _onDragLeftStart(event) { + const interaction = event.interactionData; + + // Snap the origin to the grid + if (!event.shiftKey) interaction.origin = this.getSnappedPoint(interaction.origin); + + // Create a pending MeasuredTemplateDocument + const tool = game.activeTool === 'inFront' ? 'cone' : game.activeTool; + const previewData = { + user: game.user.id, + t: tool, + x: interaction.origin.x, + y: interaction.origin.y, + sort: Math.max(this.getMaxSort() + 1, 0), + distance: 1, + direction: 0, + fillColor: game.user.color || '#FF0000', + hidden: event.altKey + }; + const defaults = CONFIG.MeasuredTemplate.defaults; + if (game.activeTool === 'cone') previewData.angle = defaults.angle; + else if (game.activeTool === 'inFront') previewData.angle = 180; + else if (game.activeTool === 'ray') previewData.width = defaults.width * canvas.dimensions.distance; + const cls = foundry.utils.getDocumentClass('MeasuredTemplate'); + const doc = new cls(previewData, { parent: canvas.scene }); + + // Create a preview MeasuredTemplate object + const template = new this.constructor.placeableClass(doc); + doc._object = template; + interaction.preview = this.preview.addChild(template); + template.draw(); + } } diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index 1dfbd015..daf63a79 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -1,5 +1,4 @@ import { burden } from '../../config/generalConfig.mjs'; -import ActionField from '../fields/actionField.mjs'; import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs'; import DhLevelData from '../levelData.mjs'; import BaseDataActor from './base.mjs'; @@ -29,7 +28,7 @@ export default class DhCharacter extends BaseDataActor { return foundry.utils.mergeObject(super.metadata, { label: 'TYPES.Actor.character', type: 'character', - isNPC: false, + isNPC: false }); } diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index 1fab0f71..50d3348c 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -5,13 +5,13 @@ import { LevelOptionType } from '../data/levelTier.mjs'; import DHFeature from '../data/item/feature.mjs'; export default class DhpActor extends Actor { - /** * Return the first Actor active owner. */ get owner() { - const user = this.hasPlayerOwner && game.users.players.find(u => this.testUserPermission(u, "OWNER") && u.active);; - if(!user) return game.user.isGM ? game.user : null; + const user = + this.hasPlayerOwner && game.users.players.find(u => this.testUserPermission(u, 'OWNER') && u.active); + if (!user) return game.user.isGM ? game.user : null; return user; } @@ -153,7 +153,6 @@ export default class DhpActor extends Actor { } async levelUp(levelupData) { - const actions = []; const levelups = {}; for (var levelKey of Object.keys(levelupData)) { const level = levelupData[levelKey]; @@ -317,7 +316,6 @@ export default class DhpActor extends Actor { await this.update({ system: { - actions: [...this.system.actions, ...actions], levelData: { level: { current: this.system.levelData.level.changed @@ -369,16 +367,16 @@ export default class DhpActor extends Actor { const modifier = roll.modifier !== null ? Number.parseInt(roll.modifier) : null; return modifier !== null ? [ - { - value: modifier, - label: roll.label - ? modifier >= 0 - ? `${roll.label} +${modifier}` - : `${roll.label} ${modifier}` - : null, - title: roll.label - } - ] + { + value: modifier, + label: roll.label + ? modifier >= 0 + ? `${roll.label} +${modifier}` + : `${roll.label} ${modifier}` + : null, + title: roll.label + } + ] : []; } @@ -460,7 +458,7 @@ export default class DhpActor extends Actor { if (Hooks.call(`${CONFIG.DH.id}.postDamageTreshold`, this, hpDamage, damage, type) === false) return null; - if(!hpDamage) return; + if (!hpDamage) return; const updates = [{ value: hpDamage, type: 'hitPoints' }]; @@ -469,8 +467,8 @@ export default class DhpActor extends Actor { this.system.armor && this.system.armor.system.marks.value < this.system.armorScore ) { - const armorStackResult = await this.owner.query('armorStack', {actorId: this.uuid, damage: hpDamage}); - if(armorStackResult) { + const armorStackResult = await this.owner.query('armorStack', { actorId: this.uuid, damage: hpDamage }); + if (armorStackResult) { const { modifiedDamage, armorSpent, stressSpent } = armorStackResult; updates.find(u => u.type === 'hitPoints').value = modifiedDamage; updates.push( @@ -479,7 +477,7 @@ export default class DhpActor extends Actor { ); } } - + await this.modifyResource(updates); if (Hooks.call(`${CONFIG.DH.id}.postTakeDamage`, this, damage, type) === false) return null; @@ -493,7 +491,7 @@ export default class DhpActor extends Actor { async modifyResource(resources) { if (!resources.length) return; - if(resources.find(r => r.type === 'stress')) this.convertStressDamageToHP(resources); + if (resources.find(r => r.type === 'stress')) this.convertStressDamageToHP(resources); let updates = { actor: { target: this, resources: {} }, armor: { target: this.system.armor, resources: {} } }; resources.forEach(r => { switch (r.type) { @@ -521,7 +519,12 @@ export default class DhpActor extends Actor { }); Object.values(updates).forEach(async u => { if (Object.keys(u.resources).length > 0) { - await emitAsGM(GMUpdateEvent.UpdateDocument, u.target.update.bind(u.target), u.resources, u.target.uuid); + await emitAsGM( + GMUpdateEvent.UpdateDocument, + u.target.update.bind(u.target), + u.resources, + u.target.uuid + ); /* if (game.user.isGM) { await u.target.update(u.resources); } else { @@ -540,27 +543,28 @@ export default class DhpActor extends Actor { convertDamageToThreshold(damage) { return damage >= this.system.damageThresholds.severe - ? 3 - : damage >= this.system.damageThresholds.major - ? 2 - : damage >= this.system.damageThresholds.minor - ? 1 - : 0; + ? 3 + : damage >= this.system.damageThresholds.major + ? 2 + : damage >= this.system.damageThresholds.minor + ? 1 + : 0; } convertStressDamageToHP(resources) { const stressDamage = resources.find(r => r.type === 'stress'), newValue = this.system.resources.stress.value + stressDamage.value; - if(newValue <= this.system.resources.stress.maxTotal) return; + if (newValue <= this.system.resources.stress.maxTotal) return; const hpDamage = resources.find(r => r.type === 'hitPoints'); - if(hpDamage) hpDamage.value++; - else resources.push({ - type: 'hitPoints', - value: 1 - }) + if (hpDamage) hpDamage.value++; + else + resources.push({ + type: 'hitPoints', + value: 1 + }); } } export const registerDHActorHooks = () => { CONFIG.queries.armorStack = DamageReductionDialog.armorStackQuery; -} \ No newline at end of file +};