-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #943 from Muttley/910-implement-dc-checks
910 implement dc checks
- Loading branch information
Showing
9 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
data/packs/macros.db/request_a_check__YOZcP9WGwie1dLIu.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, {}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |