Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

910 implement dc checks #943

Merged
merged 8 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions data/macros/request-a-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
************************************************
* This macro opens the request check dialog box
************************************************/

new shadowdark.apps.RequestCheckSD().render(true);
11 changes: 11 additions & 0 deletions data/packs/macros.db/request_a_check__YOZcP9WGwie1dLIu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"_id": "YOZcP9WGwie1dLIu",
"_key": "!macros!YOZcP9WGwie1dLIu",
"author": "XOge3YaW9qcUJnuq",
"command": "/**\n ************************************************\n * This macro opens the request check dialog box\n ************************************************/\n\nnew shadowdark.apps.RequestCheckSD().render(true);",
"folder": null,
"img": "icons/sundries/gaming/dice-runed-brown.webp",
"name": "Request a Check",
"scope": "global",
"type": "script"
}
10 changes: 10 additions & 0 deletions i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ SHADOWDARK.apps.monster-importer.instruction2d: Main stat block
SHADOWDARK.apps.monster-importer.instruction2e: Feature
SHADOWDARK.apps.monster-importer.instruction3: 3. Click Import Monster.
SHADOWDARK.apps.monster-importer.title: Import Monster
SHADOWDARK.apps.request-check.copied: Copied to Clipboard
SHADOWDARK.apps.request-check.copy_to_clipboard: Copy to Clipboard
SHADOWDARK.apps.request-check.custom: Custom
SHADOWDARK.apps.request-check.easy: Easy
SHADOWDARK.apps.request-check.hard: Hard
SHADOWDARK.apps.request-check.extreme: Extreme
SHADOWDARK.apps.request-check.normal: Normal
SHADOWDARK.apps.request-check.title: Request Check
SHADOWDARK.apps.shadowdarkling-importer.errors: Items Not Found
SHADOWDARK.apps.shadowdarkling-importer.header: Shadowdarkling Importer
SHADOWDARK.apps.shadowdarkling-importer.import_button: Import
Expand Down Expand Up @@ -187,6 +195,7 @@ SHADOWDARK.chat.welcome_message.title_text: Welceome to Shadowdark RPG. Here are
SHADOWDARK.chat.welcome_message.title: Shadowdark RPG for Foundry
SHADOWDARK.chat.welcome_message.watch: Watch the Video Tutorial
SHADOWDARK.chatcard.default: Roll
SHADOWDARK.check.requesting: Requesting a check
SHADOWDARK.class-ability.ability.check: Ability Check
SHADOWDARK.class-ability.ability.label: Ability
SHADOWDARK.class-ability.available.label: Available
Expand Down Expand Up @@ -341,6 +350,7 @@ SHADOWDARK.effect.unavailable: Disabled Effects
SHADOWDARK.error.class_ability.no-uses-remaining: No uses remaining
SHADOWDARK.error.general.gm_required: You must have the Game Master role to do that.
SHADOWDARK.error.general.no_character_class: No character class has been selected
SHADOWDARK.error.general.no_character_selected: No character selected
SHADOWDARK.error.source.source_missing: Source missing or unknown...
SHADOWDARK.error.spells.no_spellcasting_ability_set: No character spellcasting ability has been configured
SHADOWDARK.error.patron.no_supported_class: Unable to add Patron as the currently configured class does not allow it
Expand Down
8 changes: 8 additions & 0 deletions scss/shadowdark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
width: 100%;
}

input[type=radio] {
width: auto;
}

hr {
border: none;
border-top: solid 1px #{$primary-color};
Expand Down Expand Up @@ -79,4 +83,8 @@
}
}

.checkbox {
font-size:14px;
};

}
3 changes: 3 additions & 0 deletions system/shadowdark.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import registerSystemSettings from "./src/settings.mjs";
import SHADOWDARK from "./src/config.mjs";
import ShadowdarkMacro from "./src/macro.mjs";
import UtilitySD from "./src/utils/UtilitySD.mjs";
import ChecksSD from "./src/utils/ChecksSD.mjs";
import ActiveEffectsSD from "./src/effects.mjs";

import * as apps from "./src/apps/_module.mjs";
Expand Down Expand Up @@ -40,6 +41,7 @@ globalThis.shadowdark = {
log: Logger.log,
macro: ShadowdarkMacro,
sheets,
checks: ChecksSD,
utils: UtilitySD,
warn: Logger.warn,
};
Expand Down Expand Up @@ -77,6 +79,7 @@ Hooks.once("init", () => {
registerSystemSettings();
loadTemplates();

ChecksSD.registerEnrichers();
UtilitySD.loadLegacyArtMappings();

// Register sheet application classes
Expand Down
59 changes: 59 additions & 0 deletions system/src/apps/RequestCheckSD.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export default class RequestCheckSD extends FormApplication {

static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["shadowdark"],
template: "systems/shadowdark/templates/apps/request-check.hbs",
width: 400,
title: game.i18n.localize("SHADOWDARK.apps.request-check.title"),
closeOnSubmit: false,
});
}

activateListeners(html) {
super.activateListeners(html);

html.find(".custom-dc").click(
event => {
$(event.target).siblings()[0].checked=true;
}
);
}

