Skip to content

Commit

Permalink
slight restructure, and add release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Muttley committed Nov 16, 2024
1 parent e165787 commit f3acacc
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 94 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [#880] Create a new Patron Boon type for Talents
* [#901] Added Russian as a partially complete system language.
* [#908] Add rollable dice to Cure Wounds spell that includes the necessary calculations *(Many thanks to **nschoenwald** for contributing to this issue)*
* [#910] Implement prompt for DC Checks
* [#920] Show tooltips on weapon and armor properties when showing expanded inline view in inventory
* [#921] Add way to view/manipulate current Active Effects to the player Effects tab
* [#937] Support selecting or rolling Patron in character generator
Expand Down
5 changes: 3 additions & 2 deletions i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ 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.hard: Hard
SHADOWDARK.apps.request-check.normal: Normal
SHADOWDARK.apps.request-check.title: Request Check
SHADOWDARK.apps.shadowdarkling-importer.errors: Items Not Found
Expand Down Expand Up @@ -351,9 +351,10 @@ 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.patron.no_supported_class: Unable to add Patron as the currently configured class does not allow it
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
SHADOWDARK.error.too_many_tokens_selected: Too many tokens selected
SHADOWDARK.form.section_header.equipment.label: Equipment
SHADOWDARK.form.section_header.languages.label: Languages
SHADOWDARK.form.section_header.names.label: Names
Expand Down
9 changes: 5 additions & 4 deletions system/shadowdark.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import ActiveEffectsSD from "./src/system/ActiveEffectsSD.mjs";
import ChatSD from "./src/system/ChatSD.mjs";
import CompendiumsSD from "./src/documents/CompendiumsSD.mjs";
import loadTemplates from "./src/templates.mjs";
import Logger from "./src/utils/Logger.mjs";
import performDataMigration from "./src/migration.mjs";
import registerHandlebarsHelpers from "./src/handlebars.mjs";
import registerSystemSettings from "./src/settings.mjs";
import registerTextEditorEnrichers from "./src/enrichers.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";
import * as chat from "./src/chat/_module.mjs";
Expand All @@ -30,6 +31,7 @@ import listenOnSocket from "./src/socket.mjs";

globalThis.shadowdark = {
apps,
chat: ChatSD,
compendiums: CompendiumsSD,
config: SHADOWDARK,
debug: Logger.debug,
Expand All @@ -41,7 +43,6 @@ globalThis.shadowdark = {
log: Logger.log,
macro: ShadowdarkMacro,
sheets,
checks: ChecksSD,
utils: UtilitySD,
warn: Logger.warn,
};
Expand Down Expand Up @@ -77,9 +78,9 @@ Hooks.once("init", () => {

registerHandlebarsHelpers();
registerSystemSettings();
registerTextEditorEnrichers();
loadTemplates();

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

// Register sheet application classes
Expand Down
50 changes: 47 additions & 3 deletions system/src/apps/RequestCheckSD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,49 @@ export default class RequestCheckSD extends FormApplication {
});
}


static async checkHandler(event) {
const data = event.target?.dataset ?? {};

if (!data.command) return;

switch (data.command) {
case "check":
const actor = await shadowdark.utils.getCurrentActor();
if (!actor) {
return ui.notifications.error(
game.i18n.localize("SHADOWDARK.error.general.no_character_selected")
);
}

const options = {
target: data.dc,
stat: data.stat,
};

if (event.shiftKey) {
options.fastForward = true;
}

return actor.rollAbility(data.stat.toLowerCase(), options);
case "request":
return RequestCheckSD.displayRequest(data.dc, data.stat);
}
}


static async displayRequest(dc, stat) {
shadowdark.chat.renderRollRequestMessage(
await shadowdark.utils.getCurrentActor(),
{
title: game.i18n.localize("SHADOWDARK.check.requesting"),
body: `[[check ${dc} ${stat}]]`,
},
CONST.DICE_ROLL_MODES.PUBLIC
);
}


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

Expand All @@ -20,6 +63,7 @@ export default class RequestCheckSD extends FormApplication {
);
}


/** @override */
async getData() {
return {
Expand All @@ -33,9 +77,9 @@ export default class RequestCheckSD extends FormApplication {
};
}


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

if (data.custom) {
data.difficulty = data.custom;
}
Expand All @@ -48,11 +92,11 @@ export default class RequestCheckSD extends FormApplication {
ui.notifications.info(game.i18n.localize("SHADOWDARK.apps.request-check.copied"));
break;
case "request-check":
shadowdark.checks.displayRequest(data.difficulty, data.stat);
RequestCheckSD.displayRequest(data.difficulty, data.stat);
this.close();
break;
default:
shadowdark.log("Request Check Error");
shadowdark.error("Request Check Error");
}
}

Expand Down
44 changes: 44 additions & 0 deletions system/src/enrichers.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export default function registerTextEditorEnrichers() {

CONFIG.TextEditor.enrichers.push({
// [[check DC STAT]]
// [[request DC STAT]]
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.classList.add("skill-roll-request");
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;
},
});

$("body").on(
"click", "a.skill-roll-request",
shadowdark.apps.RequestCheckSD.checkHandler
);

}
File renamed without changes.
45 changes: 45 additions & 0 deletions system/src/system/ChatSD.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export default class ChatSD {

static async _renderChatMessage(
actor,
data,
template,
mode
) {
const html = await renderTemplate(template, data);

if (!mode) {
mode = game.settings.get("core", "rollMode");
}

const messageStyles = shadowdark.utils.getMessageStyles();

const chatData = {
user: game.user.id,
speaker: ChatMessage.getSpeaker({
actor: actor,
}),
rollMode: mode,
content: html,
type: messageStyles.OTHER,
};

ChatMessage.applyRollMode(chatData, mode);

await ChatMessage.create(chatData);
}

static async renderGeneralMessage(actor, data, mode) {
this._renderChatMessage(actor, data,
"systems/shadowdark/templates/chat/general.hbs",
mode
);
}

static async renderRollRequestMessage(actor, data, mode) {
this._renderChatMessage(actor, data,
"systems/shadowdark/templates/chat/roll-request.hbs",
mode
);
}
}
85 changes: 0 additions & 85 deletions system/src/utils/ChecksSD.mjs

This file was deleted.

27 changes: 27 additions & 0 deletions system/src/utils/UtilitySD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,33 @@ export default class UtilitySD {
}


// Work out the current Actor.
// If the user is the GM then use the current token they have selected.
//
static async getCurrentActor() {
let actor = null;

if (game.user.isGM) {
const controlledTokenCount = canvas.tokens.controlled.length;
if (controlledTokenCount > 0) {
if (controlledTokenCount !== 1) {
return ui.notifications.warn(
game.i18n.localize("SHADOWDARK.error.too_many_tokens_selected")
);
}
else {
actor = canvas.tokens.controlled[0].actor;
}
}
}
else {
actor = game.user.character;
}

return actor;
}


/**
* Creates de-duplicated lists of Selected and Unselected Items.
*
Expand Down
6 changes: 6 additions & 0 deletions system/templates/chat/general.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="shadowdark">
<div class="content">
<h3>{{title}}</h3>
<p>{{body}}</p>
</div>
</div>
8 changes: 8 additions & 0 deletions system/templates/chat/roll-request.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="shadowdark">
<div class="content">
<h3>{{title}}</h3>
<div style="text-align:center">
<p>{{body}}</p>
</div>
</div>
</div>

0 comments on commit f3acacc

Please sign in to comment.