Merge branch 'restructure' into 'main'

Restructure

See merge request 
This commit is contained in:
Johannes Loher 2022-11-04 21:12:44 +00:00
commit ebb2421952
98 changed files with 152 additions and 163 deletions
package.json
spec
src
apps
dice
documents
ds4.ts
handlebars
helpers.ts
hooks
macros
migration
settings.ts
ui
utils
yarn.lock

View file

@ -78,7 +78,7 @@
"@seald-io/nedb": "3.1.0", "@seald-io/nedb": "3.1.0",
"@swc/core": "1.3.14", "@swc/core": "1.3.14",
"@types/fs-extra": "9.0.13", "@types/fs-extra": "9.0.13",
"@types/node": "16.18.3", "@types/node": "18.11.9",
"@typescript-eslint/eslint-plugin": "5.42.0", "@typescript-eslint/eslint-plugin": "5.42.0",
"@typescript-eslint/parser": "5.42.0", "@typescript-eslint/parser": "5.42.0",
"conventional-changelog-cli": "2.2.2", "conventional-changelog-cli": "2.2.2",

View file

@ -5,7 +5,7 @@
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import evaluateCheck from "../../src/rolls/check-evaluation"; import { evaluateCheck } from "../../src/dice/check-evaluation";
describe("evaluateCheck with no dice", () => { describe("evaluateCheck with no dice", () => {
it("should throw an error.", () => { it("should throw an error.", () => {

View file

@ -4,9 +4,9 @@
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import { calculateSpellPrice } from "../../../src/item/spell/calculate-spell-price"; import { calculateSpellPrice } from "../../../../src/documents/item/spell/calculate-spell-price";
import type { CooldownDuration, DS4SpellDataSourceData } from "../../../src/item/spell/spell-data-source"; import type { CooldownDuration, DS4SpellDataSourceData } from "../../../../src/documents/item/spell/spell-data-source";
const defaultData: DS4SpellDataSourceData = { const defaultData: DS4SpellDataSourceData = {
description: "", description: "",

View file

@ -5,18 +5,17 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4ActiveEffect } from "../active-effect/active-effect"; import { DS4 } from "../../config";
import { disableOverriddenFields } from "../apps/sheet-helpers"; import { DS4ActiveEffect } from "../../documents/active-effect";
import { DS4 } from "../config"; import { isCheck } from "../../documents/actor/actor-data-properties-base";
import { getCanvas, getGame } from "../helpers"; import { getDS4Settings } from "../../settings";
import { getDS4Settings } from "../settings"; import { notifications } from "../../ui/notifications";
import notifications from "../ui/notifications"; import { enforce, getCanvas, getGame } from "../../utils/utils";
import { enforce } from "../utils"; import { disableOverriddenFields } from "../sheet-helpers";
import { isCheck } from "./actor-data-properties-base";
import type { ModifiableDataBaseTotal } from "../common/common-data"; import type { ModifiableDataBaseTotal } from "../../documents/common/common-data";
import type { DS4Settings } from "../settings"; import type { DS4Settings } from "../../settings";
import type { DS4Item } from "../item/item"; import type { DS4Item } from "../../documents/item/item";
/** /**
* The base sheet class for all {@link DS4Actor}s. * The base sheet class for all {@link DS4Actor}s.

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4ActorSheet } from "../actor-sheet"; import { DS4ActorSheet } from "./base-sheet";
/** /**
* The Sheet class for DS4 Character Actors * The Sheet class for DS4 Character Actors

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4ActorSheet } from "../actor-sheet"; import { DS4ActorSheet } from "./base-sheet";
/** /**
* The Sheet class for DS4 Creature Actors * The Sheet class for DS4 Creature Actors

View file

@ -4,13 +4,12 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4ActiveEffect } from "../active-effect/active-effect";
import { disableOverriddenFields } from "../apps/sheet-helpers";
import { DS4 } from "../config"; import { DS4 } from "../config";
import { getGame } from "../helpers"; import { DS4ActiveEffect } from "../documents/active-effect";
import notifications from "../ui/notifications"; import { isDS4ItemDataTypePhysical } from "../documents/item/item-data-source-base";
import { enforce } from "../utils"; import { notifications } from "../ui/notifications";
import { isDS4ItemDataTypePhysical } from "./item-data-source-base"; import { enforce, getGame } from "../utils/utils";
import { disableOverriddenFields } from "./sheet-helpers";
/** /**
* The Sheet class for DS4 Items * The Sheet class for DS4 Items

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers"; import { getGame } from "../utils/utils";
export function disableOverriddenFields( export function disableOverriddenFields(
form: HTMLElement | null, form: HTMLElement | null,

View file

@ -3,9 +3,9 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers"; import { getGame } from "../utils/utils";
export default function evaluateCheck( export function evaluateCheck(
dice: number[], dice: number[],
checkTargetNumber: number, checkTargetNumber: number,
{ {

View file

@ -5,7 +5,7 @@
import { DialogWithListeners } from "../apps/dialog-with-listeners"; import { DialogWithListeners } from "../apps/dialog-with-listeners";
import { DS4 } from "../config"; import { DS4 } from "../config";
import { getGame } from "../helpers"; import { getGame } from "../utils/utils";
/** /**
* Provides default values for all arguments the `CheckFactory` expects. * Provides default values for all arguments the `CheckFactory` expects.

View file

@ -3,8 +3,8 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers"; import { getGame } from "../utils/utils";
import evaluateCheck, { getRequiredNumberOfDice } from "./check-evaluation"; import { evaluateCheck, getRequiredNumberOfDice } from "./check-evaluation";
/** /**
* Implements DS4 Checks as an emulated "dice throw". * Implements DS4 Checks as an emulated "dice throw".

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers"; import { getGame } from "../utils/utils";
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> {

View file

@ -3,10 +3,10 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers"; import { getGame } from "../utils/utils";
import { DS4Check } from "./check"; import { DS4Check } from "./check";
export default function registerSlayingDiceModifier(): void { export function registerSlayingDiceModifier(): void {
PoolTerm.MODIFIERS.x = slay; PoolTerm.MODIFIERS.x = slay;
} }

View file

@ -3,10 +3,10 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { mathEvaluator } from "../expression-evaluation/evaluator"; import { mathEvaluator } from "../expression-evaluation/evaluator";
import { getGame } from "../helpers"; import { getGame } from "../utils/utils";
import type { DS4Actor } from "../actor/actor"; import type { DS4Actor } from "./actor/actor";
import type { DS4Item } from "../item/item"; import type { DS4Item } from "./item/item";
declare global { declare global {
interface DocumentClassConfig { interface DocumentClassConfig {

View file

@ -5,7 +5,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4 } from "../config"; import { DS4 } from "../../config";
import type { ModifiableDataBaseTotal, ResourceDataBaseTotalMax } from "../common/common-data"; import type { ModifiableDataBaseTotal, ResourceDataBaseTotalMax } from "../common/common-data";

View file

@ -5,7 +5,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4 } from "../config"; import { DS4 } from "../../config";
import type { ModifiableData, ModifiableDataBase, ResourceData } from "../common/common-data"; import type { ModifiableData, ModifiableDataBase, ResourceData } from "../common/common-data";

View file

@ -3,12 +3,12 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4ActiveEffect } from "../active-effect/active-effect"; import { DS4 } from "../../config";
import { DS4 } from "../config"; import { createCheckRoll } from "../../dice/check-factory";
import { mathEvaluator } from "../expression-evaluation/evaluator"; import { mathEvaluator } from "../../expression-evaluation/evaluator";
import { getGame } from "../helpers"; import { logger } from "../../utils/logger";
import logger from "../logger"; import { getGame } from "../../utils/utils";
import { createCheckRoll } from "../rolls/check-factory"; import { DS4ActiveEffect } from "../active-effect";
import { isAttribute, isTrait } from "./actor-data-source-base"; import { isAttribute, isTrait } from "./actor-data-source-base";
import type { ModifiableDataBaseTotal } from "../common/common-data"; import type { ModifiableDataBaseTotal } from "../common/common-data";

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import type { DS4 } from "../../config"; import type { DS4 } from "../../../config";
import type { DS4ActorDataSourceDataBase } from "../actor-data-source-base"; import type { DS4ActorDataSourceDataBase } from "../actor-data-source-base";
export interface DS4CreatureDataSource { export interface DS4CreatureDataSource {

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers"; import { getGame } from "../../utils/utils";
import { DS4Actor } from "./actor"; import { DS4Actor } from "./actor";
import { DS4Character } from "./character/character"; import { DS4Character } from "./character/character";
import { DS4Creature } from "./creature/creature"; import { DS4Creature } from "./creature/creature";

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "./helpers"; import { getGame } from "../utils/utils";
declare global { declare global {
interface FlagConfig { interface FlagConfig {

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import type { DS4 } from "../../config"; import type { DS4 } from "../../../config";
import type { import type {
DS4ItemDataSourceDataBase, DS4ItemDataSourceDataBase,
DS4ItemDataSourceDataEquipable, DS4ItemDataSourceDataEquipable,

View file

@ -4,7 +4,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import type { DS4 } from "../config"; import type { DS4 } from "../../config";
export interface DS4ItemDataSourceDataBase { export interface DS4ItemDataSourceDataBase {
description: string; description: string;

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import type { DS4 } from "../config"; import type { DS4 } from "../../config";
import type { DS4AlphabetDataSource } from "./alphabet/alphabet-data-source"; import type { DS4AlphabetDataSource } from "./alphabet/alphabet-data-source";
import type { DS4ArmorDataSource } from "./armor/armor-data-source"; import type { DS4ArmorDataSource } from "./armor/armor-data-source";
import type { DS4EquipmentDataSource } from "./equipment/equipment-data-source"; import type { DS4EquipmentDataSource } from "./equipment/equipment-data-source";

View file

@ -3,8 +3,8 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4ActiveEffect } from "../active-effect/active-effect"; import { getGame } from "../../utils/utils";
import { getGame } from "../helpers"; import { DS4ActiveEffect } from "../active-effect";
import type { ItemType } from "./item-data-source"; import type { ItemType } from "./item-data-source";

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers"; import { getGame } from "../../utils/utils";
import { DS4Alphabet } from "./alphabet/alphabet"; import { DS4Alphabet } from "./alphabet/alphabet";
import { DS4Armor } from "./armor/armor"; import { DS4Armor } from "./armor/armor";
import { DS4Equipment } from "./equipment/equipment"; import { DS4Equipment } from "./equipment/equipment";

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import type { DS4 } from "../../config"; import type { DS4 } from "../../../config";
import type { DS4ItemDataSourceDataBase, DS4ItemDataSourceDataEquipable } from "../item-data-source-base"; import type { DS4ItemDataSourceDataBase, DS4ItemDataSourceDataEquipable } from "../item-data-source-base";
export interface DS4SpellDataSource { export interface DS4SpellDataSource {

View file

@ -2,9 +2,9 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../../helpers"; import { createCheckRoll } from "../../../dice/check-factory";
import { createCheckRoll } from "../../rolls/check-factory"; import { notifications } from "../../../ui/notifications";
import notifications from "../../ui/notifications"; import { getGame } from "../../../utils/utils";
import { DS4Item } from "../item"; import { DS4Item } from "../item";
import { calculateSpellPrice } from "./calculate-spell-price"; import { calculateSpellPrice } from "./calculate-spell-price";

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import type { DS4 } from "../../config"; import type { DS4 } from "../../../config";
import type { import type {
DS4ItemDataSourceDataBase, DS4ItemDataSourceDataBase,
DS4ItemDataSourceDataEquipable, DS4ItemDataSourceDataEquipable,

View file

@ -2,10 +2,10 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4 } from "../../config"; import { DS4 } from "../../../config";
import { getGame } from "../../helpers"; import { createCheckRoll } from "../../../dice/check-factory";
import { createCheckRoll } from "../../rolls/check-factory"; import { notifications } from "../../../ui/notifications";
import notifications from "../../ui/notifications"; import { getGame } from "../../../utils/utils";
import { DS4Item } from "../item"; import { DS4Item } from "../item";
import type { AttackType } from "./weapon-data-source"; import type { AttackType } from "./weapon-data-source";

View file

@ -2,8 +2,8 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../utils/utils";
import { DS4ActorProxy } from "./actor/proxy"; import { DS4ActorProxy } from "./actor/proxy";
import { getGame } from "./helpers";
let fallbackData: foundry.data.ActorData["data"] | undefined = undefined; let fallbackData: foundry.data.ActorData["data"] | undefined = undefined;

View file

@ -4,6 +4,6 @@
import "../scss/ds4.scss"; import "../scss/ds4.scss";
import registerForHooks from "./hooks/hooks"; import { registerForHooks } from "./hooks/hooks";
registerForHooks(); registerForHooks();

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
export default function registerHandlebarsHelpers(): void { export function registerHandlebarsHelpers(): void {
Handlebars.registerHelper(helpers); Handlebars.registerHelper(helpers);
} }

View file

@ -4,7 +4,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
export default async function registerHandlebarsPartials(): Promise<void> { export async function registerHandlebarsPartials(): Promise<void> {
const templatePaths = [ const templatePaths = [
"systems/ds4/templates/sheets/actor/components/actor-header.hbs", "systems/ds4/templates/sheets/actor/components/actor-header.hbs",
"systems/ds4/templates/sheets/actor/components/actor-progression.hbs", "systems/ds4/templates/sheets/actor/components/actor-progression.hbs",

View file

@ -1,21 +0,0 @@
// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
export function getCanvas(): Canvas {
if (!(canvas instanceof Canvas) || !canvas.ready) {
throw new Error(getGame().i18n.localize("DS4.ErrorCanvasIsNotInitialized"));
}
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;
}
export function getGameSafe(): Game | undefined {
return game instanceof Game ? game : undefined;
}

View file

@ -2,13 +2,13 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import registerForHotbarDropHook from "./hotbar-drop"; import { registerForHotbarDropHook } from "./hotbar-drop";
import registerForInitHook from "./init"; import { registerForInitHook } from "./init";
import registerForReadyHook from "./ready"; import { registerForReadyHook } from "./ready";
import registerForRenderHooks from "./render"; import { registerForRenderHooks } from "./render";
import registerForSetupHook from "./setup"; import { registerForSetupHook } from "./setup";
export default function registerForHooks(): void { export function registerForHooks(): void {
registerForHotbarDropHook(); registerForHotbarDropHook();
registerForInitHook(); registerForInitHook();
registerForReadyHook(); registerForReadyHook();

View file

@ -2,14 +2,14 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { isCheck } from "../actor/actor-data-properties-base"; import { isCheck } from "../documents/actor/actor-data-properties-base";
import { getGame } from "../helpers"; import { DS4Item } from "../documents/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";
import notifications from "../ui/notifications"; import { notifications } from "../ui/notifications";
import { getGame } from "../utils/utils";
export default function registerForHotbarDropHook(): void { export function registerForHotbarDropHook(): void {
Hooks.on("hotbarDrop", async (hotbar: Hotbar, data: HotbarDropData, slot: string) => { Hooks.on("hotbarDrop", async (hotbar: Hotbar, data: HotbarDropData, slot: string) => {
switch (data.type) { switch (data.type) {
case "Item": { case "Item": {

View file

@ -4,33 +4,33 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4ActiveEffect } from "../active-effect/active-effect"; import { DS4ActiveEffectConfig } from "../apps/active-effect-config";
import { DS4ActiveEffectConfig } from "../active-effect/active-effect-config"; import { DS4CharacterActorSheet } from "../apps/actor/character-sheet";
import { DS4CharacterActorSheet } from "../actor/character/character-sheet"; import { DS4CreatureActorSheet } from "../apps/actor/creature-sheet";
import { DS4CreatureActorSheet } from "../actor/creature/creature-sheet"; import { DS4ItemSheet } from "../apps/item-sheet";
import { DS4ActorProxy } from "../actor/proxy";
import { DS4ChatMessage } from "../chat-message";
import { DS4 } from "../config"; import { DS4 } from "../config";
import { preloadFonts } from "../fonts"; import { DS4Check } from "../dice/check";
import registerHandlebarsHelpers from "../handlebars/handlebars-helpers"; import { createCheckRoll } from "../dice/check-factory";
import registerHandlebarsPartials from "../handlebars/handlebars-partials"; import { DS4Roll } from "../dice/roll";
import { getGame } from "../helpers"; import { registerSlayingDiceModifier } from "../dice/slaying-dice-modifier";
import { DS4ItemSheet } from "../item/item-sheet"; import { DS4ActiveEffect } from "../documents/active-effect";
import { DS4ItemProxy } from "../item/proxy"; import { DS4ActorProxy } from "../documents/actor/proxy";
import logger from "../logger"; import { DS4ChatMessage } from "../documents/chat-message";
import { DS4ItemProxy } from "../documents/item/proxy";
import { DS4TokenDocument } from "../documents/token-document";
import { registerHandlebarsHelpers } from "../handlebars/handlebars-helpers";
import { registerHandlebarsPartials } from "../handlebars/handlebars-partials";
import { macros } from "../macros/macros"; import { macros } from "../macros/macros";
import { migration } from "../migrations"; import { migration } from "../migration/migration";
import { DS4Check } from "../rolls/check";
import { createCheckRoll } from "../rolls/check-factory";
import { DS4Roll } from "../rolls/roll";
import registerSlayingDiceModifier from "../rolls/slaying-dice-modifier";
import { registerSystemSettings } from "../settings"; import { registerSystemSettings } from "../settings";
import { DS4TokenDocument } from "../token-document"; import { preloadFonts } from "../ui/fonts";
import { logger } from "../utils/logger";
import { getGame } from "../utils/utils";
import type { DS4Actor } from "../actor/actor"; import type { DS4Actor } from "../documents/actor/actor";
import type { DS4Item } from "../item/item"; import type { DS4Item } from "../documents/item/item";
export default function registerForInitHook(): void { export function registerForInitHook(): void {
Hooks.once("init", init); Hooks.once("init", init);
} }

View file

@ -2,9 +2,9 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { migration } from "../migrations"; import { migration } from "../migration/migration";
export default function registerForReadyHook(): void { export function registerForReadyHook(): void {
Hooks.once("ready", () => { Hooks.once("ready", () => {
migration.migrate(); migration.migrate();
}); });

View file

@ -7,7 +7,7 @@
* @remarks The render hooks of all classes in the class hierarchy are called, so e.g. for a {@link Dialog}, both the * @remarks The render hooks of all classes in the class hierarchy are called, so e.g. for a {@link Dialog}, both the
* "renderDialog" hook and the "renderApplication" hook are called (in this order). * "renderDialog" hook and the "renderApplication" hook are called (in this order).
*/ */
export default function registerForRenderHooks(): void { export function registerForRenderHooks(): void {
["renderApplication", "renderActorSheet", "renderItemSheet"].forEach((hook) => { ["renderApplication", "renderActorSheet", "renderItemSheet"].forEach((hook) => {
Hooks.on(hook, selectTargetInputOnFocus); Hooks.on(hook, selectTargetInputOnFocus);
}); });

View file

@ -6,9 +6,9 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4 } from "../config"; import { DS4 } from "../config";
import { getGame } from "../helpers"; import { getGame } from "../utils/utils";
export default function registerForSetupHooks(): void { export function registerForSetupHook(): void {
Hooks.once("setup", () => { Hooks.once("setup", () => {
localizeAndSortConfigObjects(); localizeAndSortConfigObjects();
}); });

View file

@ -2,9 +2,9 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getCanvas, getGame } from "../helpers"; import { getCanvas, getGame } from "../utils/utils";
import type { DS4Actor } from "../actor/actor"; import type { DS4Actor } from "../documents/actor/actor";
/** /**
* Gets the currently active actor and token based on how {@link ChatMessage} * Gets the currently active actor and token based on how {@link ChatMessage}

View file

@ -3,11 +3,11 @@
// 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 { getGame } from "../utils/utils";
import { getActiveActorAndToken } from "./helpers"; import { getActiveActorAndToken } from "./helpers";
import type { Check } from "../actor/actor-data-properties-base"; import type { Check } from "../documents/actor/actor-data-properties-base";
/** /**
* Creates a macro from a check drop. * Creates a macro from a check drop.
* Get an existing roll check macro if one exists, otherwise create a new one. * Get an existing roll check macro if one exists, otherwise create a new one.

View file

@ -2,8 +2,8 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers"; import { notifications } from "../ui/notifications";
import notifications from "../ui/notifications"; import { getGame } from "../utils/utils";
import { getActiveActorAndToken } from "./helpers"; import { getActiveActorAndToken } from "./helpers";
/** /**

View file

@ -2,8 +2,8 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "../helpers"; import { notifications } from "../ui/notifications";
import notifications from "../ui/notifications"; import { getGame } from "../utils/utils";
import { getActiveActorAndToken } from "./helpers"; import { getActiveActorAndToken } from "./helpers";
/** /**

View file

@ -12,7 +12,7 @@ import {
migrateScenes, migrateScenes,
} from "./migrationHelpers"; } from "./migrationHelpers";
import type { DS4SpellDataSourceData } from "../item/spell/spell-data-source"; import type { DS4SpellDataSourceData } from "../documents/item/spell/spell-data-source";
async function migrate(): Promise<void> { async function migrate(): Promise<void> {
await migrateItems(getItemUpdateData); await migrateItems(getItemUpdateData);

View file

@ -2,15 +2,15 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "./helpers"; import { notifications } from "../ui/notifications";
import logger from "./logger"; import { logger } from "../utils/logger";
import { migration as migration001 } from "./migrations/001"; import { getGame } from "../utils/utils";
import { migration as migration002 } from "./migrations/002"; import { migration as migration001 } from "./001";
import { migration as migration003 } from "./migrations/003"; import { migration as migration002 } from "./002";
import { migration as migration004 } from "./migrations/004"; import { migration as migration003 } from "./003";
import { migration as migration005 } from "./migrations/005"; import { migration as migration004 } from "./004";
import { migration as migration006 } from "./migrations/006"; import { migration as migration005 } from "./005";
import notifications from "./ui/notifications"; import { migration as migration006 } from "./006";
async function migrate(): Promise<void> { async function migrate(): Promise<void> {
if (!getGame().user?.isGM) { if (!getGame().user?.isGM) {

View file

@ -2,10 +2,10 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { DS4Actor } from "../actor/actor"; import { DS4Actor } from "../documents/actor/actor";
import { getGame } from "../helpers"; import { DS4Item } from "../documents/item/item";
import { DS4Item } from "../item/item"; import { logger } from "../utils/logger";
import logger from "../logger"; import { getGame } from "../utils/utils";
type ItemUpdateDataGetter = ( type ItemUpdateDataGetter = (
itemData: Partial<foundry.data.ItemData["_source"]>, itemData: Partial<foundry.data.ItemData["_source"]>,

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGame } from "./helpers"; import { getGame } from "./utils/utils";
export function registerSystemSettings(): void { export function registerSystemSettings(): void {
const game = getGame(); const game = getGame();

View file

@ -2,7 +2,7 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import logger from "../logger"; import { logger } from "../utils/logger";
function getNotificationFunction(type: "info" | "warn" | "error") { function getNotificationFunction(type: "info" | "warn" | "error") {
return (message: string, { permanent = false, log = false }: { permanent?: boolean; log?: boolean } = {}): void => { return (message: string, { permanent = false, log = false }: { permanent?: boolean; log?: boolean } = {}): void => {
@ -17,7 +17,7 @@ function getNotificationFunction(type: "info" | "warn" | "error") {
}; };
} }
const notifications = { export const notifications = Object.freeze({
info: getNotificationFunction("info"), info: getNotificationFunction("info"),
warn: getNotificationFunction("warn"), warn: getNotificationFunction("warn"),
error: getNotificationFunction("error"), error: getNotificationFunction("error"),
@ -35,6 +35,4 @@ const notifications = {
logger.getLoggingFunction(type)(message); logger.getLoggingFunction(type)(message);
} }
}, },
}; });
export default notifications;

View file

@ -13,12 +13,10 @@ const getLoggingFunction = (type: LogLevel = "info"): LoggingFunction => {
return (...data: unknown[]) => log(loggingContext, loggingSeparator, ...data); return (...data: unknown[]) => log(loggingContext, loggingSeparator, ...data);
}; };
const logger = Object.freeze({ export const logger = Object.freeze({
debug: getLoggingFunction("debug"), debug: getLoggingFunction("debug"),
info: getLoggingFunction("info"), info: getLoggingFunction("info"),
warn: getLoggingFunction("warning"), warn: getLoggingFunction("warning"),
error: getLoggingFunction("error"), error: getLoggingFunction("error"),
getLoggingFunction, getLoggingFunction,
}); });
export default logger;

View file

@ -2,8 +2,6 @@
// //
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { getGameSafe } from "./helpers";
/** /**
* Tests if the given `value` is truthy. * Tests if the given `value` is truthy.
* *
@ -22,3 +20,21 @@ export function enforce(value: unknown, message?: string | Error): asserts value
throw message instanceof Error ? message : new Error(message); throw message instanceof Error ? message : new Error(message);
} }
} }
export function getCanvas(): Canvas {
if (!(canvas instanceof Canvas) || !canvas.ready) {
throw new Error(getGame().i18n.localize("DS4.ErrorCanvasIsNotInitialized"));
}
return canvas;
}
export function getGame(): Game {
if (!(game instanceof Game)) {
throw new Error("Game is not initialized yet.");
}
return game;
}
export function getGameSafe(): Game | undefined {
return game instanceof Game ? game : undefined;
}

View file

@ -1209,10 +1209,10 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@types/node@npm:16.18.3": "@types/node@npm:18.11.9":
version: 16.18.3 version: 18.11.9
resolution: "@types/node@npm:16.18.3" resolution: "@types/node@npm:18.11.9"
checksum: 6b8ba2ea5d842f7986e366cb9184c54d273d492784dc62e08fd5afeae938d9b61aec6e4222d2541cd18f9b1412ba361bbcb3f4204fb003608af80a2a6af959f9 checksum: cc0aae109e9b7adefc32eecb838d6fad931663bb06484b5e9cbbbf74865c721b03d16fd8d74ad90e31dbe093d956a7c2c306ba5429ba0c00f3f7505103d7a496
languageName: node languageName: node
linkType: hard linkType: hard
@ -2553,7 +2553,7 @@ __metadata:
"@seald-io/nedb": 3.1.0 "@seald-io/nedb": 3.1.0
"@swc/core": 1.3.14 "@swc/core": 1.3.14
"@types/fs-extra": 9.0.13 "@types/fs-extra": 9.0.13
"@types/node": 16.18.3 "@types/node": 18.11.9
"@typescript-eslint/eslint-plugin": 5.42.0 "@typescript-eslint/eslint-plugin": 5.42.0
"@typescript-eslint/parser": 5.42.0 "@typescript-eslint/parser": 5.42.0
conventional-changelog-cli: 2.2.2 conventional-changelog-cli: 2.2.2