/** @override */
async getData() {
return {
stats: CONFIG.SHADOWDARK.ABILITIES_LONG,
difficulty: {
9: `9 (${game.i18n.localize("SHADOWDARK.apps.request-check.easy")})`,
12: `12 (${game.i18n.localize("SHADOWDARK.apps.request-check.normal")})`,
15: `15 (${game.i18n.localize("SHADOWDARK.apps.request-check.hard")})`,
18: `18 (${game.i18n.localize("SHADOWDARK.apps.request-check.extreme")})`,
},
};
}

/** @inheritdoc */
async _updateObject(event, data) {

if (data.custom) {
data.difficulty = data.custom;
}
data.difficulty = parseInt(data.difficulty);

switch (event.submitter.name) {
case "request-copy":
let linkText = `[[request ${data.difficulty} ${data.stat}]]`;
await navigator.clipboard.writeText(linkText);
ui.notifications.info(game.i18n.localize("SHADOWDARK.apps.request-check.copied"));
break;
case "request-check":
shadowdark.checks.displayRequest(data.difficulty, data.stat);
this.close();
break;
default:
shadowdark.log("Request Check Error");
}
}

}
1 change: 1 addition & 0 deletions system/src/apps/_module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export {default as LightSourceTrackerSD} from "./LightSourceTrackerSD.mjs";
export {default as LoadingSD} from "./LoadingSD.mjs";
export {default as MonsterImporterSD} from "./MonsterImporterSD.mjs";
export {default as NpcAttackRangesSD} from "./NpcAttackRangesSD.mjs";
export {default as RequestCheckSD} from "./RequestCheckSD.mjs";
export {default as ShadowdarklingImporterSD} from "./ShadowdarklingImporterSD.mjs";
export {default as SpellBookSD} from "./SpellBookSD.mjs";
export {default as SpellImporterSD} from "./SpellImporterSD.mjs";
Expand Down
85 changes: 85 additions & 0 deletions system/src/utils/ChecksSD.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
export default class ChecksSD {

static async registerEnrichers() {
// load custom text enrichers
// [[check DC STAT]]
// [[request DC STAT]]
CONFIG.TextEditor.enrichers.push({
pattern: /\[\[(?<command>check|request)\s(?<dc>\d+)\s(?<stat>\w{3})\]\]/g,
enricher: async (match, options) => {
let { command, dc, stat } = match.groups;

// Check for invalid data
if (!parseInt(dc)) return;
if (CONFIG.SHADOWDARK.ABILITY_KEYS.includes(stat.toLowerCase())) {
stat = stat.toLowerCase();
}
else {
return;
}

// create replacement html
const link = document.createElement("a");
link.className = "content-link";
link.dataset.command = command;
link.dataset.dc = dc;
link.dataset.stat = stat;
const linkText = `${game.i18n.localize("SHADOWDARK.class-ability.dc.label")} ${dc} ${game.i18n.localize(`SHADOWDARK.ability_${stat}`)}`.toUpperCase();
switch (command) {
case "check":
link.innerHTML = `<i class="fa-solid fa-dice-d20"></i>${linkText}`;
break;
case "request":
link.innerHTML = `<i class="fa-solid fa-comment"></i>${linkText}`;
break;
}
return link;
},
});

document.body.addEventListener("click", this.checkHandler);
}

static async checkHandler(event) {
let data = event.target?.dataset;
if ( !data.command ) return;

switch (data.command) {
case "check":
let options = {};
if (event.shiftKey) {
options.fastForward = true;
}
shadowdark.checks.rollCheck(data.dc, data.stat, options);
break;
case "request":
shadowdark.checks.displayRequest(data.dc, data.stat);
break;
}
}

static async rollCheck(dc, stat, options={}) {
let actor = game.user.character;
if (!actor) {
ui.notification.error(
game.i18n.localize("SHADOWDARK.error.general.no_character_selected")
);
}
if (dc) {
options.target = dc;
}
actor.rollAbility(stat.toLowerCase(), options);
}


static async displayRequest(dc, stat) {
const HTML = `<div style="text-align:center">[[check ${dc} ${stat}]]</div>`;
const chatData = {
user: game.user._id,
flavor: game.i18n.localize("SHADOWDARK.check.requesting"),
content: HTML,
};
ChatMessage.create(chatData, {});
}

}
32 changes: 32 additions & 0 deletions system/templates/apps/request-check.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<form autocomplete="off">
<div class="grid-2-columns">
{{#> ui/sd-box
header-label="Difficulty"
}}
<div class="grid-1-columns">
{{radioBoxes "difficulty" difficulty checked="12"}}
<hr>
<label class="checkbox">
<input type="radio" name="difficulty" value="0">
<input type="number" class="custom-dc" name="custom" style="width:2em;" maxlength="2">
({{localize "SHADOWDARK.apps.request-check.custom"}})
</label>
</div>
{{/ui/sd-box}}

{{#> ui/sd-box
header-label="Stat"
}}
<div class="grid-1-columns">
{{radioBoxes "stat" stats checked="str"}}
</div>
{{/ui/sd-box}}

<hr class="grid-colspan-2">

<button class="grid-colspan-2" type="submit" name="request-copy">{{localize "SHADOWDARK.apps.request-check.copy_to_clipboard"}}</button>
<button class="grid-colspan-2 larger" type="submit" name="request-check" style="font-family:'Old Newspaper Font';">
{{localize "SHADOWDARK.apps.request-check.title"}}
</button>
</div>
</form>