diff --git a/.betterer.results b/.betterer.results index ca60b0a27b9..7628c014454 100644 --- a/.betterer.results +++ b/.betterer.results @@ -129,7 +129,7 @@ exports[`stricter compilation`] = { [329, 28, 23, "Element implicitly has an \'any\' type because expression of type \'string\' can\'t be used to index type \'{ str: AbilityData; dex: AbilityData; con: AbilityData; int: AbilityData; wis: AbilityData; cha: AbilityData; }\'.\\n No index signature with a parameter of type \'string\' was found on type \'{ str: AbilityData; dex: AbilityData; con: AbilityData; int: AbilityData; wis: AbilityData; cha: AbilityData; }\'.", "1182846011"], [375, 36, 31, "Element implicitly has an \'any\' type because expression of type \'string\' can\'t be used to index type \'{ acid: string; adamantine: string; alchemical: string; agile: string; artifact: string; attached: string; backstabber: string; backswing: string; bomb: string; brutal: string; chaotic: string; climbing: string; ... 108 more ...; \'modular-b-P-or-s\': string; }\'.\\n No index signature with a parameter of type \'string\' was found on type \'{ acid: string; adamantine: string; alchemical: string; agile: string; artifact: string; attached: string; backstabber: string; backswing: string; bomb: string; brutal: string; chaotic: string; climbing: string; ... 108 more ...; \'modular-b-P-or-s\': string; }\'.", "3601740505"] ], - "src/module/actor/sheet/base.ts:1120150219": [ + "src/module/actor/sheet/base.ts:4261615411": [ [78, 19, 6, "Parameter \'traits\' implicitly has an \'any\' type.", "1720055084"], [99, 69, 19, "Element implicitly has an \'any\' type because expression of type \'any\' can\'t be used to index type \'{ acid: string; bludgeoning: string; cold: string; fire: string; force: string; electricity: string; sonic: string; negative: string; piercing: string; poison: string; positive: string; bleed: string; ... 12 more ...; \'protean anatomy\': string; } | { ...; } | { ...; } | { ...; } | { ...; }\'.", "3465888121"], [103, 42, 19, "Element implicitly has an \'any\' type because expression of type \'any\' can\'t be used to index type \'{ acid: string; bludgeoning: string; cold: string; fire: string; force: string; electricity: string; sonic: string; negative: string; piercing: string; poison: string; positive: string; bleed: string; ... 12 more ...; \'protean anatomy\': string; } | { ...; } | { ...; } | { ...; } | { ...; }\'.", "3465888121"], @@ -738,9 +738,6 @@ exports[`stricter compilation`] = { [23, 31, 56, "Element implicitly has an \'any\' type because index expression is not of type \'number\'.", "1741159767"], [25, 31, 56, "Element implicitly has an \'any\' type because index expression is not of type \'number\'.", "645286097"] ], - "src/module/gm/travel/travel-speed-sheet.ts:934936780": [ - [298, 25, 4, "Argument of type \'null\' is not assignable to parameter of type \'{} | undefined\'.", "2087897566"] - ], "src/module/item/bulk.ts:3592305284": [ [280, 8, 15, "Type \'string | undefined\' is not assignable to type \'string\'.\\n Type \'undefined\' is not assignable to type \'string\'.", "424545820"], [283, 8, 19, "Type \'Bulk | undefined\' is not assignable to type \'Bulk\'.\\n Type \'undefined\' is not assignable to type \'Bulk\'.", "4133372623"], @@ -1206,7 +1203,7 @@ exports[`stricter compilation`] = { [218, 18, 3, "Parameter \'val\' implicitly has an \'any\' type.", "193428222"], [224, 21, 3, "Parameter \'val\' implicitly has an \'any\' type.", "193428222"] ], - "src/module/system/world-clock/index.ts:2279674915": [ + "src/module/system/world-clock/index.ts:1853293595": [ [114, 23, 34, "Element implicitly has an \'any\' type because expression of type \'string\' can\'t be used to index type \'{ January: string; February: string; March: string; April: string; May: string; June: string; July: string; August: string; September: string; October: string; November: string; December: string; }\'.\\n No index signature with a parameter of type \'string\' was found on type \'{ January: string; February: string; March: string; April: string; May: string; June: string; July: string; August: string; September: string; October: string; November: string; December: string; }\'.", "2128514067"], [126, 23, 38, "Element implicitly has an \'any\' type because expression of type \'string\' can\'t be used to index type \'{ Monday: string; Tuesday: string; Wednesday: string; Thursday: string; Friday: string; Saturday: string; Sunday: string; }\'.\\n No index signature with a parameter of type \'string\' was found on type \'{ Monday: string; Tuesday: string; Wednesday: string; Thursday: string; Friday: string; Saturday: string; Sunday: string; }\'.", "1647180819"], [139, 15, 42, "Element implicitly has an \'any\' type because expression of type \'string\' can\'t be used to index type \'{ One: string; Two: string; Few: string; Other: string; }\'.\\n No index signature with a parameter of type \'string\' was found on type \'{ One: string; Two: string; Few: string; Other: string; }\'.", "837659766"] diff --git a/jest.config.js b/jest.config.js index 766460ae989..40bb7718ee1 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,11 +2,15 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', modulePaths: [ - '', - '/src', - '/dist', - '/types/foundry-pc-types', + '', + '/src', + '/dist', + '/types/foundry-pc-types', ], + moduleNameMapper: { + '^@utils$': '/src/module/utils.ts', + '^@scripts/(.*)$': '/src/scripts/$1', + }, setupFiles: [ './tests/setup.ts', ], diff --git a/package-lock.json b/package-lock.json index 1e97f2a67aa..cdbd6a8247c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15236,9 +15236,9 @@ } }, "node_modules/typescript": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.2.tgz", - "integrity": "sha512-tbb+NVrLfnsJy3M59lsDgrzWIflR4d4TIUjz+heUnHZwdF7YsrMTKoRERiIvI2lvBG95dfpLxB21WZhys1bgaQ==", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz", + "integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -28205,9 +28205,9 @@ } }, "typescript": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.2.tgz", - "integrity": "sha512-tbb+NVrLfnsJy3M59lsDgrzWIflR4d4TIUjz+heUnHZwdF7YsrMTKoRERiIvI2lvBG95dfpLxB21WZhys1bgaQ==", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz", + "integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==", "dev": true }, "uglify-js": { diff --git a/src/global.d.ts b/src/global.d.ts index cbfd4e71c6a..90b4381f740 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,85 +1,67 @@ -declare type TranslationsPF2e = typeof import('../static/lang/en.json'); +import { WorldClock } from '@system/world-clock'; +import { EffectPanel } from '@system/effect-panel'; +import { rollActionMacro, rollItemMacro } from '@scripts/init'; +import { calculateXP } from '@scripts/macros/xp'; +import { launchTravelSheet } from '@scripts/macros/travel/travel-speed-sheet'; +import { PF2EActor } from '@actor/actor'; +import { PF2EItem } from '@item/item'; +import { ConfigPF2e } from '@scripts/config'; +import { PF2eSystem } from './module/pf2e-system'; +import { PF2ECombat } from './module/combat'; +import { PF2Check } from '@system/rolls'; +import { + AbilityModifier, + PF2CheckModifier, + PF2Modifier, + PF2ModifierType, + PF2StatisticModifier, + ProficiencyModifier, +} from './module/modifiers'; +import { PF2eConditionManager } from './module/conditions'; +import { PF2eStatusEffects } from '@scripts/actor/status-effects'; +import { DicePF2e } from '@scripts/dice'; -declare interface Game { - pf2e: { - actions: { [key: string]: Function }; - worldClock?: import('./module/system/world-clock').WorldClock; - effectPanel?: import('./module/system/effect-panel').EffectPanel; - rollItemMacro?: typeof import('./scripts/init').rollItemMacro; - rollActionMacro: typeof import('./scripts/init').rollActionMacro; - gm: { - calculateXP: Function; - launchTravelSheet: Function; - }; - }; - - socket: SocketIO.Socket & { - emit(message: Pick): void; - on(event: string, ...message: import('./scripts/socket').SocketEventCallback): void; - }; - - i18n: Localization & { - readonly translations: Localization['translations'] & DeepPartial; - _fallback: Localization['translations'] & TranslationsPF2e; - }; -} - -declare type ItemTypeMap = { - [K in keyof import('./scripts/config').ConfigPF2e['PF2E']['Item']['entityClasses']]: InstanceType< - import('./scripts/config').ConfigPF2e['PF2E']['Item']['entityClasses'][K] +type ItemTypeMap = { + [K in keyof ConfigPF2e['PF2E']['Item']['entityClasses']]: InstanceType< + ConfigPF2e['PF2E']['Item']['entityClasses'][K] >[]; }; -declare interface Actor { - itemTypes: ItemTypeMap; -} -declare namespace Items { - function registerSheet( - scope: string, - sheetClass: typeof import('@item/sheet/base').ItemSheetPF2e, - options: { types: string[]; makeDefault?: boolean }, - ): void; - function registerSheet( - scope: string, - sheetClass: S, - options: { types: string[]; makeDefault?: boolean }, - ): void; - function registerSheet( - scope: string, - sheetClass: S, - options: { types: string[]; makeDefault?: boolean }, - ): void; - function registerSheet( - scope: string, - sheetClass: S, - options: { types: string[]; makeDefault?: boolean }, - ): void; - function registerSheet( - scope: string, - sheetClass: S, - options: { types: string[]; makeDefault?: boolean }, - ): void; -} +declare global { + interface Game { + pf2e: { + actions: { [key: string]: Function }; + worldClock?: WorldClock; + effectPanel?: EffectPanel; + rollActionMacro: typeof rollActionMacro; + rollItemMacro: typeof rollItemMacro; + gm: { + calculateXP: typeof calculateXP; + launchTravelSheet: typeof launchTravelSheet; + }; + }; + } + + interface Actor { + itemTypes: ItemTypeMap; + } -declare interface Window { - PF2e: import('./module/pf2e-system').PF2eSystem; - DicePF2e: typeof import('./scripts/dice').DicePF2e; - PF2eStatusEffects: typeof import('./scripts/actor/status-effects').PF2eStatusEffects; - PF2eConditionManager: typeof import('./module/conditions').PF2eConditionManager; - PF2ModifierType: typeof import('./module/modifiers').PF2ModifierType; - PF2Modifier: typeof import('./module/modifiers').PF2Modifier; - AbilityModifier: typeof import('./module/modifiers').AbilityModifier; - ProficiencyModifier: typeof import('./module/modifiers').ProficiencyModifier; - PF2StatisticModifier: typeof import('./module/modifiers').PF2StatisticModifier; - PF2CheckModifier: typeof import('./module/modifiers').PF2CheckModifier; - PF2Check: typeof import('./module/system/rolls').PF2Check; + interface Window { + PF2e: PF2eSystem; + DicePF2e: typeof DicePF2e; + PF2eStatusEffects: typeof PF2eStatusEffects; + PF2eConditionManager: typeof PF2eConditionManager; + PF2ModifierType: typeof PF2ModifierType; + PF2Modifier: typeof PF2Modifier; + AbilityModifier: typeof AbilityModifier; + ProficiencyModifier: typeof ProficiencyModifier; + PF2StatisticModifier: typeof PF2StatisticModifier; + PF2CheckModifier: typeof PF2CheckModifier; + PF2Check: typeof PF2Check; + } + const game: Game; + const CONFIG: ConfigPF2e; + const canvas: Canvas; + let PF2e: PF2eSystem; + const BUILD_MODE: 'development' | 'production'; } -declare const game: Game< - import('./module/actor/actor').PF2EActor, - import('./module/item/item').PF2EItem, - import('./module/combat').PF2ECombat ->; -declare const CONFIG: import('./scripts/config').ConfigPF2e; -declare const canvas: Canvas; -declare let PF2e: import('./module/pf2e-system').PF2eSystem; -declare const BUILD_MODE: 'development' | 'production'; diff --git a/src/module/actor/sheet/base.ts b/src/module/actor/sheet/base.ts index 3d5f2f091f5..e2a6957325d 100644 --- a/src/module/actor/sheet/base.ts +++ b/src/module/actor/sheet/base.ts @@ -17,7 +17,7 @@ import { createConsumableFromSpell, SpellConsumableTypes } from '@item/spell-con import { Spell } from '@item/spell'; import { SpellcastingEntry } from '@item/spellcasting-entry'; import { PF2ECondition, PF2ESpell } from '@item/others'; -import { LocalizePF2e } from '@system/localization'; +import { LocalizePF2e } from '@system/localize'; /** * Extend the basic ActorSheet class to do all the PF2e things! diff --git a/src/module/item/sheet/abc.ts b/src/module/item/sheet/abc.ts index c8a785878a0..2763709c89c 100644 --- a/src/module/item/sheet/abc.ts +++ b/src/module/item/sheet/abc.ts @@ -7,7 +7,7 @@ import { PF2EBackground } from '@item/background'; import { PF2EClass } from '@item/class'; import { PF2EItem } from '@item/item'; import { TraitSelector5e } from '@system/trait-selector'; -import { LocalizePF2e } from '@system/localization'; +import { LocalizePF2e } from '@system/localize'; import { ABCSheetData } from './data-types'; import { ConfigPF2e } from '@scripts/config'; diff --git a/src/module/item/sheet/base.ts b/src/module/item/sheet/base.ts index deb942d3ed8..518281ed589 100644 --- a/src/module/item/sheet/base.ts +++ b/src/module/item/sheet/base.ts @@ -2,8 +2,8 @@ import { PF2EActor } from '@actor/actor'; import { getPropertySlots } from '../runes'; import { TraitSelector5e } from '@system/trait-selector'; import { LoreDetailsData, MartialData, WeaponData } from '../data-definitions'; -import { LocalizePF2e } from '@system/localization'; -import { ConfigPF2e } from 'src/scripts/config'; +import { LocalizePF2e } from '@system/localize'; +import { ConfigPF2e } from '@scripts/config'; import { AESheetData, SheetOptions, SheetSelections } from './data-types'; import { PF2EItem } from '@item/item'; import { PF2RuleElementData } from 'src/module/rules/rules-data-definitions'; @@ -558,7 +558,7 @@ export class ItemSheetPF2e extends ItemSheet = {}): Record { // create the expanded update data object const fd = new FormDataExtended(this.form, { editors: this.editors }); diff --git a/src/module/register-sheets.ts b/src/module/register-sheets.ts index 57bfa72e4d6..1db3b0c8a9c 100644 --- a/src/module/register-sheets.ts +++ b/src/module/register-sheets.ts @@ -3,10 +3,11 @@ import { KitSheetPF2e } from '@item/sheet/kit'; import { AncestrySheetPF2e } from '@item/sheet/ancestry'; import { BackgroundSheetPF2e } from '@item/sheet/background'; import { ClassSheetPF2e } from '@item/sheet/class'; +import { PF2EItem } from '@item/item'; export function registerSheets() { Items.unregisterSheet('core', ItemSheet); - Items.registerSheet('pf2e', ItemSheetPF2e, { + Items.registerSheet('pf2e', ItemSheetPF2e, { types: [ 'weapon', 'melee', diff --git a/src/module/settings/world-clock.ts b/src/module/settings/world-clock.ts index 31a377a974b..d569912d0fc 100644 --- a/src/module/settings/world-clock.ts +++ b/src/module/settings/world-clock.ts @@ -1,5 +1,5 @@ import { DateTime } from 'luxon'; -import { LocalizePF2e } from '../system/localization'; +import { LocalizePF2e } from '../system/localize'; type SettingsKey = 'dateTheme' | 'timeConvention' | 'playersCanView' | 'syncDarkness' | 'worldCreatedOn'; diff --git a/src/module/system/localization.ts b/src/module/system/localize.ts similarity index 56% rename from src/module/system/localization.ts rename to src/module/system/localize.ts index f1ee419de85..411d8e9c57a 100644 --- a/src/module/system/localization.ts +++ b/src/module/system/localize.ts @@ -1,14 +1,18 @@ +import * as translationsPF2e from 'static/lang/en.json'; + +type TranslationsPF2e = Record & typeof translationsPF2e; + export class LocalizePF2e { - private static _translations: typeof game.i18n._fallback; + private static _translations: TranslationsPF2e; - static get translations(): typeof game.i18n._fallback { + static get translations(): TranslationsPF2e { if (!game.ready) { throw Error('PF2e System | TranslationsPF2e instantiated too early'); } if (this._translations === undefined) { this._translations = mergeObject(game.i18n._fallback, game.i18n.translations, { enforceTypes: true, - }); + }) as TranslationsPF2e; } return this._translations; } diff --git a/src/module/system/world-clock/index.ts b/src/module/system/world-clock/index.ts index e919fdd89b3..8ca1b9275b2 100644 --- a/src/module/system/world-clock/index.ts +++ b/src/module/system/world-clock/index.ts @@ -1,6 +1,6 @@ import { DateTime } from 'luxon'; import { animateDarkness } from './animate-darkness'; -import { LocalizePF2e } from '../localization'; +import { LocalizePF2e } from '../localize'; interface WorldClockData { date: string; diff --git a/src/scripts/hooks/ready.ts b/src/scripts/hooks/ready.ts index 4416510871d..c40c11a8c99 100644 --- a/src/scripts/hooks/ready.ts +++ b/src/scripts/hooks/ready.ts @@ -1,18 +1,18 @@ -import { activateSocketListener } from '../socket'; +import { activateSocketListener } from '@scripts/socket'; import { PlayerConfigPF2e } from '../../module/user/player-config'; -import { WorldClock } from '../../module/system/world-clock'; -import { updateMinionActors } from '../actor/update-minions'; -import { MigrationRunner } from '../..//module/migration-runner'; +import { updateMinionActors } from '@scripts/actor/update-minions'; +import { MigrationRunner } from '../../module/migration-runner'; import { Migrations } from '../../module/migrations'; -import { EffectPanel } from '../../module/system/effect-panel'; -import { calculateXP } from '../macros/xp'; -import { launchTravelSheet } from '../../module/gm/travel/travel-speed-sheet'; -import { rollActionMacro, rollItemMacro } from '../init'; -import { raiseAShield } from '../macros/raise-a-shield'; -import { earnIncome } from '../macros/earn-income'; -import { PF2Actions } from '../../module/system/actions/actions'; +import { calculateXP } from '@scripts/macros/xp'; +import { launchTravelSheet } from '@scripts/macros/travel/travel-speed-sheet'; +import { rollActionMacro, rollItemMacro } from '@scripts/init'; +import { raiseAShield } from '@scripts/macros/raise-a-shield'; +import { earnIncome } from '@scripts/macros/earn-income'; +import { PF2Actions } from '@system/actions/actions'; import { PF2eConditionManager } from '../../module/conditions'; -import { PF2eStatusEffects } from '../actor/status-effects'; +import { PF2eStatusEffects } from '@scripts/actor/status-effects'; +import { WorldClock } from '@system/world-clock'; +import { EffectPanel } from '@system/effect-panel'; export function listen(): void { Hooks.once('ready', () => { diff --git a/src/scripts/macros/raise-a-shield.ts b/src/scripts/macros/raise-a-shield.ts index 377da720184..8321f6ef9c8 100644 --- a/src/scripts/macros/raise-a-shield.ts +++ b/src/scripts/macros/raise-a-shield.ts @@ -2,7 +2,7 @@ import { PF2ECharacter } from '@actor/character'; import { PF2ENPC } from '@actor/npc'; import { PF2EEffect } from '@item/effect'; import { ActionDefaultOptions } from '../..//module/system/actions/actions'; -import { LocalizePF2e } from '../../module/system/localization'; +import { LocalizePF2e } from '../../module/system/localize'; /** Effect: Raise a Shield */ const ITEM_UUID = 'Compendium.pf2e.equipment-effects.2YgXoHvJfrDHucMr'; diff --git a/src/module/gm/travel/travel-speed-sheet.ts b/src/scripts/macros/travel/travel-speed-sheet.ts similarity index 98% rename from src/module/gm/travel/travel-speed-sheet.ts rename to src/scripts/macros/travel/travel-speed-sheet.ts index 77cfef17b62..26190fec1ef 100644 --- a/src/module/gm/travel/travel-speed-sheet.ts +++ b/src/scripts/macros/travel/travel-speed-sheet.ts @@ -10,8 +10,8 @@ import { TravelDuration, Trip, } from './travel-speed'; -import { Fraction, zip } from '../../utils'; -import { PF2EActor } from 'src/module/actor/actor'; +import { Fraction, zip } from '@utils'; +import { PF2EActor } from '@actor/actor'; type DetectionModeData = 'none' | 'everything' | 'before'; type SpeedUnitData = 'feet' | 'miles'; @@ -296,5 +296,5 @@ function toArray(data: Record): T[] { } export function launchTravelSheet(actors: PF2EActor[]): void { - new TravelSpeedSheet(null, { actors }).render(true); + new TravelSpeedSheet({}, { actors }).render(true); } diff --git a/src/module/gm/travel/travel-speed.ts b/src/scripts/macros/travel/travel-speed.ts similarity index 99% rename from src/module/gm/travel/travel-speed.ts rename to src/scripts/macros/travel/travel-speed.ts index 5c9782e2b47..94dfe574972 100644 --- a/src/module/gm/travel/travel-speed.ts +++ b/src/scripts/macros/travel/travel-speed.ts @@ -1,8 +1,8 @@ +import { sum, Fraction } from '@utils'; + /** * Implementation of travel speed https://2e.aonprd.com/Rules.aspx?ID=470 */ -import { Fraction, sum } from '../../utils'; - export interface ExplorationOptions { practicedDefender: boolean; swiftSneak: boolean; diff --git a/tests/module/gm/travel/travel-speed.test.ts b/tests/module/gm/travel/travel-speed.test.ts index 445cf7b8198..190f748a325 100644 --- a/tests/module/gm/travel/travel-speed.test.ts +++ b/tests/module/gm/travel/travel-speed.test.ts @@ -9,7 +9,7 @@ import { Terrain, TerrainSlowdown, Trip, -} from '../../../../src/module/gm/travel/travel-speed'; +} from '@scripts/macros/travel/travel-speed'; const terrainModifiers: TerrainSlowdown = { normal: { numerator: 1, denominator: 1 }, diff --git a/tsconfig.json b/tsconfig.json index 935e1c8d486..d8bbea68a0d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,7 +16,8 @@ "@actor/*": ["src/module/actor/*"], "@item/*": ["src/module/item/*"], "@scripts/*": ["src/scripts/*"], - "@system/*": ["src/module/system/*"] + "@system/*": ["src/module/system/*"], + "@utils": ["src/module/utils"] }, "types": [ "jquery", diff --git a/types/foundry-pc-types/types/apps/forms/item-sheet.d.ts b/types/foundry-pc-types/types/apps/forms/item-sheet.d.ts index d6459c229c1..ac2a7811f3d 100644 --- a/types/foundry-pc-types/types/apps/forms/item-sheet.d.ts +++ b/types/foundry-pc-types/types/apps/forms/item-sheet.d.ts @@ -10,15 +10,20 @@ declare interface ItemSheetData extends BaseEntitySheetD * * System modifications may elect to override this class to better suit their own game system by re-defining the value * ``CONFIG.Item.sheetClass``. - * - * @param item The Item instance being displayed within the sheet. - * @param options Additional options which modify the rendering of the item. - * @param options.editable Is the item editable? Default is true. + + * @param item The Item instance being displayed within the sheet. + * @param [options] Additional options which modify the rendering of the item. */ declare class ItemSheet extends BaseEntitySheet { + /** @override */ + constructor(item: ItemType, options?: FormApplicationOptions); + /** @override */ static get defaultOptions(): BaseEntitySheetOptions; + /** @override */ + get id(): `item-${string}` | `actor-${string}-item-{string}`; + /** * A convenience reference to the Item entity */ diff --git a/types/foundry-pc-types/types/framework/entities/actor.d.ts b/types/foundry-pc-types/types/framework/entities/actor.d.ts index 8559cf1583b..d9815596419 100644 --- a/types/foundry-pc-types/types/framework/entities/actor.d.ts +++ b/types/foundry-pc-types/types/framework/entities/actor.d.ts @@ -8,8 +8,8 @@ declare interface ActorData extends BaseE sort: number; } -declare interface ActorClassConfig extends EntityClassConfig { - collection: Actors; +declare interface ActorClassConfig extends EntityClassConfig { + collection: Actors; embeddedEntities: { ActiveEffect: 'effects'; OwnedItem: 'items'; @@ -25,7 +25,7 @@ declare interface ActorClassConfig extends EntityClassConfig { * @example Retrieve an existing Actor by its id * let actor = game.actors.get(actorId); */ -declare class Actors extends EntityCollection { +declare class Actors extends EntityCollection { /** * A mapping of synthetic Token Actors which are currently active within the viewed Scene. * Each Actor is referenced by the Token.id. @@ -43,10 +43,10 @@ declare class Actors extends EntityCollection( + static registerSheet( scope: string, - sheetClass: new (object: S['actor'], options?: FormApplicationOptions) => S, - options: { types: string[]; makeDefault?: boolean }, + sheetClass: new (actor: A, options?: FormApplicationOptions) => A['sheet'], + options?: RegisterSheetOptions, ): void; /** @@ -87,9 +87,6 @@ declare class Actors extends EntityCollection extends Entity { - data: ActorData; - _data: ActorData; - /** * A reference to a placed Token which creates a synthetic Actor */ @@ -105,19 +102,16 @@ declare class Actor extends Entity { */ overrides: Record; - /** The item's collection of ActiveEffects */ + /** The actor's collection of ActiveEffects */ effects: Collection; - /** overload */ - get sheet(): ActorSheet; - /** * Cache an Array of allowed Token images if using a wildcard path */ protected _tokenImages: string[] | null; /** @override */ - static get config(): ActorClassConfig; + static get config(): ActorClassConfig; /* -------------------------------------------- */ /* Data Preparation */ @@ -309,18 +303,23 @@ declare class Actor extends Entity { embeddedName: 'ActiveEffect', child: ActiveEffectData, options: EntityCreateOptions, - userId: string + userId: string, ): void; protected _onCreateEmbeddedEntity( embeddedName: 'OwnedItem', child: ItemType['data'], options: EntityCreateOptions, - userId: string + userId: string, ): void; protected _onCreateEmbeddedEntity( embeddedName: 'ActiveEffect' | 'OwnedItem', child: ActiveEffectData | ItemType['data'], options: EntityCreateOptions, - userId: string + userId: string, ): void; } + +declare interface Actor { + data: ActorData; + _data: ActorData; +} diff --git a/types/foundry-pc-types/types/framework/entities/item.d.ts b/types/foundry-pc-types/types/framework/entities/item.d.ts index 1aeee3213c9..23b9e68b951 100644 --- a/types/foundry-pc-types/types/framework/entities/item.d.ts +++ b/types/foundry-pc-types/types/framework/entities/item.d.ts @@ -3,7 +3,7 @@ * The items collection is accessible within the game as game.items */ -declare class Items extends EntityCollection { +declare class Items extends EntityCollection { /* -------------------------------------------- */ /* Collection Properties */ /* -------------------------------------------- */ @@ -15,6 +15,16 @@ declare class Items extends EntityCollection( + scope: string, + sheetClass: new (item: I, options?: FormApplicationOptions) => I['sheet'], + options?: RegisterSheetOptions, + ): void; + /** * Unregister an Item sheet class, removing it from the list of avaliable sheet Applications to use * See EntitySheetConfig.unregisterSheet for details @@ -27,18 +37,6 @@ declare class Items extends EntityCollection; -declare interface ItemClassConfig extends EntityClassConfig { - collection: Items; +declare interface ItemClassConfig extends EntityClassConfig { + collection: Items; embeddedEntities: { ActiveEffect: 'effects'; }; @@ -63,17 +61,11 @@ declare type ItemCreateData = DeepPartial; type _Actor = Actor>; declare class Item extends Entity { - data: BaseItemData; - _data: BaseItemData; - /** The item's collection of ActiveEffects */ effects: Collection; - /** @overload */ - constructor(data: BaseEntityData, options?: ItemConstructorOptions); - /** @override */ - static get config(): ItemClassConfig; + static get config(): ItemClassConfig; /** @override */ prepareData(): void; @@ -135,3 +127,8 @@ declare class Item extends Entity { getEmbeddedEntity(collection: 'ActiveEffect', id: string, { strict }?: { strict?: boolean }): ActiveEffect['data']; getEmbeddedEntity(collection: string, id: string, { strict }?: { strict?: boolean }): never; } + +declare interface Item extends Entity { + data: BaseItemData; + _data: BaseItemData; +} diff --git a/types/foundry-pc-types/types/framework/entity.d.ts b/types/foundry-pc-types/types/framework/entity.d.ts index 2b445a85e75..c211610703d 100644 --- a/types/foundry-pc-types/types/framework/entity.d.ts +++ b/types/foundry-pc-types/types/framework/entity.d.ts @@ -184,13 +184,13 @@ declare class Entity { * let actor = game.entities.actors[0]; * actor.sheet; // ActorSheet */ - get sheet(): BaseEntitySheet; + get sheet(): BaseEntitySheet; /** * Obtain a reference to the BaseEntitySheet implementation which should be used to render the Entity instance * configuration sheet. */ - protected get _sheetClass(): any; + protected get _sheetClass(): BaseEntitySheet; /** * Return a reference to the Folder which this Entity belongs to, if any. @@ -493,22 +493,22 @@ declare class Entity { embeddedName: string, child: BaseEntityData | EmbeddedEntityData, options: EntityCreateOptions, - userId: string + userId: string, ): void; - /** - * Handle Embedded Entity updates within this Entity with specific callback steps. - * This function is triggered once per EmbeddedEntity which is updated. - * It therefore may run multiple times per creation workflow. - * Any steps defined here should run on a per-EmbeddedEntity basis. - * Steps that should run once for the whole batch should go in _onModifyEmbeddedEntity() - */ + /** + * Handle Embedded Entity updates within this Entity with specific callback steps. + * This function is triggered once per EmbeddedEntity which is updated. + * It therefore may run multiple times per creation workflow. + * Any steps defined here should run on a per-EmbeddedEntity basis. + * Steps that should run once for the whole batch should go in _onModifyEmbeddedEntity() + */ protected _onUpdateEmbeddedEntity( embeddedName: string, child: BaseEntityData | EmbeddedEntityData, updateData: EntityUpdateData | EmbeddedEntityUpdateData, options: EntityUpdateOptions, - userId: string + userId: string, ): void; /** diff --git a/webpack.config.ts b/webpack.config.ts index 30cfe381c55..b11fd7b36d1 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -123,6 +123,7 @@ const config: Configuration = { '@item': path.resolve(__dirname, 'src/module/item'), '@scripts': path.resolve(__dirname, 'src/scripts'), '@system': path.resolve(__dirname, 'src/module/system'), + '@utils': path.resolve(__dirname, 'src/module/utils.ts'), }, extensions: ['.ts'], },