Skip to content

Commit

Permalink
Merge pull request #13 from MangoFVTT/develop
Browse files Browse the repository at this point in the history
release/1.0.2
  • Loading branch information
MangoFVTT authored Sep 6, 2022
2 parents f441ce5 + 9afb809 commit 36a25f3
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 72 deletions.
4 changes: 4 additions & 0 deletions src/module/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ITEM_TYPE } from "../utils/item.js";
import { MODULE_SHORT } from "./const.js";

/**
* A set of configuration details that are globally used throughout the module.
* This currently includes valid item types for roll configuration and default configuration flags.
*/
CONFIG[`${MODULE_SHORT}`] = {
validItemTypes: [
ITEM_TYPE.WEAPON,
Expand Down
29 changes: 27 additions & 2 deletions src/module/quickroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { CoreUtility } from "../utils/core.js";
import { HOOK_CHAT_MESSAGE, HOOK_PROCESSED_ROLL, HOOK_RENDER } from "../utils/hooks.js";
import { FIELD_TYPE, RenderUtility } from "../utils/render.js";

/**
* Default quick roll parameters to fill in the parameter list that is passed on to field generation and rendering.
*/
let defaultParams = {
label: "",
forceCrit: false,
Expand Down Expand Up @@ -51,21 +54,37 @@ export class QuickRoll {
this.processed = false;
}

/**
* Sets the item associated with this quick roll.
* @param {Item} item The item to store in this quick roll.
*/
set item(item) {
this._item = item;
this.itemId = item?.id;
}

/**
* Gets the item associated with this quick roll.
* @returns {Item} The item stored in this quick roll.
*/
get item() {
return this._item;
}

/**
* Sets the actor associated with this quick roll.
* @param {Actor} actor The actor to store in this quick roll.
*/
set actor(actor) {
this._actor = actor;
this.actorId = actor?.id;
this.tokenId = actor?.token ? actor.token.uuid : null;
}

/**
* Gets the actor associated with this quick roll.
* @returns {Actor} The actor stored in this quick roll.
*/
get actor() {
return this._actor;
}
Expand Down Expand Up @@ -105,7 +124,7 @@ export class QuickRoll {

/**
* Renders HTML templates for the provided fields and combines them into a card.
* @returns Combined HTML chat data for all the roll fields.
* @returns {Promise<string>} Combined HTML chat data for all the roll fields.
* @private
*/
async _render() {
Expand Down Expand Up @@ -140,7 +159,7 @@ export class QuickRoll {

/**
* Allows this roll to be serialized into message flags.
* @returns A set of flags to attach to the chat message.
* @returns {any} A set of flags to attach to the chat message.
* @private
*/
_getFlags() {
Expand Down Expand Up @@ -173,6 +192,12 @@ export class QuickRoll {
return flags;
}

/**
* Function that concatenates damage rolls together into a single roll for use with the context menu
* apply damage, healing, half-damage, etc.
* @returns {Roll} A single roll compounding all the damage in the chat card into a single value.
* @private
*/
_getApplyDamageRoll() {
const noDamageRoll = new Roll("0").roll({ async: false });

Expand Down
4 changes: 4 additions & 0 deletions src/module/templates.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* A list of templates available for rendering.
* Used by the module for chat cards and item sheet renders.
*/
export const TEMPLATE = {
FULL_CARD: "rsr-full-card.html",
HEADER: "rsr-header.html",
Expand Down
4 changes: 2 additions & 2 deletions src/utils/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CoreUtility {
* Shorthand for both game.i18n.format() and game.i18n.localize() depending on whether data is supplied or not.
* @param {string} key The key string to localize for.
* @param {object?} data Optional data that if given will do a i18n.format() instead.
* @returns A localized string (with formatting if needed).
* @returns {string} A localized string (with formatting if needed).
*/
static localize(key, data = null) {
if (data) {
Expand Down Expand Up @@ -59,7 +59,7 @@ export class CoreUtility {

/**
* Checks a given data object to determine if it is an item or an actor.
* @param {*} dataObject
* @param {object} dataObject
* @returns {Item | Actor} A tuple containing an item and its actor if given an item, or just the actor otherwise.
*/
static resolveActorOrItem(dataObject) {
Expand Down
12 changes: 8 additions & 4 deletions src/utils/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ import { RollUtility } from "./roll.js";
import { SheetUtility } from "./sheet.js";
import { ItemUtility } from "./item.js";

// A list of module specific hooks that are fired throughout the module.
export const HOOK_LOADED = `${MODULE_SHORT}.loaded`;
export const HOOK_CHAT_MESSAGE = `${MODULE_SHORT}.chatMessage`;
export const HOOK_RENDER = `${MODULE_SHORT}.render`;
export const HOOK_PROCESSED_ROLL = `${MODULE_SHORT}.rollProcessed`;

/**
* Utility class to handle registering listeners for hooks needed throughout the module.
*/
export class HooksUtility {
/**
* Register all necessary hooks for the module as a whole.
Expand Down Expand Up @@ -41,7 +45,7 @@ export class HooksUtility {
CONFIG.DND5E.healingTypes,
{ recursive: false }
);

HooksUtility.registerChatHooks();

if (SettingsUtility.getSettingValue(SETTING_NAMES.QUICK_ITEM_ENABLED)) {
Expand All @@ -56,7 +60,7 @@ export class HooksUtility {
}

/**
* Register item specific hooks for module function.
* Register item specific hooks for module functionality.
*/
static registerItemHooks() {
Hooks.on("createItem", (item) => {
Expand All @@ -71,14 +75,14 @@ export class HooksUtility {
}

/**
* Register chat specific hooks for module function.
* Register chat specific hooks for module functionality.
*/
static registerChatHooks() {

}

/**
* Register sheet specific hooks for module function.
* Register sheet specific hooks for module functionality.
*/
static registerSheetHooks() {
Hooks.on("renderItemSheet5e", (app, html, data) => {
Expand Down
Loading

0 comments on commit 36a25f3

Please sign in to comment.