Update vtt types

This commit is contained in:
Johannes Loher 2021-07-07 19:22:35 +02:00
parent 623558dc78
commit c57960c153
24 changed files with 144 additions and 107 deletions

View file

@ -5,12 +5,13 @@
import { ModifiableDataBaseTotal } from "../common/common-data"; import { ModifiableDataBaseTotal } from "../common/common-data";
import { DS4 } from "../config"; import { DS4 } from "../config";
import { ItemType } from "../item/item-data-source"; import { getGame } from "../helpers";
import { DS4ArmorDataProperties, DS4ShieldDataProperties } from "../item/item-data-properties";
import { createCheckRoll } from "../rolls/check-factory";
import { isAttribute, isTrait } from "./actor-data-source";
import { Check } from "./actor-data-properties";
import { DS4Item } from "../item/item"; import { DS4Item } from "../item/item";
import { DS4ArmorDataProperties, DS4ShieldDataProperties } from "../item/item-data-properties";
import { ItemType } from "../item/item-data-source";
import { createCheckRoll } from "../rolls/check-factory";
import { Check } from "./actor-data-properties";
import { isAttribute, isTrait } from "./actor-data-source";
declare global { declare global {
interface DocumentClassConfig { interface DocumentClassConfig {
@ -307,10 +308,10 @@ export class DS4Actor extends Actor {
*/ */
async rollCheck(check: Check): Promise<void> { async rollCheck(check: Check): Promise<void> {
await createCheckRoll(this.data.data.checks[check], { await createCheckRoll(this.data.data.checks[check], {
rollMode: game.settings.get("core", "rollMode"), rollMode: getGame().settings.get("core", "rollMode"),
maximumCoupResult: this.data.data.rolling.maximumCoupResult, maximumCoupResult: this.data.data.rolling.maximumCoupResult,
minimumFumbleResult: this.data.data.rolling.minimumFumbleResult, minimumFumbleResult: this.data.data.rolling.minimumFumbleResult,
flavor: game.i18n.format("DS4.ActorCheckFlavor", { actor: this.name, check: DS4.i18n.checks[check] }), flavor: getGame().i18n.format("DS4.ActorCheckFlavor", { actor: this.name, check: DS4.i18n.checks[check] }),
}); });
} }
@ -322,10 +323,10 @@ export class DS4Actor extends Actor {
const { attribute, trait } = await this.selectAttributeAndTrait(); const { attribute, trait } = await this.selectAttributeAndTrait();
const checkTargetNumber = this.data.data.attributes[attribute].total + this.data.data.traits[trait].total; const checkTargetNumber = this.data.data.attributes[attribute].total + this.data.data.traits[trait].total;
await createCheckRoll(checkTargetNumber, { await createCheckRoll(checkTargetNumber, {
rollMode: game.settings.get("core", "rollMode"), rollMode: getGame().settings.get("core", "rollMode"),
maximumCoupResult: this.data.data.rolling.maximumCoupResult, maximumCoupResult: this.data.data.rolling.maximumCoupResult,
minimumFumbleResult: this.data.data.rolling.minimumFumbleResult, minimumFumbleResult: this.data.data.rolling.minimumFumbleResult,
flavor: game.i18n.format("DS4.ActorGenericCheckFlavor", { flavor: getGame().i18n.format("DS4.ActorGenericCheckFlavor", {
actor: this.name, actor: this.name,
attribute: DS4.i18n.attributes[attribute], attribute: DS4.i18n.attributes[attribute],
trait: DS4.i18n.traits[trait], trait: DS4.i18n.traits[trait],
@ -340,27 +341,27 @@ export class DS4Actor extends Actor {
const attributeIdentifier = "attribute-trait-selection-attribute"; const attributeIdentifier = "attribute-trait-selection-attribute";
const traitIdentifier = "attribute-trait-selection-trait"; const traitIdentifier = "attribute-trait-selection-trait";
return Dialog.prompt({ return Dialog.prompt({
title: game.i18n.localize("DS4.DialogAttributeTraitSelection"), title: getGame().i18n.localize("DS4.DialogAttributeTraitSelection"),
content: await renderTemplate("systems/ds4/templates/dialogs/simple-select-form.hbs", { content: await renderTemplate("systems/ds4/templates/dialogs/simple-select-form.hbs", {
selects: [ selects: [
{ {
label: game.i18n.localize("DS4.Attribute"), label: getGame().i18n.localize("DS4.Attribute"),
identifier: attributeIdentifier, identifier: attributeIdentifier,
options: DS4.i18n.attributes, options: DS4.i18n.attributes,
}, },
{ {
label: game.i18n.localize("DS4.Trait"), label: getGame().i18n.localize("DS4.Trait"),
identifier: traitIdentifier, identifier: traitIdentifier,
options: DS4.i18n.traits, options: DS4.i18n.traits,
}, },
], ],
}), }),
label: game.i18n.localize("DS4.GenericOkButton"), label: getGame().i18n.localize("DS4.GenericOkButton"),
callback: (html) => { callback: (html) => {
const selectedAttribute = html.find(`#${attributeIdentifier}`).val(); const selectedAttribute = html.find(`#${attributeIdentifier}`).val();
if (!isAttribute(selectedAttribute)) { if (!isAttribute(selectedAttribute)) {
throw new Error( throw new Error(
game.i18n.format("DS4.ErrorUnexpectedAttribute", { getGame().i18n.format("DS4.ErrorUnexpectedAttribute", {
actualAttribute: selectedAttribute, actualAttribute: selectedAttribute,
expectedTypes: Object.keys(DS4.i18n.attributes) expectedTypes: Object.keys(DS4.i18n.attributes)
.map((attribute) => `'${attribute}'`) .map((attribute) => `'${attribute}'`)
@ -371,7 +372,7 @@ export class DS4Actor extends Actor {
const selectedTrait = html.find(`#${traitIdentifier}`).val(); const selectedTrait = html.find(`#${traitIdentifier}`).val();
if (!isTrait(selectedTrait)) { if (!isTrait(selectedTrait)) {
throw new Error( throw new Error(
game.i18n.format("DS4.ErrorUnexpectedTrait", { getGame().i18n.format("DS4.ErrorUnexpectedTrait", {
actualTrait: selectedTrait, actualTrait: selectedTrait,
expectedTypes: Object.keys(DS4.i18n.traits) expectedTypes: Object.keys(DS4.i18n.traits)
.map((attribute) => `'${attribute}'`) .map((attribute) => `'${attribute}'`)

View file

@ -7,7 +7,7 @@
import { ModifiableDataBaseTotal } from "../../common/common-data"; import { ModifiableDataBaseTotal } from "../../common/common-data";
import { DS4 } from "../../config"; import { DS4 } from "../../config";
import { getCanvas } from "../../helpers"; import { getCanvas, getGame } from "../../helpers";
import { DS4Item } from "../../item/item"; import { DS4Item } from "../../item/item";
import { DS4Settings, getDS4Settings } from "../../settings"; import { DS4Settings, getDS4Settings } from "../../settings";
import notifications from "../../ui/notifications"; import notifications from "../../ui/notifications";
@ -81,9 +81,11 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
} }
protected getTooltipForValue(value: ModifiableDataBaseTotal<number>): string { protected getTooltipForValue(value: ModifiableDataBaseTotal<number>): string {
return `${value.base} (${game.i18n.localize("DS4.TooltipBaseValue")}) + ${value.mod} (${game.i18n.localize( return `${value.base} (${getGame().i18n.localize("DS4.TooltipBaseValue")}) + ${
"DS4.TooltipModifier", value.mod
)}) ${game.i18n.localize("DS4.TooltipEffects")} ${value.total}`; } (${getGame().i18n.localize("DS4.TooltipModifier")}) ${getGame().i18n.localize("DS4.TooltipEffects")} ${
value.total
}`;
} }
/** @override */ /** @override */
@ -102,10 +104,10 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
const id = li.data("itemId"); const id = li.data("itemId");
const item = this.actor.getEmbeddedDocument("Item", id) as DS4Item; // TODO: Improve in upstream const item = this.actor.getEmbeddedDocument("Item", id) as DS4Item; // TODO: Improve in upstream
if (!item) { if (!item) {
throw new Error(game.i18n.format("DS4.ErrorActorDoesNotHaveItem", { id, actor: this.actor.name })); throw new Error(getGame().i18n.format("DS4.ErrorActorDoesNotHaveItem", { id, actor: this.actor.name }));
} }
if (!item.sheet) { if (!item.sheet) {
throw new Error(game.i18n.localize("DS4.ErrorUnexpectedError")); throw new Error(getGame().i18n.localize("DS4.ErrorUnexpectedError"));
} }
item.sheet.render(true); item.sheet.render(true);
}); });
@ -257,7 +259,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
const check = target.dataset.check; const check = target.dataset.check;
if (!check) return super._onDragStart(event); if (!check) return super._onDragStart(event);
if (!isCheck(check)) throw new Error(game.i18n.format("DS4.ErrorCannotDragMissingCheck", { check })); if (!isCheck(check)) throw new Error(getGame().i18n.format("DS4.ErrorCannotDragMissingCheck", { check }));
const dragData = { const dragData = {
actorId: this.actor.id, actorId: this.actor.id,
@ -275,7 +277,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
const item = await DS4Item.fromDropData(data); const item = await DS4Item.fromDropData(data);
if (item && !this.actor.canOwnItemType(item.data.type)) { if (item && !this.actor.canOwnItemType(item.data.type)) {
notifications.warn( notifications.warn(
game.i18n.format("DS4.WarningActorCannotOwnItem", { getGame().i18n.format("DS4.WarningActorCannotOwnItem", {
actorName: this.actor.name, actorName: this.actor.name,
actorType: this.actor.data.type, actorType: this.actor.data.type,
itemName: item.name, itemName: item.name,

View file

@ -4,7 +4,14 @@
export function getCanvas(): Canvas { export function getCanvas(): Canvas {
if (!(canvas instanceof Canvas) || !canvas.ready) { if (!(canvas instanceof Canvas) || !canvas.ready) {
throw new Error(game.i18n.localize("DS4.ErrorCanvasIsNotInitialized")); throw new Error(getGame().i18n.localize("DS4.ErrorCanvasIsNotInitialized"));
} }
return canvas; return canvas;
} }
export function getGame(): Game {
if (!(game instanceof Game)) {
throw new Error("Game is not initialized yet."); // Cannot localize this as we would need to access game to do this.
}
return game;
}

View file

@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { isCheck } from "../actor/actor-data-properties"; import { isCheck } from "../actor/actor-data-properties";
import { getGame } from "../helpers";
import { DS4Item } from "../item/item"; import { DS4Item } from "../item/item";
import { createRollCheckMacro } from "../macros/roll-check"; import { createRollCheckMacro } from "../macros/roll-check";
import { createRollItemMacro } from "../macros/roll-item"; import { createRollItemMacro } from "../macros/roll-item";
@ -13,13 +14,15 @@ export default function registerForHotbarDropHook(): void {
switch (data.type) { switch (data.type) {
case "Item": { case "Item": {
if (!isItemDropData(data) || !("data" in data)) { if (!isItemDropData(data) || !("data" in data)) {
return notifications.warn(game.i18n.localize("DS4.WarningMacrosCanOnlyBeCreatedForOwnedItems")); return notifications.warn(
getGame().i18n.localize("DS4.WarningMacrosCanOnlyBeCreatedForOwnedItems"),
);
} }
const itemData = data.data; const itemData = data.data;
if (!DS4Item.rollableItemTypes.includes(itemData.type)) { if (!DS4Item.rollableItemTypes.includes(itemData.type)) {
return notifications.warn( return notifications.warn(
game.i18n.format("DS4.WarningItemIsNotRollable", { getGame().i18n.format("DS4.WarningItemIsNotRollable", {
name: itemData.name, name: itemData.name,
id: itemData._id, id: itemData._id,
type: itemData.type, type: itemData.type,
@ -30,7 +33,7 @@ export default function registerForHotbarDropHook(): void {
} }
case "Check": { case "Check": {
if (!("data" in data) || typeof data.data !== "string" || !isCheck(data.data)) { if (!("data" in data) || typeof data.data !== "string" || !isCheck(data.data)) {
return notifications.warn(game.i18n.localize("DS4.WarningInvalidCheckDropped")); return notifications.warn(getGame().i18n.localize("DS4.WarningInvalidCheckDropped"));
} }
return createRollCheckMacro(data.data, slot); return createRollCheckMacro(data.data, slot);
} }

View file

@ -10,6 +10,7 @@ import { DS4CreatureActorSheet } from "../actor/sheets/creature-sheet";
import { DS4 } from "../config"; import { DS4 } from "../config";
import registerHandlebarsHelpers from "../handlebars/handlebars-helpers"; import registerHandlebarsHelpers from "../handlebars/handlebars-helpers";
import registerHandlebarsPartials from "../handlebars/handlebars-partials"; import registerHandlebarsPartials from "../handlebars/handlebars-partials";
import { getGame } from "../helpers";
import { DS4Item } from "../item/item"; import { DS4Item } from "../item/item";
import { DS4ItemSheet } from "../item/item-sheet"; import { DS4ItemSheet } from "../item/item-sheet";
import logger from "../logger"; import logger from "../logger";
@ -28,7 +29,7 @@ export default function registerForInitHook(): void {
async function init() { async function init() {
logger.info(`Initializing the DS4 Game System\n${DS4.ASCII}`); logger.info(`Initializing the DS4 Game System\n${DS4.ASCII}`);
game.ds4 = { getGame().ds4 = {
DS4Actor, DS4Actor,
DS4Item, DS4Item,
DS4, DS4,

View file

@ -6,6 +6,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4 } from "../config"; import { DS4 } from "../config";
import { getGame } from "../helpers";
export default function registerForSetupHooks(): void { export default function registerForSetupHooks(): void {
Hooks.once("setup", () => { Hooks.once("setup", () => {
@ -21,7 +22,7 @@ function localizeAndSortConfigObjects() {
const localizeObject = <T extends { [s: string]: string }>(obj: T, sort = true): T => { const localizeObject = <T extends { [s: string]: string }>(obj: T, sort = true): T => {
const localized = Object.entries(obj).map(([key, value]) => { const localized = Object.entries(obj).map(([key, value]) => {
return [key, game.i18n.localize(value)]; return [key, getGame().i18n.localize(value)];
}); });
if (sort) localized.sort((a, b) => a[1].localeCompare(b[1])); if (sort) localized.sort((a, b) => a[1].localeCompare(b[1]));
return Object.fromEntries(localized); return Object.fromEntries(localized);

View file

@ -5,6 +5,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4 } from "../config"; import { DS4 } from "../config";
import { getGame } from "../helpers";
import notifications from "../ui/notifications"; import notifications from "../ui/notifications";
import { isDS4ItemDataTypePhysical } from "./item-data-source"; import { isDS4ItemDataTypePhysical } from "./item-data-source";
@ -70,7 +71,7 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData>
event.preventDefault(); event.preventDefault();
if (this.item.isOwned) { if (this.item.isOwned) {
return notifications.warn(game.i18n.localize("DS4.WarningManageActiveEffectOnOwnedItem")); return notifications.warn(getGame().i18n.localize("DS4.WarningManageActiveEffectOnOwnedItem"));
} }
const a = event.currentTarget; const a = event.currentTarget;
const li = $(a).parents(".effect"); const li = $(a).parents(".effect");
@ -82,7 +83,9 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData>
const id = li.data("effectId"); const id = li.data("effectId");
const effect = this.item.effects.get(id); const effect = this.item.effects.get(id);
if (!effect) { if (!effect) {
throw new Error(game.i18n.format("DS4.ErrorItemDoesNotHaveEffect", { id, item: this.item.name })); throw new Error(
getGame().i18n.format("DS4.ErrorItemDoesNotHaveEffect", { id, item: this.item.name }),
);
} }
return effect.sheet.render(true); return effect.sheet.render(true);
case "delete": { case "delete": {

View file

@ -4,6 +4,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4 } from "../config"; import { DS4 } from "../config";
import { getGame } from "../helpers";
import { createCheckRoll } from "../rolls/check-factory"; import { createCheckRoll } from "../rolls/check-factory";
import notifications from "../ui/notifications"; import notifications from "../ui/notifications";
import { AttackType, ItemType } from "./item-data-source"; import { AttackType, ItemType } from "./item-data-source";
@ -71,14 +72,16 @@ export class DS4Item extends Item {
case "spell": case "spell":
return this.rollSpell(); return this.rollSpell();
default: default:
throw new Error(game.i18n.format("DS4.ErrorRollingForItemTypeNotPossible", { type: this.data.type })); throw new Error(
getGame().i18n.format("DS4.ErrorRollingForItemTypeNotPossible", { type: this.data.type }),
);
} }
} }
protected async rollWeapon(): Promise<void> { protected async rollWeapon(): Promise<void> {
if (!(this.data.type === "weapon")) { if (!(this.data.type === "weapon")) {
throw new Error( throw new Error(
game.i18n.format("DS4.ErrorWrongItemType", { getGame().i18n.format("DS4.ErrorWrongItemType", {
actualType: this.data.type, actualType: this.data.type,
expectedType: "weapon", expectedType: "weapon",
id: this.id, id: this.id,
@ -89,7 +92,7 @@ export class DS4Item extends Item {
if (!this.data.data.equipped) { if (!this.data.data.equipped) {
return notifications.warn( return notifications.warn(
game.i18n.format("DS4.WarningItemMustBeEquippedToBeRolled", { getGame().i18n.format("DS4.WarningItemMustBeEquippedToBeRolled", {
name: this.name, name: this.name,
id: this.id, id: this.id,
type: this.data.type, type: this.data.type,
@ -98,7 +101,7 @@ export class DS4Item extends Item {
} }
if (!this.actor) { if (!this.actor) {
throw new Error(game.i18n.format("DS4.ErrorCannotRollUnownedItem", { name: this.name, id: this.id })); throw new Error(getGame().i18n.format("DS4.ErrorCannotRollUnownedItem", { name: this.name, id: this.id }));
} }
const ownerDataData = this.actor.data.data; const ownerDataData = this.actor.data.data;
@ -107,17 +110,17 @@ export class DS4Item extends Item {
const checkTargetNumber = ownerDataData.combatValues[combatValue].total + weaponBonus; const checkTargetNumber = ownerDataData.combatValues[combatValue].total + weaponBonus;
await createCheckRoll(checkTargetNumber, { await createCheckRoll(checkTargetNumber, {
rollMode: game.settings.get("core", "rollMode"), rollMode: getGame().settings.get("core", "rollMode"),
maximumCoupResult: ownerDataData.rolling.maximumCoupResult, maximumCoupResult: ownerDataData.rolling.maximumCoupResult,
minimumFumbleResult: ownerDataData.rolling.minimumFumbleResult, minimumFumbleResult: ownerDataData.rolling.minimumFumbleResult,
flavor: game.i18n.format("DS4.ItemWeaponCheckFlavor", { actor: this.actor.name, weapon: this.name }), flavor: getGame().i18n.format("DS4.ItemWeaponCheckFlavor", { actor: this.actor.name, weapon: this.name }),
}); });
} }
protected async rollSpell(): Promise<void> { protected async rollSpell(): Promise<void> {
if (!(this.data.type === "spell")) { if (!(this.data.type === "spell")) {
throw new Error( throw new Error(
game.i18n.format("DS4.ErrorWrongItemType", { getGame().i18n.format("DS4.ErrorWrongItemType", {
actualType: this.data.type, actualType: this.data.type,
expectedType: "spell", expectedType: "spell",
id: this.id, id: this.id,
@ -128,7 +131,7 @@ export class DS4Item extends Item {
if (!this.data.data.equipped) { if (!this.data.data.equipped) {
return notifications.warn( return notifications.warn(
game.i18n.format("DS4.WarningItemMustBeEquippedToBeRolled", { getGame().i18n.format("DS4.WarningItemMustBeEquippedToBeRolled", {
name: this.name, name: this.name,
id: this.id, id: this.id,
type: this.data.type, type: this.data.type,
@ -137,14 +140,14 @@ export class DS4Item extends Item {
} }
if (!this.actor) { if (!this.actor) {
throw new Error(game.i18n.format("DS4.ErrorCannotRollUnownedItem", { name: this.name, id: this.id })); throw new Error(getGame().i18n.format("DS4.ErrorCannotRollUnownedItem", { name: this.name, id: this.id }));
} }
const ownerDataData = this.actor.data.data; const ownerDataData = this.actor.data.data;
const spellBonus = Number.isNumeric(this.data.data.bonus) ? parseInt(this.data.data.bonus) : undefined; const spellBonus = Number.isNumeric(this.data.data.bonus) ? parseInt(this.data.data.bonus) : undefined;
if (spellBonus === undefined) { if (spellBonus === undefined) {
notifications.info( notifications.info(
game.i18n.format("DS4.InfoManuallyEnterSpellBonus", { getGame().i18n.format("DS4.InfoManuallyEnterSpellBonus", {
name: this.name, name: this.name,
spellBonus: this.data.data.bonus, spellBonus: this.data.data.bonus,
}), }),
@ -154,10 +157,10 @@ export class DS4Item extends Item {
const checkTargetNumber = ownerDataData.combatValues[spellType].total + (spellBonus ?? 0); const checkTargetNumber = ownerDataData.combatValues[spellType].total + (spellBonus ?? 0);
await createCheckRoll(checkTargetNumber, { await createCheckRoll(checkTargetNumber, {
rollMode: game.settings.get("core", "rollMode"), rollMode: getGame().settings.get("core", "rollMode"),
maximumCoupResult: ownerDataData.rolling.maximumCoupResult, maximumCoupResult: ownerDataData.rolling.maximumCoupResult,
minimumFumbleResult: ownerDataData.rolling.minimumFumbleResult, minimumFumbleResult: ownerDataData.rolling.minimumFumbleResult,
flavor: game.i18n.format("DS4.ItemSpellCheckFlavor", { actor: this.actor.name, spell: this.name }), flavor: getGame().i18n.format("DS4.ItemSpellCheckFlavor", { actor: this.actor.name, spell: this.name }),
}); });
} }
@ -166,22 +169,22 @@ export class DS4Item extends Item {
const { melee, ranged } = { ...DS4.i18n.attackTypes }; const { melee, ranged } = { ...DS4.i18n.attackTypes };
const identifier = "attack-type-selection"; const identifier = "attack-type-selection";
return Dialog.prompt({ return Dialog.prompt({
title: game.i18n.localize("DS4.DialogAttackTypeSelection"), title: getGame().i18n.localize("DS4.DialogAttackTypeSelection"),
content: await renderTemplate("systems/ds4/templates/dialogs/simple-select-form.hbs", { content: await renderTemplate("systems/ds4/templates/dialogs/simple-select-form.hbs", {
selects: [ selects: [
{ {
label: game.i18n.localize("DS4.AttackType"), label: getGame().i18n.localize("DS4.AttackType"),
identifier, identifier,
options: { melee, ranged }, options: { melee, ranged },
}, },
], ],
}), }),
label: game.i18n.localize("DS4.GenericOkButton"), label: getGame().i18n.localize("DS4.GenericOkButton"),
callback: (html) => { callback: (html) => {
const selectedAttackType = html.find(`#${identifier}`).val(); const selectedAttackType = html.find(`#${identifier}`).val();
if (selectedAttackType !== "melee" && selectedAttackType !== "ranged") { if (selectedAttackType !== "melee" && selectedAttackType !== "ranged") {
throw new Error( throw new Error(
game.i18n.format("DS4.ErrorUnexpectedAttackType", { getGame().i18n.format("DS4.ErrorUnexpectedAttackType", {
actualType: selectedAttackType, actualType: selectedAttackType,
expectedTypes: "'melee', 'ranged'", expectedTypes: "'melee', 'ranged'",
}), }),

View file

@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4Actor } from "../actor/actor"; import { DS4Actor } from "../actor/actor";
import { getCanvas } from "../helpers"; import { getCanvas, getGame } from "../helpers";
/** /**
* Gets the currently active actor based on how {@link ChatMessage} determines * Gets the currently active actor based on how {@link ChatMessage} determines
@ -18,7 +18,7 @@ export function getActiveActor(): DS4Actor | undefined {
return speakerToken.actor ?? undefined; return speakerToken.actor ?? undefined;
} }
const speakerActor = speaker.actor ? game.actors?.get(speaker.actor) : undefined; const speakerActor = speaker.actor ? getGame().actors?.get(speaker.actor) : undefined;
if (speakerActor) { if (speakerActor) {
return speakerActor; return speakerActor;
} }

View file

@ -4,6 +4,7 @@
import { Check } from "../actor/actor-data-properties"; import { Check } from "../actor/actor-data-properties";
import { DS4 } from "../config"; import { DS4 } from "../config";
import { getGame } from "../helpers";
import notifications from "../ui/notifications"; import notifications from "../ui/notifications";
import { getActiveActor } from "./helpers"; import { getActiveActor } from "./helpers";
@ -15,13 +16,15 @@ import { getActiveActor } from "./helpers";
*/ */
export async function createRollCheckMacro(check: Check, slot: string): Promise<void> { export async function createRollCheckMacro(check: Check, slot: string): Promise<void> {
const macro = await getOrCreateRollCheckMacro(check); const macro = await getOrCreateRollCheckMacro(check);
game.user?.assignHotbarMacro(macro ?? null, slot); getGame().user?.assignHotbarMacro(macro ?? null, slot);
} }
async function getOrCreateRollCheckMacro(check: Check): Promise<Macro | undefined> { async function getOrCreateRollCheckMacro(check: Check): Promise<Macro | undefined> {
const command = `game.ds4.macros.rollCheck("${check}");`; const command = `getGame().ds4.macros.rollCheck("${check}");`;
const existingMacro = game.macros?.find((m) => m.name === DS4.i18n.checks[check] && m.data.command === command); const existingMacro = getGame().macros?.find(
(m) => m.name === DS4.i18n.checks[check] && m.data.command === command,
);
if (existingMacro) { if (existingMacro) {
return existingMacro; return existingMacro;
} }
@ -44,7 +47,7 @@ async function getOrCreateRollCheckMacro(check: Check): Promise<Macro | undefine
export async function rollCheck(check: Check): Promise<void> { export async function rollCheck(check: Check): Promise<void> {
const actor = getActiveActor(); const actor = getActiveActor();
if (!actor) { if (!actor) {
return notifications.warn(game.i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro")); return notifications.warn(getGame().i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro"));
} }
return actor.rollCheck(check).catch((e) => notifications.error(e, { log: true })); return actor.rollCheck(check).catch((e) => notifications.error(e, { log: true }));

View file

@ -2,15 +2,17 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers";
import notifications from "../ui/notifications"; import notifications from "../ui/notifications";
import { getActiveActor } from "./helpers"; import { getActiveActor } from "./helpers";
/** /**
* Executes the roll generic check macro. * Executes the roll generic check macro.
*/ */
export async function rollGenericCheck(): Promise<void> { export async function rollGenericCheck(): Promise<void> {
const actor = getActiveActor(); const actor = getActiveActor();
if (!actor) { if (!actor) {
return notifications.warn(game.i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro")); return notifications.warn(getGame().i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro"));
} }
return actor.rollGenericCheck().catch((e) => notifications.error(e, { log: true })); return actor.rollGenericCheck().catch((e) => notifications.error(e, { log: true }));

View file

@ -2,6 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers";
import notifications from "../ui/notifications"; import notifications from "../ui/notifications";
import { getActiveActor } from "./helpers"; import { getActiveActor } from "./helpers";
@ -13,13 +14,13 @@ import { getActiveActor } from "./helpers";
*/ */
export async function createRollItemMacro(itemData: foundry.data.ItemData["_source"], slot: string): Promise<void> { export async function createRollItemMacro(itemData: foundry.data.ItemData["_source"], slot: string): Promise<void> {
const macro = await getOrCreateRollItemMacro(itemData); const macro = await getOrCreateRollItemMacro(itemData);
game.user?.assignHotbarMacro(macro ?? null, slot); getGame().user?.assignHotbarMacro(macro ?? null, slot);
} }
async function getOrCreateRollItemMacro(itemData: foundry.data.ItemData["_source"]): Promise<Macro | undefined> { async function getOrCreateRollItemMacro(itemData: foundry.data.ItemData["_source"]): Promise<Macro | undefined> {
const command = `game.ds4.macros.rollItem("${itemData._id}");`; const command = `getGame().ds4.macros.rollItem("${itemData._id}");`;
const existingMacro = game.macros?.find((m) => m.name === itemData.name && m.data.command === command); const existingMacro = getGame().macros?.find((m) => m.name === itemData.name && m.data.command === command);
if (existingMacro) { if (existingMacro) {
return existingMacro; return existingMacro;
} }
@ -42,13 +43,13 @@ async function getOrCreateRollItemMacro(itemData: foundry.data.ItemData["_source
export async function rollItem(itemId: string): Promise<void> { export async function rollItem(itemId: string): Promise<void> {
const actor = getActiveActor(); const actor = getActiveActor();
if (!actor) { if (!actor) {
return notifications.warn(game.i18n.localize("DS4.WarningMustControlActorToUseRollItemMacro")); return notifications.warn(getGame().i18n.localize("DS4.WarningMustControlActorToUseRollItemMacro"));
} }
const item = actor.items?.get(itemId); const item = actor.items?.get(itemId);
if (!item) { if (!item) {
return notifications.warn( return notifications.warn(
game.i18n.format("DS4.WarningControlledActorDoesNotHaveItem", { getGame().i18n.format("DS4.WarningControlledActorDoesNotHaveItem", {
actorName: actor.name, actorName: actor.name,
actorId: actor.id, actorId: actor.id,
itemId, itemId,

View file

@ -2,25 +2,25 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "./helpers";
import logger from "./logger"; import logger from "./logger";
import { migrate as migrate001 } from "./migrations/001"; import { migrate as migrate001 } from "./migrations/001";
// import { migrate as migrate002 } from "./migrations/002"; // import { migrate as migrate002 } from "./migrations/002";
// import { migrate as migrate003 } from "./migrations/003"; // import { migrate as migrate003 } from "./migrations/003";
// import { migrate as migrate004 } from "./migrations/004"; // import { migrate as migrate004 } from "./migrations/004";
import notifications from "./ui/notifications"; import notifications from "./ui/notifications";
async function migrate(): Promise<void> { async function migrate(): Promise<void> {
if (!game.user?.isGM) { if (!getGame().user?.isGM) {
return; return;
} }
const oldMigrationVersion = game.settings.get("ds4", "systemMigrationVersion"); const oldMigrationVersion = getGame().settings.get("ds4", "systemMigrationVersion");
const targetMigrationVersion = migrations.length; const targetMigrationVersion = migrations.length;
if (isFirstWorldStart(oldMigrationVersion)) { if (isFirstWorldStart(oldMigrationVersion)) {
game.settings.set("ds4", "systemMigrationVersion", targetMigrationVersion); getGame().settings.set("ds4", "systemMigrationVersion", targetMigrationVersion);
return; return;
} }
@ -28,7 +28,7 @@ async function migrate(): Promise<void> {
} }
async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion: number): Promise<void> { async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion: number): Promise<void> {
if (!game.user?.isGM) { if (!getGame().user?.isGM) {
return; return;
} }
@ -36,7 +36,7 @@ async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion
if (migrationsToExecute.length > 0) { if (migrationsToExecute.length > 0) {
notifications.info( notifications.info(
game.i18n.format("DS4.InfoSystemUpdateStart", { getGame().i18n.format("DS4.InfoSystemUpdateStart", {
currentVersion: oldMigrationVersion, currentVersion: oldMigrationVersion,
targetVersion: targetMigrationVersion, targetVersion: targetMigrationVersion,
}), }),
@ -48,10 +48,10 @@ async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion
logger.info("executing migration script ", currentMigrationVersion); logger.info("executing migration script ", currentMigrationVersion);
try { try {
await migration(); await migration();
game.settings.set("ds4", "systemMigrationVersion", currentMigrationVersion); getGame().settings.set("ds4", "systemMigrationVersion", currentMigrationVersion);
} catch (err) { } catch (err) {
notifications.error( notifications.error(
game.i18n.format("DS4.ErrorDuringMigration", { getGame().i18n.format("DS4.ErrorDuringMigration", {
currentVersion: oldMigrationVersion, currentVersion: oldMigrationVersion,
targetVersion: targetMigrationVersion, targetVersion: targetMigrationVersion,
migrationVersion: currentMigrationVersion, migrationVersion: currentMigrationVersion,
@ -65,7 +65,7 @@ async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion
} }
notifications.info( notifications.info(
game.i18n.format("DS4.InfoSystemUpdateCompleted", { getGame().i18n.format("DS4.InfoSystemUpdateCompleted", {
currentVersion: oldMigrationVersion, currentVersion: oldMigrationVersion,
targetVersion: targetMigrationVersion, targetVersion: targetMigrationVersion,
}), }),

View file

@ -2,10 +2,11 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers";
import logger from "../logger"; import logger from "../logger";
export async function migrate(): Promise<void> { export async function migrate(): Promise<void> {
for (const a of game.actors?.contents ?? []) { for (const a of getGame().actors?.contents ?? []) {
const updateData = getActorUpdateData(); const updateData = getActorUpdateData();
logger.info(`Migrating actor ${a.name}`); logger.info(`Migrating actor ${a.name}`);
await a.update(updateData); await a.update(updateData);

View file

@ -12,7 +12,7 @@ import logger from "../logger";
// } // }
// async function migrateItems() { // async function migrateItems() {
// for (const item of game.items?.contents ?? []) { // for (const item of getGame().items?.contents ?? []) {
// try { // try {
// const updateData = getItemUpdateData(item.toObject()); // const updateData = getItemUpdateData(item.toObject());
// if (updateData) { // if (updateData) {
@ -32,7 +32,7 @@ import logger from "../logger";
// } // }
// async function migrateActors() { // async function migrateActors() {
// for (const actor of game.actors?.contents ?? []) { // for (const actor of getGame().actors?.contents ?? []) {
// try { // try {
// const updateData = getActorUpdateData(actor.toObject()); // const updateData = getActorUpdateData(actor.toObject());
// if (updateData) { // if (updateData) {
@ -61,7 +61,7 @@ import logger from "../logger";
// } // }
// async function migrateScenes() { // async function migrateScenes() {
// for (const scene of game.scenes?.contents ?? []) { // for (const scene of getGame().scenes?.contents ?? []) {
// try { // try {
// const updateData = getSceneUpdateData(scene.toObject()); // const updateData = getSceneUpdateData(scene.toObject());
// if (updateData) { // if (updateData) {
@ -81,7 +81,7 @@ import logger from "../logger";
// const tokens = scene.tokens.map((tokenData: foundry.data.TokenData["_source"]) => { // const tokens = scene.tokens.map((tokenData: foundry.data.TokenData["_source"]) => {
// if (!tokenData.actorId || tokenData.actorLink) { // if (!tokenData.actorId || tokenData.actorLink) {
// tokenData.actorData = {}; // tokenData.actorData = {};
// } else if (!game.actors?.has(tokenData.actorId)) { // } else if (!getGame().actors?.has(tokenData.actorId)) {
// tokenData.actorId = null; // tokenData.actorId = null;
// tokenData.actorData = {}; // tokenData.actorData = {};
// } else if (!tokenData.actorLink) { // } else if (!tokenData.actorLink) {
@ -111,7 +111,7 @@ import logger from "../logger";
// } // }
// async function migrateCompendiums() { // async function migrateCompendiums() {
// for (const compendium of game.packs ?? []) { // for (const compendium of getGame().packs ?? []) {
// if (compendium.metadata.package !== "world") continue; // if (compendium.metadata.package !== "world") continue;
// if (!["Actor", "Item", "Scene"].includes(compendium.metadata.entity)) continue; // if (!["Actor", "Item", "Scene"].includes(compendium.metadata.entity)) continue;
// await migrateCompendium(compendium); // await migrateCompendium(compendium);

View file

@ -12,7 +12,7 @@ import logger from "../logger";
// } // }
// async function migrateItems() { // async function migrateItems() {
// for (const item of game.items?.entities ?? []) { // for (const item of getGame().items?.entities ?? []) {
// try { // try {
// const updateData = getItemUpdateData(item._data); // const updateData = getItemUpdateData(item._data);
// if (updateData) { // if (updateData) {
@ -36,7 +36,7 @@ import logger from "../logger";
// } // }
// async function migrateActors() { // async function migrateActors() {
// for (const actor of game.actors?.entities ?? []) { // for (const actor of getGame().actors?.entities ?? []) {
// try { // try {
// const updateData = getActorUpdateData(actor._data); // const updateData = getActorUpdateData(actor._data);
// if (updateData) { // if (updateData) {
@ -65,7 +65,7 @@ import logger from "../logger";
// } // }
// async function migrateScenes() { // async function migrateScenes() {
// for (const scene of game.scenes?.entities ?? []) { // for (const scene of getGame().scenes?.entities ?? []) {
// try { // try {
// const updateData = getSceneUpdateData(scene._data); // const updateData = getSceneUpdateData(scene._data);
// if (updateData) { // if (updateData) {
@ -104,7 +104,7 @@ import logger from "../logger";
// } // }
// async function migrateCompendiums() { // async function migrateCompendiums() {
// for (const compendium of game.packs ?? []) { // for (const compendium of getGame().packs ?? []) {
// if (compendium.metadata.package !== "world") continue; // if (compendium.metadata.package !== "world") continue;
// if (!["Actor", "Item", "Scene"].includes(compendium.metadata.entity)) continue; // if (!["Actor", "Item", "Scene"].includes(compendium.metadata.entity)) continue;
// await migrateCompendium(compendium); // await migrateCompendium(compendium);

View file

@ -13,7 +13,7 @@ import logger from "../logger";
// } // }
// async function migrateItems() { // async function migrateItems() {
// for (const item of game.items?.entities ?? []) { // for (const item of getGame().items?.entities ?? []) {
// try { // try {
// const updateData = getItemUpdateData(item._data); // const updateData = getItemUpdateData(item._data);
// if (updateData) { // if (updateData) {
@ -40,7 +40,7 @@ import logger from "../logger";
// } // }
// async function migrateActors() { // async function migrateActors() {
// for (const actor of game.actors?.entities ?? []) { // for (const actor of getGame().actors?.entities ?? []) {
// try { // try {
// const updateData = getActorUpdateData(actor._data); // const updateData = getActorUpdateData(actor._data);
// if (updateData) { // if (updateData) {
@ -76,7 +76,7 @@ import logger from "../logger";
// } // }
// async function migrateScenes() { // async function migrateScenes() {
// for (const scene of game.scenes?.entities ?? []) { // for (const scene of getGame().scenes?.entities ?? []) {
// try { // try {
// const updateData = getSceneUpdateData(scene._data); // const updateData = getSceneUpdateData(scene._data);
// if (updateData) { // if (updateData) {
@ -115,7 +115,7 @@ import logger from "../logger";
// } // }
// async function migrateCompendiums() { // async function migrateCompendiums() {
// for (const compendium of game.packs ?? []) { // for (const compendium of getGame().packs ?? []) {
// if (compendium.metadata.package !== "world") continue; // if (compendium.metadata.package !== "world") continue;
// if (!["Actor", "Item", "Scene"].includes(compendium.metadata.entity)) continue; // if (!["Actor", "Item", "Scene"].includes(compendium.metadata.entity)) continue;
// await migrateCompendium(compendium); // await migrateCompendium(compendium);

View file

@ -3,6 +3,8 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers";
export default function evaluateCheck( export default function evaluateCheck(
dice: number[], dice: number[],
checkTargetNumber: number, checkTargetNumber: number,
@ -39,7 +41,7 @@ function assignSubChecksToDice(
const requiredNumberOfDice = getRequiredNumberOfDice(checkTargetNumber); const requiredNumberOfDice = getRequiredNumberOfDice(checkTargetNumber);
if (dice.length !== requiredNumberOfDice || requiredNumberOfDice < 1) { if (dice.length !== requiredNumberOfDice || requiredNumberOfDice < 1) {
throw new Error(game.i18n.localize("DS4.ErrorInvalidNumberOfDice")); throw new Error(getGame().i18n.localize("DS4.ErrorInvalidNumberOfDice"));
} }
const checkTargetNumberForLastSubCheck = checkTargetNumber - 20 * (requiredNumberOfDice - 1); const checkTargetNumberForLastSubCheck = checkTargetNumber - 20 * (requiredNumberOfDice - 1);

View file

@ -3,6 +3,8 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers";
/** /**
* Provides default values for all arguments the `CheckFactory` expects. * Provides default values for all arguments the `CheckFactory` expects.
*/ */
@ -86,7 +88,7 @@ export async function createCheckRoll(
const newOptions: Partial<DS4CheckFactoryOptions> = { const newOptions: Partial<DS4CheckFactoryOptions> = {
maximumCoupResult: gmModifierData.maximumCoupResult ?? options.maximumCoupResult, maximumCoupResult: gmModifierData.maximumCoupResult ?? options.maximumCoupResult,
minimumFumbleResult: gmModifierData.minimumFumbleResult ?? options.minimumFumbleResult, minimumFumbleResult: gmModifierData.minimumFumbleResult ?? options.minimumFumbleResult,
useSlayingDice: game.settings.get("ds4", "useSlayingDiceForAutomatedChecks"), useSlayingDice: getGame().settings.get("ds4", "useSlayingDiceForAutomatedChecks"),
rollMode: gmModifierData.rollMode ?? options.rollMode, rollMode: gmModifierData.rollMode ?? options.rollMode,
flavor: options.flavor, flavor: options.flavor,
}; };
@ -114,13 +116,13 @@ async function askGmModifier(
{ template, title }: { template?: string; title?: string } = {}, { template, title }: { template?: string; title?: string } = {},
): Promise<Partial<IntermediateGmModifierData>> { ): Promise<Partial<IntermediateGmModifierData>> {
const usedTemplate = template ?? "systems/ds4/templates/dialogs/roll-options.hbs"; const usedTemplate = template ?? "systems/ds4/templates/dialogs/roll-options.hbs";
const usedTitle = title ?? game.i18n.localize("DS4.DialogRollOptionsDefaultTitle"); const usedTitle = title ?? getGame().i18n.localize("DS4.DialogRollOptionsDefaultTitle");
const templateData = { const templateData = {
title: usedTitle, title: usedTitle,
checkTargetNumber: checkTargetNumber, checkTargetNumber: checkTargetNumber,
maximumCoupResult: options.maximumCoupResult ?? defaultCheckOptions.maximumCoupResult, maximumCoupResult: options.maximumCoupResult ?? defaultCheckOptions.maximumCoupResult,
minimumFumbleResult: options.minimumFumbleResult ?? defaultCheckOptions.minimumFumbleResult, minimumFumbleResult: options.minimumFumbleResult ?? defaultCheckOptions.minimumFumbleResult,
rollMode: options.rollMode ?? game.settings.get("core", "rollMode"), rollMode: options.rollMode ?? getGame().settings.get("core", "rollMode"),
rollModes: CONFIG.Dice.rollModes, rollModes: CONFIG.Dice.rollModes,
}; };
const renderedHtml = await renderTemplate(usedTemplate, templateData); const renderedHtml = await renderTemplate(usedTemplate, templateData);
@ -132,11 +134,11 @@ async function askGmModifier(
buttons: { buttons: {
ok: { ok: {
icon: '<i class="fas fa-check"></i>', icon: '<i class="fas fa-check"></i>',
label: game.i18n.localize("DS4.GenericOkButton"), label: getGame().i18n.localize("DS4.GenericOkButton"),
callback: (html) => { callback: (html) => {
if (!("jquery" in html)) { if (!("jquery" in html)) {
throw new Error( throw new Error(
game.i18n.format("DS4.ErrorUnexpectedHtmlType", { getGame().i18n.format("DS4.ErrorUnexpectedHtmlType", {
exType: "JQuery", exType: "JQuery",
realType: "HTMLElement", realType: "HTMLElement",
}), }),
@ -145,7 +147,7 @@ async function askGmModifier(
const innerForm = html[0].querySelector("form"); const innerForm = html[0].querySelector("form");
if (!innerForm) { if (!innerForm) {
throw new Error( throw new Error(
game.i18n.format("DS4.ErrorCouldNotFindHtmlElement", { htmlElement: "form" }), getGame().i18n.format("DS4.ErrorCouldNotFindHtmlElement", { htmlElement: "form" }),
); );
} }
resolve(innerForm); resolve(innerForm);
@ -154,7 +156,7 @@ async function askGmModifier(
}, },
cancel: { cancel: {
icon: '<i class="fas fa-times"></i>', icon: '<i class="fas fa-times"></i>',
label: game.i18n.localize("DS4.GenericCancelButton"), label: getGame().i18n.localize("DS4.GenericCancelButton"),
}, },
}, },
default: "ok", default: "ok",

View file

@ -3,6 +3,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers";
import evaluateCheck, { getRequiredNumberOfDice } from "./check-evaluation"; import evaluateCheck, { getRequiredNumberOfDice } from "./check-evaluation";
/** /**
@ -50,7 +51,7 @@ export class DS4Check extends DiceTerm {
? parseInt(parseMinimumFumbleResult) ? parseInt(parseMinimumFumbleResult)
: DS4Check.DEFAULT_MINIMUM_FUMBLE_RESULT; : DS4Check.DEFAULT_MINIMUM_FUMBLE_RESULT;
if (this.minimumFumbleResult <= this.maximumCoupResult) if (this.minimumFumbleResult <= this.maximumCoupResult)
throw new SyntaxError(game.i18n.localize("DS4.ErrorDiceCoupFumbleOverlap")); throw new SyntaxError(getGame().i18n.localize("DS4.ErrorDiceCoupFumbleOverlap"));
} }
// Parse and store no fumble // Parse and store no fumble

View file

@ -2,6 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers";
import { DS4Check } from "./check"; import { DS4Check } from "./check";
export class DS4Roll<D extends Record<string, unknown> = Record<string, unknown>> extends Roll<D> { export class DS4Roll<D extends Record<string, unknown> = Record<string, unknown>> extends Roll<D> {
@ -15,7 +16,7 @@ export class DS4Roll<D extends Record<string, unknown> = Record<string, unknown>
async render(chatOptions: Parameters<Roll["render"]>[0] = {}): Promise<string> { async render(chatOptions: Parameters<Roll["render"]>[0] = {}): Promise<string> {
chatOptions = foundry.utils.mergeObject( chatOptions = foundry.utils.mergeObject(
{ {
user: game.user?.id, user: getGame().user?.id,
flavor: null, flavor: null,
template: DS4Roll.CHAT_TEMPLATE, template: DS4Roll.CHAT_TEMPLATE,
blind: false, blind: false,

View file

@ -3,6 +3,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers";
import { DS4Check } from "./check"; import { DS4Check } from "./check";
export default function registerSlayingDiceModifier(): void { export default function registerSlayingDiceModifier(): void {
@ -26,6 +27,6 @@ function slay(this: PoolTerm, modifier: string): void {
this.results.push({ result: additionalRoll.total ?? 0, active: true }); this.results.push({ result: additionalRoll.total ?? 0, active: true });
this.terms.push(formula); this.terms.push(formula);
} }
if (checked > 1000) throw new Error(game.i18n.localize("DS4.ErrorSlayingDiceRecursionLimitExceeded")); if (checked > 1000) throw new Error(getGame().i18n.localize("DS4.ErrorSlayingDiceRecursionLimitExceeded"));
} }
} }

View file

@ -2,11 +2,13 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "./helpers";
export function registerSystemSettings(): void { export function registerSystemSettings(): void {
/** /**
* Track the migrations version of the latest migration that has been applied * Track the migrations version of the latest migration that has been applied
*/ */
game.settings.register("ds4", "systemMigrationVersion", { getGame().settings.register("ds4", "systemMigrationVersion", {
name: "System Migration Version", name: "System Migration Version",
scope: "world", scope: "world",
config: false, config: false,
@ -14,7 +16,7 @@ export function registerSystemSettings(): void {
default: -1, default: -1,
}); });
game.settings.register("ds4", "useSlayingDiceForAutomatedChecks", { getGame().settings.register("ds4", "useSlayingDiceForAutomatedChecks", {
name: "DS4.SettingUseSlayingDiceForAutomatedChecksName", name: "DS4.SettingUseSlayingDiceForAutomatedChecksName",
hint: "DS4.SettingUseSlayingDiceForAutomatedChecksHint", hint: "DS4.SettingUseSlayingDiceForAutomatedChecksHint",
scope: "world", scope: "world",
@ -23,7 +25,7 @@ export function registerSystemSettings(): void {
default: false, default: false,
}); });
game.settings.register("ds4", "showSlayerPoints", { getGame().settings.register("ds4", "showSlayerPoints", {
name: "DS4.SettingShowSlayerPointsName", name: "DS4.SettingShowSlayerPointsName",
hint: "DS4.SettingShowSlayerPointsHint", hint: "DS4.SettingShowSlayerPointsHint",
scope: "world", scope: "world",
@ -41,8 +43,8 @@ export interface DS4Settings {
export function getDS4Settings(): DS4Settings { export function getDS4Settings(): DS4Settings {
return { return {
systemMigrationVersion: game.settings.get("ds4", "systemMigrationVersion"), systemMigrationVersion: getGame().settings.get("ds4", "systemMigrationVersion"),
useSlayingDiceForAutomatedChecks: game.settings.get("ds4", "useSlayingDiceForAutomatedChecks"), useSlayingDiceForAutomatedChecks: getGame().settings.get("ds4", "useSlayingDiceForAutomatedChecks"),
showSlayerPoints: game.settings.get("ds4", "showSlayerPoints"), showSlayerPoints: getGame().settings.get("ds4", "showSlayerPoints"),
}; };
} }

View file

@ -673,7 +673,7 @@ __metadata:
"@league-of-foundry-developers/foundry-vtt-types@https://github.com/League-of-Foundry-Developers/foundry-vtt-types.git#foundry-0.8.x": "@league-of-foundry-developers/foundry-vtt-types@https://github.com/League-of-Foundry-Developers/foundry-vtt-types.git#foundry-0.8.x":
version: 0.7.9-6 version: 0.7.9-6
resolution: "@league-of-foundry-developers/foundry-vtt-types@https://github.com/League-of-Foundry-Developers/foundry-vtt-types.git#commit=91fcf23da640665cf9b0a02bf83f87958b1dfef0" resolution: "@league-of-foundry-developers/foundry-vtt-types@https://github.com/League-of-Foundry-Developers/foundry-vtt-types.git#commit=22688f7be9f9c2605c3376e365e12b6084d59b85"
dependencies: dependencies:
"@types/jquery": ~3.5.5 "@types/jquery": ~3.5.5
"@types/simple-peer": ~9.11.0 "@types/simple-peer": ~9.11.0
@ -683,7 +683,7 @@ __metadata:
socket.io-client: 4.1.2 socket.io-client: 4.1.2
tinymce: 5.8.1 tinymce: 5.8.1
typescript: ^4.1.6 typescript: ^4.1.6
checksum: 513c8c8eaeb585641e78dd72f983e07a06d0babb24a8ed4de83479afdc9f9d85d2b255bc6168ec2d17d9368bcff3429b910d310b5f63358e74c9f49a84da958e checksum: bba8fb7081e7cd1c43a5af841820232629a9034e7075d733558b261b5d488fd166dcf9501158cd49e29a7a2e9b7b4ebf6f4aef76b1d740a253455a7432308a77
languageName: node languageName: node
linkType: hard linkType: hard
@ -1279,11 +1279,11 @@ __metadata:
linkType: hard linkType: hard
"@types/jquery@npm:~3.5.5": "@types/jquery@npm:~3.5.5":
version: 3.5.5 version: 3.5.6
resolution: "@types/jquery@npm:3.5.5" resolution: "@types/jquery@npm:3.5.6"
dependencies: dependencies:
"@types/sizzle": "*" "@types/sizzle": "*"
checksum: 9e3c34451577c6916ac9de8a26fd8bce2831cb5861116514cba4a984189067635a3e084039308324d8e20bfa5f2e1ce7725a509110e5e05487b91f9369b1ae43 checksum: b59c43f42ad94cb428c8708e1c0e9589a4e2cf8ca38a34528630081de2b715f0760d02e73171934896573a6e817c45c9ded725ae13e9f8d33509f67ae4f1bd01
languageName: node languageName: node
linkType: hard linkType: hard
@ -1325,11 +1325,11 @@ __metadata:
linkType: hard linkType: hard
"@types/simple-peer@npm:~9.11.0": "@types/simple-peer@npm:~9.11.0":
version: 9.11.0 version: 9.11.1
resolution: "@types/simple-peer@npm:9.11.0" resolution: "@types/simple-peer@npm:9.11.1"
dependencies: dependencies:
"@types/node": "*" "@types/node": "*"
checksum: ab05e2373fe48faa59cc0d7795bfdea3c7e7a93f7af2683cfdd2a311035ce4dd2a948c950886f48d662db503e8af2d930b9d51b53c0eef8c90ba86287864d4f7 checksum: 15738eb9e95e2fa98b012f519ed01dbd55219ff52ed531a95b6cb7861fc1a000930db7e165de8f414a3b1998813a7c6c26becaa1eb21918f8e65e7e03395cfe5
languageName: node languageName: node
linkType: hard linkType: hard