From b6a1af99263064bcb543119740cd3fd90a5b5a84 Mon Sep 17 00:00:00 2001 From: CPTN Cosmo Date: Sat, 24 Jan 2026 11:39:37 +0100 Subject: [PATCH 1/4] fixed range detection for actions --- module.json | 4 ++-- scripts/importer.js | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/module.json b/module.json index 8f8ee2e..7c240de 100644 --- a/module.json +++ b/module.json @@ -1,7 +1,7 @@ { "id": "dh-importer", "title": "Daggerheart Statblock Importer", - "version": "1.1.0", + "version": "1.1.1", "compatibility": { "minimum": "13", "verified": "13" @@ -34,5 +34,5 @@ "description": "Imports Adversaries and Environments from text blocks into the Daggerheart system.", "url": "https://github.com/cptn-cosmo/dh-importer", "manifest": "https://git.geeks.gay/cosmo/dh-importer/raw/branch/main/module.json", - "download": "https://git.geeks.gay/cosmo/dh-importer/releases/download/1.1.0/dh-importer.zip" + "download": "https://git.geeks.gay/cosmo/dh-importer/releases/download/1.1.1/dh-importer.zip" } \ No newline at end of file diff --git a/scripts/importer.js b/scripts/importer.js index cbc5cd4..2ad4f3b 100644 --- a/scripts/importer.js +++ b/scripts/importer.js @@ -241,7 +241,10 @@ export class DHImporter { // Ranges: Melee, Very Close, Close, Far, Very Far const rangeMatch = rest.match(/^(Melee|Very Close|Close|Far|Very Far)/i); if (rangeMatch) { - data.system.attack.range = rangeMatch[1].toLowerCase(); + let rangeVal = rangeMatch[1].toLowerCase(); + if (rangeVal === "very close") rangeVal = "veryClose"; + if (rangeVal === "very far") rangeVal = "veryFar"; + data.system.attack.range = rangeVal; rest = rest.substring(rangeMatch[0].length).trim(); } @@ -260,7 +263,7 @@ export class DHImporter { formula = dmgMatch[1]; type = dmgMatch[2].toLowerCase(); if (type === "phy") type = "physical"; - else if (type === "mag") type = "magic"; + else if (type === "mag" || type === "magic") type = "magical"; } data.system.attack.damage.parts.push({ @@ -324,7 +327,7 @@ export class DHImporter { damage: { parts: [], includeBase: false, direct: false }, range: "", roll: { - type: "action", // Default to action, switch to attack if detected + type: "attack", // Default to attack diceRolling: { multiplier: "flat", dice: "d6" } } }; @@ -361,7 +364,11 @@ export class DHImporter { // Parse Range const rangeMatch = buffer.description.match(/(Melee|Very Close|Close|Far|Very Far)/i); if (rangeMatch) { - action.range = rangeMatch[1].toLowerCase(); + let rangeVal = rangeMatch[1].toLowerCase(); + if (rangeVal === "very close") rangeVal = "veryClose"; + if (rangeVal === "very far") rangeVal = "veryFar"; + + action.range = rangeVal; } // Parse Damage: "deal 3d4+10 direct physical damage" @@ -376,7 +383,7 @@ export class DHImporter { // Map short codes if (type === "phy") type = "physical"; - else if (type === "mag") type = "magic"; + else if (type === "mag" || type === "magic") type = "magical"; action.damage.direct = isDirect; action.damage.parts.push({ From 3e9bc42ca443f8fb86b9cea4f54421fa3c8d9292 Mon Sep 17 00:00:00 2001 From: CPTN Cosmo Date: Sat, 24 Jan 2026 12:02:46 +0100 Subject: [PATCH 2/4] Going back to the input from the preview no longer empties the textfield, allowing for easier edits before importing --- module.json | 4 ++-- scripts/app.js | 7 ++++++- scripts/importer.js | 12 ++++++++++-- templates/importer.hbs | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/module.json b/module.json index 7c240de..90458b6 100644 --- a/module.json +++ b/module.json @@ -1,7 +1,7 @@ { "id": "dh-importer", "title": "Daggerheart Statblock Importer", - "version": "1.1.1", + "version": "1.2.0", "compatibility": { "minimum": "13", "verified": "13" @@ -34,5 +34,5 @@ "description": "Imports Adversaries and Environments from text blocks into the Daggerheart system.", "url": "https://github.com/cptn-cosmo/dh-importer", "manifest": "https://git.geeks.gay/cosmo/dh-importer/raw/branch/main/module.json", - "download": "https://git.geeks.gay/cosmo/dh-importer/releases/download/1.1.1/dh-importer.zip" + "download": "https://git.geeks.gay/cosmo/dh-importer/releases/download/1.2.0/dh-importer.zip" } \ No newline at end of file diff --git a/scripts/app.js b/scripts/app.js index dd72686..2d30b66 100644 --- a/scripts/app.js +++ b/scripts/app.js @@ -8,6 +8,7 @@ export class DHImporterApp extends HandlebarsApplicationMixin(ApplicationV2) { this.step = "input"; this.parsedData = null; this.parsedDataType = null; + this.inputText = ""; } static DEFAULT_OPTIONS = { @@ -45,7 +46,8 @@ export class DHImporterApp extends HandlebarsApplicationMixin(ApplicationV2) { types: { adversary: "Adversary", environment: "Environment" - } + }, + inputText: this.inputText }; } @@ -75,6 +77,9 @@ export class DHImporterApp extends HandlebarsApplicationMixin(ApplicationV2) { const text = form.querySelector("textarea[name='text']").value; const type = form.querySelector("select[name='type']").value; + // Store input text + this.inputText = text; + if (!text) { ui.notifications.warn("Please enter text to import."); return; diff --git a/scripts/importer.js b/scripts/importer.js index 2ad4f3b..1500f3c 100644 --- a/scripts/importer.js +++ b/scripts/importer.js @@ -314,10 +314,18 @@ export class DHImporter { }; if (isAction) { + // Determine if this is an attack or a generic ability + const isAttack = buffer.description.match(/make.*?attack/i) || + buffer.description.match(/(?:deal|inflict|take)\s+(\d+(?:d\d+)?(?:[\s]*[\+\-][\s]*\d+)?)\s+(direct\s+)?(\w+)\s+damage/i); + + const actionType = isAttack ? "attack" : "ability"; + const rollType = isAttack ? "attack" : "ability"; + const actionId = foundry.utils.randomID(); + const action = { _id: actionId, - type: "attack", + type: actionType, name: buffer.name, actionType: "action", img: "icons/svg/item-bag.svg", @@ -327,7 +335,7 @@ export class DHImporter { damage: { parts: [], includeBase: false, direct: false }, range: "", roll: { - type: "attack", // Default to attack + type: rollType, diceRolling: { multiplier: "flat", dice: "d6" } } }; diff --git a/templates/importer.hbs b/templates/importer.hbs index 833799c..4ad3828 100644 --- a/templates/importer.hbs +++ b/templates/importer.hbs @@ -13,7 +13,7 @@
- +
+
+
+ + +
+
+ +
+
+