From c5d4ec1abd060472dc2a9bc79f2e2b9d6c9bb165 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 4 Nov 2022 21:47:18 +0100 Subject: [PATCH 1/2] refactor: improve structure of src --- spec/{rolls => dice}/check-evaluation.spec.ts | 2 +- .../item/spell/calculate-spell-price.spec.ts | 4 +- .../active-effect-config.ts | 0 .../actor/base-sheet.ts} | 21 +++++---- .../actor}/character-sheet.ts | 2 +- .../creature => apps/actor}/creature-sheet.ts | 2 +- src/{item => apps}/item-sheet.ts | 11 +++-- src/apps/sheet-helpers.ts | 2 +- src/{rolls => dice}/check-evaluation.ts | 4 +- src/{rolls => dice}/check-factory.ts | 2 +- src/{rolls => dice}/check.ts | 4 +- src/{rolls => dice}/roll.ts | 2 +- src/{rolls => dice}/slaying-dice-modifier.ts | 4 +- .../active-effect.ts | 6 +-- .../actor/actor-data-properties-base.ts | 2 +- .../actor/actor-data-properties.ts | 0 .../actor/actor-data-source-base.ts | 2 +- .../actor/actor-data-source.ts | 0 src/{ => documents}/actor/actor.ts | 12 ++--- .../character/character-data-properties.ts | 0 .../actor/character/character-data-source.ts | 0 .../actor/character/character.ts | 0 .../creature/creature-data-properties.ts | 0 .../actor/creature/creature-data-source.ts | 2 +- .../actor/creature/creature.ts | 0 src/{ => documents}/actor/proxy.ts | 2 +- src/{ => documents}/chat-message.ts | 2 +- src/{ => documents}/common/common-data.ts | 0 .../item/alphabet/alphabet-data-properties.ts | 0 .../item/alphabet/alphabet-data-source.ts | 0 src/{ => documents}/item/alphabet/alphabet.ts | 0 .../item/armor/armor-data-properties.ts | 0 .../item/armor/armor-data-source.ts | 2 +- src/{ => documents}/item/armor/armor.ts | 0 .../equipment/equipment-data-properties.ts | 0 .../item/equipment/equipment-data-source.ts | 0 .../item/equipment/equipment.ts | 0 .../item/item-data-properties-base.ts | 0 .../item/item-data-properties.ts | 0 .../item/item-data-source-base.ts | 2 +- src/{ => documents}/item/item-data-source.ts | 2 +- src/{ => documents}/item/item.ts | 4 +- .../item/language/language-data-properties.ts | 0 .../item/language/language-data-source.ts | 0 src/{ => documents}/item/language/language.ts | 0 .../item/loot/loot-data-properties.ts | 0 .../item/loot/loot-data-source.ts | 0 src/{ => documents}/item/loot/loot.ts | 0 src/{ => documents}/item/proxy.ts | 2 +- .../racial-ability-data-properties.ts | 0 .../racial-ability-data-source.ts | 0 .../item/racial-ability/racial-ability.ts | 0 .../item/shield/shield-data-properties.ts | 0 .../item/shield/shield-data-source.ts | 0 src/{ => documents}/item/shield/shield.ts | 0 ...pecial-creature-ability-data-properties.ts | 0 .../special-creature-ability-data-source.ts | 0 .../special-creature-ability.ts | 0 .../item/spell/calculate-spell-price.ts | 0 .../item/spell/spell-data-properties.ts | 0 .../item/spell/spell-data-source.ts | 2 +- src/{ => documents}/item/spell/spell.ts | 6 +-- .../item/talent/talent-data-properties.ts | 0 .../item/talent/talent-data-source.ts | 0 src/{ => documents}/item/talent/talent.ts | 0 .../item/weapon/weapon-data-properties.ts | 0 .../item/weapon/weapon-data-source.ts | 2 +- src/{ => documents}/item/weapon/weapon.ts | 8 ++-- src/{ => documents}/token-document.ts | 2 +- src/ds4.ts | 2 +- src/handlebars/handlebars-helpers.ts | 2 +- src/handlebars/handlebars-partials.ts | 2 +- src/helpers.ts | 21 --------- src/hooks/hooks.ts | 12 ++--- src/hooks/hotbar-drop.ts | 10 ++--- src/hooks/init.ts | 44 +++++++++---------- src/hooks/ready.ts | 4 +- src/hooks/render.ts | 2 +- src/hooks/setup.ts | 4 +- src/macros/helpers.ts | 4 +- src/macros/roll-check.ts | 6 +-- src/macros/roll-generic-check.ts | 4 +- src/macros/roll-item.ts | 4 +- src/{migrations => migration}/001.ts | 0 src/{migrations => migration}/002.ts | 0 src/{migrations => migration}/003.ts | 0 src/{migrations => migration}/004.ts | 0 src/{migrations => migration}/005.ts | 0 src/{migrations => migration}/006.ts | 2 +- src/{migrations.ts => migration/migration.ts} | 18 ++++---- .../migrationHelpers.ts | 8 ++-- src/settings.ts | 2 +- src/{ => ui}/fonts.ts | 0 src/ui/notifications.ts | 8 ++-- src/{ => utils}/logger.ts | 4 +- src/{ => utils}/utils.ts | 20 ++++++++- 96 files changed, 146 insertions(+), 157 deletions(-) rename spec/{rolls => dice}/check-evaluation.spec.ts (99%) rename spec/{ => documents}/item/spell/calculate-spell-price.spec.ts (98%) rename src/{active-effect => apps}/active-effect-config.ts (100%) rename src/{actor/actor-sheet.ts => apps/actor/base-sheet.ts} (96%) rename src/{actor/character => apps/actor}/character-sheet.ts (89%) rename src/{actor/creature => apps/actor}/creature-sheet.ts (89%) rename src/{item => apps}/item-sheet.ts (93%) rename src/{rolls => dice}/check-evaluation.ts (98%) rename src/{rolls => dice}/check-factory.ts (99%) rename src/{rolls => dice}/check.ts (97%) rename src/{rolls => dice}/roll.ts (97%) rename src/{rolls => dice}/slaying-dice-modifier.ts (91%) rename src/{active-effect => documents}/active-effect.ts (97%) rename src/{ => documents}/actor/actor-data-properties-base.ts (97%) rename src/{ => documents}/actor/actor-data-properties.ts (100%) rename src/{ => documents}/actor/actor-data-source-base.ts (97%) rename src/{ => documents}/actor/actor-data-source.ts (100%) rename src/{ => documents}/actor/actor.ts (98%) rename src/{ => documents}/actor/character/character-data-properties.ts (100%) rename src/{ => documents}/actor/character/character-data-source.ts (100%) rename src/{ => documents}/actor/character/character.ts (100%) rename src/{ => documents}/actor/creature/creature-data-properties.ts (100%) rename src/{ => documents}/actor/creature/creature-data-source.ts (94%) rename src/{ => documents}/actor/creature/creature.ts (100%) rename src/{ => documents}/actor/proxy.ts (94%) rename src/{ => documents}/chat-message.ts (95%) rename src/{ => documents}/common/common-data.ts (100%) rename src/{ => documents}/item/alphabet/alphabet-data-properties.ts (100%) rename src/{ => documents}/item/alphabet/alphabet-data-source.ts (100%) rename src/{ => documents}/item/alphabet/alphabet.ts (100%) rename src/{ => documents}/item/armor/armor-data-properties.ts (100%) rename src/{ => documents}/item/armor/armor-data-source.ts (93%) rename src/{ => documents}/item/armor/armor.ts (100%) rename src/{ => documents}/item/equipment/equipment-data-properties.ts (100%) rename src/{ => documents}/item/equipment/equipment-data-source.ts (100%) rename src/{ => documents}/item/equipment/equipment.ts (100%) rename src/{ => documents}/item/item-data-properties-base.ts (100%) rename src/{ => documents}/item/item-data-properties.ts (100%) rename src/{ => documents}/item/item-data-source-base.ts (95%) rename src/{ => documents}/item/item-data-source.ts (97%) rename src/{ => documents}/item/item.ts (95%) rename src/{ => documents}/item/language/language-data-properties.ts (100%) rename src/{ => documents}/item/language/language-data-source.ts (100%) rename src/{ => documents}/item/language/language.ts (100%) rename src/{ => documents}/item/loot/loot-data-properties.ts (100%) rename src/{ => documents}/item/loot/loot-data-source.ts (100%) rename src/{ => documents}/item/loot/loot.ts (100%) rename src/{ => documents}/item/proxy.ts (97%) rename src/{ => documents}/item/racial-ability/racial-ability-data-properties.ts (100%) rename src/{ => documents}/item/racial-ability/racial-ability-data-source.ts (100%) rename src/{ => documents}/item/racial-ability/racial-ability.ts (100%) rename src/{ => documents}/item/shield/shield-data-properties.ts (100%) rename src/{ => documents}/item/shield/shield-data-source.ts (100%) rename src/{ => documents}/item/shield/shield.ts (100%) rename src/{ => documents}/item/special-creature-ability/special-creature-ability-data-properties.ts (100%) rename src/{ => documents}/item/special-creature-ability/special-creature-ability-data-source.ts (100%) rename src/{ => documents}/item/special-creature-ability/special-creature-ability.ts (100%) rename src/{ => documents}/item/spell/calculate-spell-price.ts (100%) rename src/{ => documents}/item/spell/spell-data-properties.ts (100%) rename src/{ => documents}/item/spell/spell-data-source.ts (96%) rename src/{ => documents}/item/spell/spell.ts (93%) rename src/{ => documents}/item/talent/talent-data-properties.ts (100%) rename src/{ => documents}/item/talent/talent-data-source.ts (100%) rename src/{ => documents}/item/talent/talent.ts (100%) rename src/{ => documents}/item/weapon/weapon-data-properties.ts (100%) rename src/{ => documents}/item/weapon/weapon-data-source.ts (93%) rename src/{ => documents}/item/weapon/weapon.ts (94%) rename src/{ => documents}/token-document.ts (95%) delete mode 100644 src/helpers.ts rename src/{migrations => migration}/001.ts (100%) rename src/{migrations => migration}/002.ts (100%) rename src/{migrations => migration}/003.ts (100%) rename src/{migrations => migration}/004.ts (100%) rename src/{migrations => migration}/005.ts (100%) rename src/{migrations => migration}/006.ts (97%) rename src/{migrations.ts => migration/migration.ts} (90%) rename src/{migrations => migration}/migrationHelpers.ts (97%) rename src/{ => ui}/fonts.ts (100%) rename src/{ => utils}/logger.ts (92%) rename src/{ => utils}/utils.ts (66%) diff --git a/spec/rolls/check-evaluation.spec.ts b/spec/dice/check-evaluation.spec.ts similarity index 99% rename from spec/rolls/check-evaluation.spec.ts rename to spec/dice/check-evaluation.spec.ts index a89cf91d..cf2c0d3b 100644 --- a/spec/rolls/check-evaluation.spec.ts +++ b/spec/dice/check-evaluation.spec.ts @@ -5,7 +5,7 @@ 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", () => { it("should throw an error.", () => { diff --git a/spec/item/spell/calculate-spell-price.spec.ts b/spec/documents/item/spell/calculate-spell-price.spec.ts similarity index 98% rename from spec/item/spell/calculate-spell-price.spec.ts rename to spec/documents/item/spell/calculate-spell-price.spec.ts index 0e9f5d34..4e9f2409 100644 --- a/spec/item/spell/calculate-spell-price.spec.ts +++ b/spec/documents/item/spell/calculate-spell-price.spec.ts @@ -4,9 +4,9 @@ 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 = { description: "", diff --git a/src/active-effect/active-effect-config.ts b/src/apps/active-effect-config.ts similarity index 100% rename from src/active-effect/active-effect-config.ts rename to src/apps/active-effect-config.ts diff --git a/src/actor/actor-sheet.ts b/src/apps/actor/base-sheet.ts similarity index 96% rename from src/actor/actor-sheet.ts rename to src/apps/actor/base-sheet.ts index bf14abcf..bb2e5fa4 100644 --- a/src/actor/actor-sheet.ts +++ b/src/apps/actor/base-sheet.ts @@ -5,18 +5,17 @@ // // SPDX-License-Identifier: MIT -import { DS4ActiveEffect } from "../active-effect/active-effect"; -import { disableOverriddenFields } from "../apps/sheet-helpers"; -import { DS4 } from "../config"; -import { getCanvas, getGame } from "../helpers"; -import { getDS4Settings } from "../settings"; -import notifications from "../ui/notifications"; -import { enforce } from "../utils"; -import { isCheck } from "./actor-data-properties-base"; +import { DS4 } from "../../config"; +import { DS4ActiveEffect } from "../../documents/active-effect"; +import { isCheck } from "../../documents/actor/actor-data-properties-base"; +import { getDS4Settings } from "../../settings"; +import { notifications } from "../../ui/notifications"; +import { enforce, getCanvas, getGame } from "../../utils/utils"; +import { disableOverriddenFields } from "../sheet-helpers"; -import type { ModifiableDataBaseTotal } from "../common/common-data"; -import type { DS4Settings } from "../settings"; -import type { DS4Item } from "../item/item"; +import type { ModifiableDataBaseTotal } from "../../documents/common/common-data"; +import type { DS4Settings } from "../../settings"; +import type { DS4Item } from "../../documents/item/item"; /** * The base sheet class for all {@link DS4Actor}s. diff --git a/src/actor/character/character-sheet.ts b/src/apps/actor/character-sheet.ts similarity index 89% rename from src/actor/character/character-sheet.ts rename to src/apps/actor/character-sheet.ts index 379eb547..f6ec0649 100644 --- a/src/actor/character/character-sheet.ts +++ b/src/apps/actor/character-sheet.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -import { DS4ActorSheet } from "../actor-sheet"; +import { DS4ActorSheet } from "./base-sheet"; /** * The Sheet class for DS4 Character Actors diff --git a/src/actor/creature/creature-sheet.ts b/src/apps/actor/creature-sheet.ts similarity index 89% rename from src/actor/creature/creature-sheet.ts rename to src/apps/actor/creature-sheet.ts index 08f56773..53b75523 100644 --- a/src/actor/creature/creature-sheet.ts +++ b/src/apps/actor/creature-sheet.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -import { DS4ActorSheet } from "../actor-sheet"; +import { DS4ActorSheet } from "./base-sheet"; /** * The Sheet class for DS4 Creature Actors diff --git a/src/item/item-sheet.ts b/src/apps/item-sheet.ts similarity index 93% rename from src/item/item-sheet.ts rename to src/apps/item-sheet.ts index 56af9363..3062419b 100644 --- a/src/item/item-sheet.ts +++ b/src/apps/item-sheet.ts @@ -4,13 +4,12 @@ // // SPDX-License-Identifier: MIT -import { DS4ActiveEffect } from "../active-effect/active-effect"; -import { disableOverriddenFields } from "../apps/sheet-helpers"; import { DS4 } from "../config"; -import { getGame } from "../helpers"; -import notifications from "../ui/notifications"; -import { enforce } from "../utils"; -import { isDS4ItemDataTypePhysical } from "./item-data-source-base"; +import { DS4ActiveEffect } from "../documents/active-effect"; +import { isDS4ItemDataTypePhysical } from "../documents/item/item-data-source-base"; +import { notifications } from "../ui/notifications"; +import { enforce, getGame } from "../utils/utils"; +import { disableOverriddenFields } from "./sheet-helpers"; /** * The Sheet class for DS4 Items diff --git a/src/apps/sheet-helpers.ts b/src/apps/sheet-helpers.ts index 2a2e4d14..5082244d 100644 --- a/src/apps/sheet-helpers.ts +++ b/src/apps/sheet-helpers.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -import { getGame } from "../helpers"; +import { getGame } from "../utils/utils"; export function disableOverriddenFields( form: HTMLElement | null, diff --git a/src/rolls/check-evaluation.ts b/src/dice/check-evaluation.ts similarity index 98% rename from src/rolls/check-evaluation.ts rename to src/dice/check-evaluation.ts index 2ee1e461..753c7d8f 100644 --- a/src/rolls/check-evaluation.ts +++ b/src/dice/check-evaluation.ts @@ -3,9 +3,9 @@ // // SPDX-License-Identifier: MIT -import { getGame } from "../helpers"; +import { getGame } from "../utils/utils"; -export default function evaluateCheck( +export function evaluateCheck( dice: number[], checkTargetNumber: number, { diff --git a/src/rolls/check-factory.ts b/src/dice/check-factory.ts similarity index 99% rename from src/rolls/check-factory.ts rename to src/dice/check-factory.ts index 99f87216..0f2ec62a 100644 --- a/src/rolls/check-factory.ts +++ b/src/dice/check-factory.ts @@ -5,7 +5,7 @@ import { DialogWithListeners } from "../apps/dialog-with-listeners"; import { DS4 } from "../config"; -import { getGame } from "../helpers"; +import { getGame } from "../utils/utils"; /** * Provides default values for all arguments the `CheckFactory` expects. diff --git a/src/rolls/check.ts b/src/dice/check.ts similarity index 97% rename from src/rolls/check.ts rename to src/dice/check.ts index 9491be3f..ce9e983a 100644 --- a/src/rolls/check.ts +++ b/src/dice/check.ts @@ -3,8 +3,8 @@ // // SPDX-License-Identifier: MIT -import { getGame } from "../helpers"; -import evaluateCheck, { getRequiredNumberOfDice } from "./check-evaluation"; +import { getGame } from "../utils/utils"; +import { evaluateCheck, getRequiredNumberOfDice } from "./check-evaluation"; /** * Implements DS4 Checks as an emulated "dice throw". diff --git a/src/rolls/roll.ts b/src/dice/roll.ts similarity index 97% rename from src/rolls/roll.ts rename to src/dice/roll.ts index 653a5787..fa86f212 100644 --- a/src/rolls/roll.ts +++ b/src/dice/roll.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -import { getGame } from "../helpers"; +import { getGame } from "../utils/utils"; import { DS4Check } from "./check"; export class DS4Roll = Record> extends Roll { diff --git a/src/rolls/slaying-dice-modifier.ts b/src/dice/slaying-dice-modifier.ts similarity index 91% rename from src/rolls/slaying-dice-modifier.ts rename to src/dice/slaying-dice-modifier.ts index bd58b059..7f091e07 100644 --- a/src/rolls/slaying-dice-modifier.ts +++ b/src/dice/slaying-dice-modifier.ts @@ -3,10 +3,10 @@ // // SPDX-License-Identifier: MIT -import { getGame } from "../helpers"; +import { getGame } from "../utils/utils"; import { DS4Check } from "./check"; -export default function registerSlayingDiceModifier(): void { +export function registerSlayingDiceModifier(): void { PoolTerm.MODIFIERS.x = slay; } diff --git a/src/active-effect/active-effect.ts b/src/documents/active-effect.ts similarity index 97% rename from src/active-effect/active-effect.ts rename to src/documents/active-effect.ts index 2acdeaeb..cbc816b9 100644 --- a/src/active-effect/active-effect.ts +++ b/src/documents/active-effect.ts @@ -3,10 +3,10 @@ // SPDX-License-Identifier: MIT import { mathEvaluator } from "../expression-evaluation/evaluator"; -import { getGame } from "../helpers"; +import { getGame } from "../utils/utils"; -import type { DS4Actor } from "../actor/actor"; -import type { DS4Item } from "../item/item"; +import type { DS4Actor } from "./actor/actor"; +import type { DS4Item } from "./item/item"; declare global { interface DocumentClassConfig { diff --git a/src/actor/actor-data-properties-base.ts b/src/documents/actor/actor-data-properties-base.ts similarity index 97% rename from src/actor/actor-data-properties-base.ts rename to src/documents/actor/actor-data-properties-base.ts index 9aa9e335..70abd07c 100644 --- a/src/actor/actor-data-properties-base.ts +++ b/src/documents/actor/actor-data-properties-base.ts @@ -5,7 +5,7 @@ // // SPDX-License-Identifier: MIT -import { DS4 } from "../config"; +import { DS4 } from "../../config"; import type { ModifiableDataBaseTotal, ResourceDataBaseTotalMax } from "../common/common-data"; diff --git a/src/actor/actor-data-properties.ts b/src/documents/actor/actor-data-properties.ts similarity index 100% rename from src/actor/actor-data-properties.ts rename to src/documents/actor/actor-data-properties.ts diff --git a/src/actor/actor-data-source-base.ts b/src/documents/actor/actor-data-source-base.ts similarity index 97% rename from src/actor/actor-data-source-base.ts rename to src/documents/actor/actor-data-source-base.ts index e57ad17d..4c20f471 100644 --- a/src/actor/actor-data-source-base.ts +++ b/src/documents/actor/actor-data-source-base.ts @@ -5,7 +5,7 @@ // // SPDX-License-Identifier: MIT -import { DS4 } from "../config"; +import { DS4 } from "../../config"; import type { ModifiableData, ModifiableDataBase, ResourceData } from "../common/common-data"; diff --git a/src/actor/actor-data-source.ts b/src/documents/actor/actor-data-source.ts similarity index 100% rename from src/actor/actor-data-source.ts rename to src/documents/actor/actor-data-source.ts diff --git a/src/actor/actor.ts b/src/documents/actor/actor.ts similarity index 98% rename from src/actor/actor.ts rename to src/documents/actor/actor.ts index 7d20c220..800885b4 100644 --- a/src/actor/actor.ts +++ b/src/documents/actor/actor.ts @@ -3,12 +3,12 @@ // // SPDX-License-Identifier: MIT -import { DS4ActiveEffect } from "../active-effect/active-effect"; -import { DS4 } from "../config"; -import { mathEvaluator } from "../expression-evaluation/evaluator"; -import { getGame } from "../helpers"; -import logger from "../logger"; -import { createCheckRoll } from "../rolls/check-factory"; +import { DS4 } from "../../config"; +import { createCheckRoll } from "../../dice/check-factory"; +import { mathEvaluator } from "../../expression-evaluation/evaluator"; +import { logger } from "../../utils/logger"; +import { getGame } from "../../utils/utils"; +import { DS4ActiveEffect } from "../active-effect"; import { isAttribute, isTrait } from "./actor-data-source-base"; import type { ModifiableDataBaseTotal } from "../common/common-data"; diff --git a/src/actor/character/character-data-properties.ts b/src/documents/actor/character/character-data-properties.ts similarity index 100% rename from src/actor/character/character-data-properties.ts rename to src/documents/actor/character/character-data-properties.ts diff --git a/src/actor/character/character-data-source.ts b/src/documents/actor/character/character-data-source.ts similarity index 100% rename from src/actor/character/character-data-source.ts rename to src/documents/actor/character/character-data-source.ts diff --git a/src/actor/character/character.ts b/src/documents/actor/character/character.ts similarity index 100% rename from src/actor/character/character.ts rename to src/documents/actor/character/character.ts diff --git a/src/actor/creature/creature-data-properties.ts b/src/documents/actor/creature/creature-data-properties.ts similarity index 100% rename from src/actor/creature/creature-data-properties.ts rename to src/documents/actor/creature/creature-data-properties.ts diff --git a/src/actor/creature/creature-data-source.ts b/src/documents/actor/creature/creature-data-source.ts similarity index 94% rename from src/actor/creature/creature-data-source.ts rename to src/documents/actor/creature/creature-data-source.ts index 6d01ccbe..12f77d8b 100644 --- a/src/actor/creature/creature-data-source.ts +++ b/src/documents/actor/creature/creature-data-source.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -import type { DS4 } from "../../config"; +import type { DS4 } from "../../../config"; import type { DS4ActorDataSourceDataBase } from "../actor-data-source-base"; export interface DS4CreatureDataSource { diff --git a/src/actor/creature/creature.ts b/src/documents/actor/creature/creature.ts similarity index 100% rename from src/actor/creature/creature.ts rename to src/documents/actor/creature/creature.ts diff --git a/src/actor/proxy.ts b/src/documents/actor/proxy.ts similarity index 94% rename from src/actor/proxy.ts rename to src/documents/actor/proxy.ts index 51ca02f2..e5eb2f44 100644 --- a/src/actor/proxy.ts +++ b/src/documents/actor/proxy.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -import { getGame } from "../helpers"; +import { getGame } from "../../utils/utils"; import { DS4Actor } from "./actor"; import { DS4Character } from "./character/character"; import { DS4Creature } from "./creature/creature"; diff --git a/src/chat-message.ts b/src/documents/chat-message.ts similarity index 95% rename from src/chat-message.ts rename to src/documents/chat-message.ts index b4578b57..ac99b9d5 100644 --- a/src/chat-message.ts +++ b/src/documents/chat-message.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -import { getGame } from "./helpers"; +import { getGame } from "../utils/utils"; declare global { interface FlagConfig { diff --git a/src/common/common-data.ts b/src/documents/common/common-data.ts similarity index 100% rename from src/common/common-data.ts rename to src/documents/common/common-data.ts diff --git a/src/item/alphabet/alphabet-data-properties.ts b/src/documents/item/alphabet/alphabet-data-properties.ts similarity index 100% rename from src/item/alphabet/alphabet-data-properties.ts rename to src/documents/item/alphabet/alphabet-data-properties.ts diff --git a/src/item/alphabet/alphabet-data-source.ts b/src/documents/item/alphabet/alphabet-data-source.ts similarity index 100% rename from src/item/alphabet/alphabet-data-source.ts rename to src/documents/item/alphabet/alphabet-data-source.ts diff --git a/src/item/alphabet/alphabet.ts b/src/documents/item/alphabet/alphabet.ts similarity index 100% rename from src/item/alphabet/alphabet.ts rename to src/documents/item/alphabet/alphabet.ts diff --git a/src/item/armor/armor-data-properties.ts b/src/documents/item/armor/armor-data-properties.ts similarity index 100% rename from src/item/armor/armor-data-properties.ts rename to src/documents/item/armor/armor-data-properties.ts diff --git a/src/item/armor/armor-data-source.ts b/src/documents/item/armor/armor-data-source.ts similarity index 93% rename from src/item/armor/armor-data-source.ts rename to src/documents/item/armor/armor-data-source.ts index e19f8a06..26a2e23f 100644 --- a/src/item/armor/armor-data-source.ts +++ b/src/documents/item/armor/armor-data-source.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -import type { DS4 } from "../../config"; +import type { DS4 } from "../../../config"; import type { DS4ItemDataSourceDataBase, DS4ItemDataSourceDataEquipable, diff --git a/src/item/armor/armor.ts b/src/documents/item/armor/armor.ts similarity index 100% rename from src/item/armor/armor.ts rename to src/documents/item/armor/armor.ts diff --git a/src/item/equipment/equipment-data-properties.ts b/src/documents/item/equipment/equipment-data-properties.ts similarity index 100% rename from src/item/equipment/equipment-data-properties.ts rename to src/documents/item/equipment/equipment-data-properties.ts diff --git a/src/item/equipment/equipment-data-source.ts b/src/documents/item/equipment/equipment-data-source.ts similarity index 100% rename from src/item/equipment/equipment-data-source.ts rename to src/documents/item/equipment/equipment-data-source.ts diff --git a/src/item/equipment/equipment.ts b/src/documents/item/equipment/equipment.ts similarity index 100% rename from src/item/equipment/equipment.ts rename to src/documents/item/equipment/equipment.ts diff --git a/src/item/item-data-properties-base.ts b/src/documents/item/item-data-properties-base.ts similarity index 100% rename from src/item/item-data-properties-base.ts rename to src/documents/item/item-data-properties-base.ts diff --git a/src/item/item-data-properties.ts b/src/documents/item/item-data-properties.ts similarity index 100% rename from src/item/item-data-properties.ts rename to src/documents/item/item-data-properties.ts diff --git a/src/item/item-data-source-base.ts b/src/documents/item/item-data-source-base.ts similarity index 95% rename from src/item/item-data-source-base.ts rename to src/documents/item/item-data-source-base.ts index ce801d31..dbd1a06b 100644 --- a/src/item/item-data-source-base.ts +++ b/src/documents/item/item-data-source-base.ts @@ -4,7 +4,7 @@ // // SPDX-License-Identifier: MIT -import type { DS4 } from "../config"; +import type { DS4 } from "../../config"; export interface DS4ItemDataSourceDataBase { description: string; diff --git a/src/item/item-data-source.ts b/src/documents/item/item-data-source.ts similarity index 97% rename from src/item/item-data-source.ts rename to src/documents/item/item-data-source.ts index ab4cf950..e2cb0b43 100644 --- a/src/item/item-data-source.ts +++ b/src/documents/item/item-data-source.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -import type { DS4 } from "../config"; +import type { DS4 } from "../../config"; import type { DS4AlphabetDataSource } from "./alphabet/alphabet-data-source"; import type { DS4ArmorDataSource } from "./armor/armor-data-source"; import type { DS4EquipmentDataSource } from "./equipment/equipment-data-source"; diff --git a/src/item/item.ts b/src/documents/item/item.ts similarity index 95% rename from src/item/item.ts rename to src/documents/item/item.ts index 9b3e8db4..f1655ba0 100644 --- a/src/item/item.ts +++ b/src/documents/item/item.ts @@ -3,8 +3,8 @@ // // SPDX-License-Identifier: MIT -import { DS4ActiveEffect } from "../active-effect/active-effect"; -import { getGame } from "../helpers"; +import { getGame } from "../../utils/utils"; +import { DS4ActiveEffect } from "../active-effect"; import type { ItemType } from "./item-data-source"; diff --git a/src/item/language/language-data-properties.ts b/src/documents/item/language/language-data-properties.ts similarity index 100% rename from src/item/language/language-data-properties.ts rename to src/documents/item/language/language-data-properties.ts diff --git a/src/item/language/language-data-source.ts b/src/documents/item/language/language-data-source.ts similarity index 100% rename from src/item/language/language-data-source.ts rename to src/documents/item/language/language-data-source.ts diff --git a/src/item/language/language.ts b/src/documents/item/language/language.ts similarity index 100% rename from src/item/language/language.ts rename to src/documents/item/language/language.ts diff --git a/src/item/loot/loot-data-properties.ts b/src/documents/item/loot/loot-data-properties.ts similarity index 100% rename from src/item/loot/loot-data-properties.ts rename to src/documents/item/loot/loot-data-properties.ts diff --git a/src/item/loot/loot-data-source.ts b/src/documents/item/loot/loot-data-source.ts similarity index 100% rename from src/item/loot/loot-data-source.ts rename to src/documents/item/loot/loot-data-source.ts diff --git a/src/item/loot/loot.ts b/src/documents/item/loot/loot.ts similarity index 100% rename from src/item/loot/loot.ts rename to src/documents/item/loot/loot.ts diff --git a/src/item/proxy.ts b/src/documents/item/proxy.ts similarity index 97% rename from src/item/proxy.ts rename to src/documents/item/proxy.ts index 58d4997f..b978bc30 100644 --- a/src/item/proxy.ts +++ b/src/documents/item/proxy.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -import { getGame } from "../helpers"; +import { getGame } from "../../utils/utils"; import { DS4Alphabet } from "./alphabet/alphabet"; import { DS4Armor } from "./armor/armor"; import { DS4Equipment } from "./equipment/equipment"; diff --git a/src/item/racial-ability/racial-ability-data-properties.ts b/src/documents/item/racial-ability/racial-ability-data-properties.ts similarity index 100% rename from src/item/racial-ability/racial-ability-data-properties.ts rename to src/documents/item/racial-ability/racial-ability-data-properties.ts diff --git a/src/item/racial-ability/racial-ability-data-source.ts b/src/documents/item/racial-ability/racial-ability-data-source.ts similarity index 100% rename from src/item/racial-ability/racial-ability-data-source.ts rename to src/documents/item/racial-ability/racial-ability-data-source.ts diff --git a/src/item/racial-ability/racial-ability.ts b/src/documents/item/racial-ability/racial-ability.ts similarity index 100% rename from src/item/racial-ability/racial-ability.ts rename to src/documents/item/racial-ability/racial-ability.ts diff --git a/src/item/shield/shield-data-properties.ts b/src/documents/item/shield/shield-data-properties.ts similarity index 100% rename from src/item/shield/shield-data-properties.ts rename to src/documents/item/shield/shield-data-properties.ts diff --git a/src/item/shield/shield-data-source.ts b/src/documents/item/shield/shield-data-source.ts similarity index 100% rename from src/item/shield/shield-data-source.ts rename to src/documents/item/shield/shield-data-source.ts diff --git a/src/item/shield/shield.ts b/src/documents/item/shield/shield.ts similarity index 100% rename from src/item/shield/shield.ts rename to src/documents/item/shield/shield.ts diff --git a/src/item/special-creature-ability/special-creature-ability-data-properties.ts b/src/documents/item/special-creature-ability/special-creature-ability-data-properties.ts similarity index 100% rename from src/item/special-creature-ability/special-creature-ability-data-properties.ts rename to src/documents/item/special-creature-ability/special-creature-ability-data-properties.ts diff --git a/src/item/special-creature-ability/special-creature-ability-data-source.ts b/src/documents/item/special-creature-ability/special-creature-ability-data-source.ts similarity index 100% rename from src/item/special-creature-ability/special-creature-ability-data-source.ts rename to src/documents/item/special-creature-ability/special-creature-ability-data-source.ts diff --git a/src/item/special-creature-ability/special-creature-ability.ts b/src/documents/item/special-creature-ability/special-creature-ability.ts similarity index 100% rename from src/item/special-creature-ability/special-creature-ability.ts rename to src/documents/item/special-creature-ability/special-creature-ability.ts diff --git a/src/item/spell/calculate-spell-price.ts b/src/documents/item/spell/calculate-spell-price.ts similarity index 100% rename from src/item/spell/calculate-spell-price.ts rename to src/documents/item/spell/calculate-spell-price.ts diff --git a/src/item/spell/spell-data-properties.ts b/src/documents/item/spell/spell-data-properties.ts similarity index 100% rename from src/item/spell/spell-data-properties.ts rename to src/documents/item/spell/spell-data-properties.ts diff --git a/src/item/spell/spell-data-source.ts b/src/documents/item/spell/spell-data-source.ts similarity index 96% rename from src/item/spell/spell-data-source.ts rename to src/documents/item/spell/spell-data-source.ts index e6f182bb..7751ad5a 100644 --- a/src/item/spell/spell-data-source.ts +++ b/src/documents/item/spell/spell-data-source.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -import type { DS4 } from "../../config"; +import type { DS4 } from "../../../config"; import type { DS4ItemDataSourceDataBase, DS4ItemDataSourceDataEquipable } from "../item-data-source-base"; export interface DS4SpellDataSource { diff --git a/src/item/spell/spell.ts b/src/documents/item/spell/spell.ts similarity index 93% rename from src/item/spell/spell.ts rename to src/documents/item/spell/spell.ts index 898cdfa9..e2d8925c 100644 --- a/src/item/spell/spell.ts +++ b/src/documents/item/spell/spell.ts @@ -2,9 +2,9 @@ // // SPDX-License-Identifier: MIT -import { getGame } from "../../helpers"; -import { createCheckRoll } from "../../rolls/check-factory"; -import notifications from "../../ui/notifications"; +import { createCheckRoll } from "../../../dice/check-factory"; +import { notifications } from "../../../ui/notifications"; +import { getGame } from "../../../utils/utils"; import { DS4Item } from "../item"; import { calculateSpellPrice } from "./calculate-spell-price"; diff --git a/src/item/talent/talent-data-properties.ts b/src/documents/item/talent/talent-data-properties.ts similarity index 100% rename from src/item/talent/talent-data-properties.ts rename to src/documents/item/talent/talent-data-properties.ts diff --git a/src/item/talent/talent-data-source.ts b/src/documents/item/talent/talent-data-source.ts similarity index 100% rename from src/item/talent/talent-data-source.ts rename to src/documents/item/talent/talent-data-source.ts diff --git a/src/item/talent/talent.ts b/src/documents/item/talent/talent.ts similarity index 100% rename from src/item/talent/talent.ts rename to src/documents/item/talent/talent.ts diff --git a/src/item/weapon/weapon-data-properties.ts b/src/documents/item/weapon/weapon-data-properties.ts similarity index 100% rename from src/item/weapon/weapon-data-properties.ts rename to src/documents/item/weapon/weapon-data-properties.ts diff --git a/src/item/weapon/weapon-data-source.ts b/src/documents/item/weapon/weapon-data-source.ts similarity index 93% rename from src/item/weapon/weapon-data-source.ts rename to src/documents/item/weapon/weapon-data-source.ts index 3dbe5410..6da1ce47 100644 --- a/src/item/weapon/weapon-data-source.ts +++ b/src/documents/item/weapon/weapon-data-source.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -import type { DS4 } from "../../config"; +import type { DS4 } from "../../../config"; import type { DS4ItemDataSourceDataBase, DS4ItemDataSourceDataEquipable, diff --git a/src/item/weapon/weapon.ts b/src/documents/item/weapon/weapon.ts similarity index 94% rename from src/item/weapon/weapon.ts rename to src/documents/item/weapon/weapon.ts index 34157629..134b4397 100644 --- a/src/item/weapon/weapon.ts +++ b/src/documents/item/weapon/weapon.ts @@ -2,10 +2,10 @@ // // SPDX-License-Identifier: MIT -import { DS4 } from "../../config"; -import { getGame } from "../../helpers"; -import { createCheckRoll } from "../../rolls/check-factory"; -import notifications from "../../ui/notifications"; +import { DS4 } from "../../../config"; +import { createCheckRoll } from "../../../dice/check-factory"; +import { notifications } from "../../../ui/notifications"; +import { getGame } from "../../../utils/utils"; import { DS4Item } from "../item"; import type { AttackType } from "./weapon-data-source"; diff --git a/src/token-document.ts b/src/documents/token-document.ts similarity index 95% rename from src/token-document.ts rename to src/documents/token-document.ts index ad170f9f..4aa855e6 100644 --- a/src/token-document.ts +++ b/src/documents/token-document.ts @@ -2,8 +2,8 @@ // // SPDX-License-Identifier: MIT +import { getGame } from "../utils/utils"; import { DS4ActorProxy } from "./actor/proxy"; -import { getGame } from "./helpers"; let fallbackData: foundry.data.ActorData["data"] | undefined = undefined; diff --git a/src/ds4.ts b/src/ds4.ts index 57f61604..25364a54 100644 --- a/src/ds4.ts +++ b/src/ds4.ts @@ -4,6 +4,6 @@ import "../scss/ds4.scss"; -import registerForHooks from "./hooks/hooks"; +import { registerForHooks } from "./hooks/hooks"; registerForHooks(); diff --git a/src/handlebars/handlebars-helpers.ts b/src/handlebars/handlebars-helpers.ts index 004f31e7..669262eb 100644 --- a/src/handlebars/handlebars-helpers.ts +++ b/src/handlebars/handlebars-helpers.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -export default function registerHandlebarsHelpers(): void { +export function registerHandlebarsHelpers(): void { Handlebars.registerHelper(helpers); } diff --git a/src/handlebars/handlebars-partials.ts b/src/handlebars/handlebars-partials.ts index f90d2f55..3220a2b9 100644 --- a/src/handlebars/handlebars-partials.ts +++ b/src/handlebars/handlebars-partials.ts @@ -4,7 +4,7 @@ // // SPDX-License-Identifier: MIT -export default async function registerHandlebarsPartials(): Promise { +export async function registerHandlebarsPartials(): Promise { const templatePaths = [ "systems/ds4/templates/sheets/actor/components/actor-header.hbs", "systems/ds4/templates/sheets/actor/components/actor-progression.hbs", diff --git a/src/helpers.ts b/src/helpers.ts deleted file mode 100644 index e96322e4..00000000 --- a/src/helpers.ts +++ /dev/null @@ -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; -} diff --git a/src/hooks/hooks.ts b/src/hooks/hooks.ts index 2507c4fd..b33cbf23 100644 --- a/src/hooks/hooks.ts +++ b/src/hooks/hooks.ts @@ -2,13 +2,13 @@ // // SPDX-License-Identifier: MIT -import registerForHotbarDropHook from "./hotbar-drop"; -import registerForInitHook from "./init"; -import registerForReadyHook from "./ready"; -import registerForRenderHooks from "./render"; -import registerForSetupHook from "./setup"; +import { registerForHotbarDropHook } from "./hotbar-drop"; +import { registerForInitHook } from "./init"; +import { registerForReadyHook } from "./ready"; +import { registerForRenderHooks } from "./render"; +import { registerForSetupHook } from "./setup"; -export default function registerForHooks(): void { +export function registerForHooks(): void { registerForHotbarDropHook(); registerForInitHook(); registerForReadyHook(); diff --git a/src/hooks/hotbar-drop.ts b/src/hooks/hotbar-drop.ts index efc8d719..438cb630 100644 --- a/src/hooks/hotbar-drop.ts +++ b/src/hooks/hotbar-drop.ts @@ -2,14 +2,14 @@ // // SPDX-License-Identifier: MIT -import { isCheck } from "../actor/actor-data-properties-base"; -import { getGame } from "../helpers"; -import { DS4Item } from "../item/item"; +import { isCheck } from "../documents/actor/actor-data-properties-base"; +import { DS4Item } from "../documents/item/item"; import { createRollCheckMacro } from "../macros/roll-check"; 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) => { switch (data.type) { case "Item": { diff --git a/src/hooks/init.ts b/src/hooks/init.ts index 35f22540..19de9032 100644 --- a/src/hooks/init.ts +++ b/src/hooks/init.ts @@ -4,33 +4,33 @@ // // SPDX-License-Identifier: MIT -import { DS4ActiveEffect } from "../active-effect/active-effect"; -import { DS4ActiveEffectConfig } from "../active-effect/active-effect-config"; -import { DS4CharacterActorSheet } from "../actor/character/character-sheet"; -import { DS4CreatureActorSheet } from "../actor/creature/creature-sheet"; -import { DS4ActorProxy } from "../actor/proxy"; -import { DS4ChatMessage } from "../chat-message"; +import { DS4ActiveEffectConfig } from "../apps/active-effect-config"; +import { DS4CharacterActorSheet } from "../apps/actor/character-sheet"; +import { DS4CreatureActorSheet } from "../apps/actor/creature-sheet"; +import { DS4ItemSheet } from "../apps/item-sheet"; import { DS4 } from "../config"; -import { preloadFonts } from "../fonts"; -import registerHandlebarsHelpers from "../handlebars/handlebars-helpers"; -import registerHandlebarsPartials from "../handlebars/handlebars-partials"; -import { getGame } from "../helpers"; -import { DS4ItemSheet } from "../item/item-sheet"; -import { DS4ItemProxy } from "../item/proxy"; -import logger from "../logger"; +import { DS4Check } from "../dice/check"; +import { createCheckRoll } from "../dice/check-factory"; +import { DS4Roll } from "../dice/roll"; +import { registerSlayingDiceModifier } from "../dice/slaying-dice-modifier"; +import { DS4ActiveEffect } from "../documents/active-effect"; +import { DS4ActorProxy } from "../documents/actor/proxy"; +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 { migration } from "../migrations"; -import { DS4Check } from "../rolls/check"; -import { createCheckRoll } from "../rolls/check-factory"; -import { DS4Roll } from "../rolls/roll"; -import registerSlayingDiceModifier from "../rolls/slaying-dice-modifier"; +import { migration } from "../migration/migration"; 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 { DS4Item } from "../item/item"; +import type { DS4Actor } from "../documents/actor/actor"; +import type { DS4Item } from "../documents/item/item"; -export default function registerForInitHook(): void { +export function registerForInitHook(): void { Hooks.once("init", init); } diff --git a/src/hooks/ready.ts b/src/hooks/ready.ts index b313ce5c..91c9c0cb 100644 --- a/src/hooks/ready.ts +++ b/src/hooks/ready.ts @@ -2,9 +2,9 @@ // // 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", () => { migration.migrate(); }); diff --git a/src/hooks/render.ts b/src/hooks/render.ts index 14a7f689..b12c9ebe 100644 --- a/src/hooks/render.ts +++ b/src/hooks/render.ts @@ -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 * "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) => { Hooks.on(hook, selectTargetInputOnFocus); }); diff --git a/src/hooks/setup.ts b/src/hooks/setup.ts index 6623f5eb..6c339f51 100644 --- a/src/hooks/setup.ts +++ b/src/hooks/setup.ts @@ -6,9 +6,9 @@ // SPDX-License-Identifier: MIT 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", () => { localizeAndSortConfigObjects(); }); diff --git a/src/macros/helpers.ts b/src/macros/helpers.ts index 5471a2e4..3542c7b8 100644 --- a/src/macros/helpers.ts +++ b/src/macros/helpers.ts @@ -2,9 +2,9 @@ // // 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} diff --git a/src/macros/roll-check.ts b/src/macros/roll-check.ts index ae93a039..45fa601e 100644 --- a/src/macros/roll-check.ts +++ b/src/macros/roll-check.ts @@ -3,11 +3,11 @@ // SPDX-License-Identifier: MIT 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 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. * Get an existing roll check macro if one exists, otherwise create a new one. diff --git a/src/macros/roll-generic-check.ts b/src/macros/roll-generic-check.ts index a0108267..61a3c91d 100644 --- a/src/macros/roll-generic-check.ts +++ b/src/macros/roll-generic-check.ts @@ -2,8 +2,8 @@ // // 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"; /** diff --git a/src/macros/roll-item.ts b/src/macros/roll-item.ts index b78c908a..a30d02cd 100644 --- a/src/macros/roll-item.ts +++ b/src/macros/roll-item.ts @@ -2,8 +2,8 @@ // // 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"; /** diff --git a/src/migrations/001.ts b/src/migration/001.ts similarity index 100% rename from src/migrations/001.ts rename to src/migration/001.ts diff --git a/src/migrations/002.ts b/src/migration/002.ts similarity index 100% rename from src/migrations/002.ts rename to src/migration/002.ts diff --git a/src/migrations/003.ts b/src/migration/003.ts similarity index 100% rename from src/migrations/003.ts rename to src/migration/003.ts diff --git a/src/migrations/004.ts b/src/migration/004.ts similarity index 100% rename from src/migrations/004.ts rename to src/migration/004.ts diff --git a/src/migrations/005.ts b/src/migration/005.ts similarity index 100% rename from src/migrations/005.ts rename to src/migration/005.ts diff --git a/src/migrations/006.ts b/src/migration/006.ts similarity index 97% rename from src/migrations/006.ts rename to src/migration/006.ts index 314ce2cd..6ce4a9c0 100644 --- a/src/migrations/006.ts +++ b/src/migration/006.ts @@ -12,7 +12,7 @@ import { migrateScenes, } 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 { await migrateItems(getItemUpdateData); diff --git a/src/migrations.ts b/src/migration/migration.ts similarity index 90% rename from src/migrations.ts rename to src/migration/migration.ts index e42e8358..c9118eae 100644 --- a/src/migrations.ts +++ b/src/migration/migration.ts @@ -2,15 +2,15 @@ // // SPDX-License-Identifier: MIT -import { getGame } from "./helpers"; -import logger from "./logger"; -import { migration as migration001 } from "./migrations/001"; -import { migration as migration002 } from "./migrations/002"; -import { migration as migration003 } from "./migrations/003"; -import { migration as migration004 } from "./migrations/004"; -import { migration as migration005 } from "./migrations/005"; -import { migration as migration006 } from "./migrations/006"; -import notifications from "./ui/notifications"; +import { notifications } from "../ui/notifications"; +import { logger } from "../utils/logger"; +import { getGame } from "../utils/utils"; +import { migration as migration001 } from "./001"; +import { migration as migration002 } from "./002"; +import { migration as migration003 } from "./003"; +import { migration as migration004 } from "./004"; +import { migration as migration005 } from "./005"; +import { migration as migration006 } from "./006"; async function migrate(): Promise { if (!getGame().user?.isGM) { diff --git a/src/migrations/migrationHelpers.ts b/src/migration/migrationHelpers.ts similarity index 97% rename from src/migrations/migrationHelpers.ts rename to src/migration/migrationHelpers.ts index 7a980668..1e25b6f0 100644 --- a/src/migrations/migrationHelpers.ts +++ b/src/migration/migrationHelpers.ts @@ -2,10 +2,10 @@ // // SPDX-License-Identifier: MIT -import { DS4Actor } from "../actor/actor"; -import { getGame } from "../helpers"; -import { DS4Item } from "../item/item"; -import logger from "../logger"; +import { DS4Actor } from "../documents/actor/actor"; +import { DS4Item } from "../documents/item/item"; +import { logger } from "../utils/logger"; +import { getGame } from "../utils/utils"; type ItemUpdateDataGetter = ( itemData: Partial, diff --git a/src/settings.ts b/src/settings.ts index a2d1017e..516d34f6 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -import { getGame } from "./helpers"; +import { getGame } from "./utils/utils"; export function registerSystemSettings(): void { const game = getGame(); diff --git a/src/fonts.ts b/src/ui/fonts.ts similarity index 100% rename from src/fonts.ts rename to src/ui/fonts.ts diff --git a/src/ui/notifications.ts b/src/ui/notifications.ts index 84b62e76..7e830beb 100644 --- a/src/ui/notifications.ts +++ b/src/ui/notifications.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -import logger from "../logger"; +import { logger } from "../utils/logger"; function getNotificationFunction(type: "info" | "warn" | "error") { 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"), warn: getNotificationFunction("warn"), error: getNotificationFunction("error"), @@ -35,6 +35,4 @@ const notifications = { logger.getLoggingFunction(type)(message); } }, -}; - -export default notifications; +}); diff --git a/src/logger.ts b/src/utils/logger.ts similarity index 92% rename from src/logger.ts rename to src/utils/logger.ts index c5c9a561..357d3087 100644 --- a/src/logger.ts +++ b/src/utils/logger.ts @@ -13,12 +13,10 @@ const getLoggingFunction = (type: LogLevel = "info"): LoggingFunction => { return (...data: unknown[]) => log(loggingContext, loggingSeparator, ...data); }; -const logger = Object.freeze({ +export const logger = Object.freeze({ debug: getLoggingFunction("debug"), info: getLoggingFunction("info"), warn: getLoggingFunction("warning"), error: getLoggingFunction("error"), getLoggingFunction, }); - -export default logger; diff --git a/src/utils.ts b/src/utils/utils.ts similarity index 66% rename from src/utils.ts rename to src/utils/utils.ts index a3038fe1..44cce905 100644 --- a/src/utils.ts +++ b/src/utils/utils.ts @@ -2,8 +2,6 @@ // // SPDX-License-Identifier: MIT -import { getGameSafe } from "./helpers"; - /** * 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); } } + +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; +} From 0e836fee65b810c7c34155f21f4fa2082c16c395 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Fri, 4 Nov 2022 21:50:03 +0100 Subject: [PATCH 2/2] chore(deps): update @types/node to v18.11.9 --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 2ecb9851..00aa0bb7 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "@seald-io/nedb": "3.1.0", "@swc/core": "1.3.14", "@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/parser": "5.42.0", "conventional-changelog-cli": "2.2.2", diff --git a/yarn.lock b/yarn.lock index 2dd6c018..71874316 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1209,10 +1209,10 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:16.18.3": - version: 16.18.3 - resolution: "@types/node@npm:16.18.3" - checksum: 6b8ba2ea5d842f7986e366cb9184c54d273d492784dc62e08fd5afeae938d9b61aec6e4222d2541cd18f9b1412ba361bbcb3f4204fb003608af80a2a6af959f9 +"@types/node@npm:18.11.9": + version: 18.11.9 + resolution: "@types/node@npm:18.11.9" + checksum: cc0aae109e9b7adefc32eecb838d6fad931663bb06484b5e9cbbbf74865c721b03d16fd8d74ad90e31dbe093d956a7c2c306ba5429ba0c00f3f7505103d7a496 languageName: node linkType: hard @@ -2553,7 +2553,7 @@ __metadata: "@seald-io/nedb": 3.1.0 "@swc/core": 1.3.14 "@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/parser": 5.42.0 conventional-changelog-cli: 2.2.2