Skip to content

Commit

Permalink
Adjust types and client code to load in Foundry V12
Browse files Browse the repository at this point in the history
  • Loading branch information
stwlam authored and CarlosFdez committed May 29, 2024
1 parent 118aab5 commit 3868fe0
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 131 deletions.
2 changes: 1 addition & 1 deletion src/module/actor/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class ActorPF2e<TParent extends TokenDocumentPF2e | null = TokenDocumentPF2e | n
.filter((e) => e.system.tokenIcon?.show && (e.isIdentified || game.user.isGM))
.map((e) => new TokenEffect(e));

return R.uniqBy(
return R.uniqueBy(
[super.temporaryEffects, fromConditions, fromEffects, this.synthetics.tokenEffectIcons].flat(),
(e) => e.icon,
);
Expand Down
2 changes: 1 addition & 1 deletion src/module/actor/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function userColorForActor(actor: ActorPF2e): HexColorString {
game.users.find((u) => u.character === actor) ??
game.users.players.find((u) => actor.testUserPermission(u, "OWNER")) ??
actor.primaryUpdater;
return user?.color ?? "#43dfdf";
return user?.color.toString() ?? "#43dfdf";
}

async function migrateActorSource(source: PreCreate<ActorSourcePF2e>): Promise<ActorSourcePF2e> {
Expand Down
2 changes: 1 addition & 1 deletion src/module/actor/token-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ActorPF2e } from "./base.ts";
export class TokenEffect implements TemporaryEffect {
#effect: AbstractEffectPF2e<ActorPF2e>;

tint: HexColorString | null = null;
tint: Color | null = null;

readonly isTemporary = true;

Expand Down
2 changes: 1 addition & 1 deletion src/module/apps/sidebar/encounter-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class EncounterTrackerPF2e<TEncounter extends EncounterPF2e | null> exten

const userIndicators = usersTargetting.map((user): HTMLElement => {
const icon = fontAwesomeIcon("location-crosshairs", { style: "duotone", fixedWidth: true });
icon.style.color = user.color;
icon.style.color = user.color.toString();
return icon;
});

Expand Down
13 changes: 10 additions & 3 deletions src/module/canvas/token/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ class TokenPF2e<TDocument extends TokenDocumentPF2e = TokenDocumentPF2e> extends
return this.document.sight.range >= dimensions.maxR ? dimensions.maxR : super.sightRange;
}

override initializeVisionSource(options?: { deleted?: boolean }): void {
super.initializeVisionSource(options);
if (!options?.deleted) {
this.hearing.initialize();
}
}

isAdjacentTo(token: TokenPF2e): boolean {
return this.distanceTo(token) === 5;
}
Expand Down Expand Up @@ -507,11 +514,11 @@ class TokenPF2e<TDocument extends TokenDocumentPF2e = TokenDocumentPF2e> extends
super.render(renderer);
if (!this.mesh) return;

const configuredTint = this.document.texture.tint ?? "#FFFFFF";
const configuredTint = this.document.texture.tint ?? Color.fromString("#FFFFFF");
if (this.mesh.tint !== 0 && this.detectionFilter instanceof OutlineOverlayFilter) {
this.mesh.tint = 0;
} else if (this.mesh.tint === 0 && configuredTint !== "#000000" && !this.detectionFilter) {
this.mesh.tint = Number(Color.fromString(configuredTint));
} else if (this.mesh.tint === 0 && configuredTint.toString() !== "#000000" && !this.detectionFilter) {
this.mesh.tint = Number(configuredTint);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/module/rules/rule-element/token-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TokenImageRuleElement extends RuleElementPF2e<TokenImageRuleSchema> {

if (!this.test()) return;

const texture: { src: VideoFilePath; scaleX?: number; scaleY?: number; tint?: HexColorString } = { src };
const texture: { src: VideoFilePath; scaleX?: number; scaleY?: number; tint?: Color } = { src };
if (this.scale) {
texture.scaleX = this.scale;
texture.scaleY = this.scale;
Expand Down
7 changes: 4 additions & 3 deletions src/module/rules/synthetics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { MaterialDamageEffect } from "@system/damage/types.ts";
import type { DegreeOfSuccessAdjustment } from "@system/degree-of-success.ts";
import type { Predicate } from "@system/predication.ts";
import type { Statistic } from "@system/statistic/index.ts";
import type { TokenSource } from "types/foundry/common/documents/token.d.ts";
import type { DamageAlteration } from "./rule-element/damage-alteration/alteration.ts";
import type { Suboption } from "./rule-element/roll-option/data.ts";

Expand Down Expand Up @@ -53,10 +54,10 @@ interface RuleElementSynthetics {
toggles: Record<string, Record<string, RollOptionToggle>>;
tokenEffectIcons: TokenEffect[];
tokenMarks: Map<TokenDocumentUUID, string>;
tokenOverrides: DeepPartial<Pick<foundry.documents.TokenSource, "light" | "name" | "alpha">> & {
tokenOverrides: DeepPartial<Pick<TokenSource, "light" | "name" | "alpha">> & {
texture?:
| { src: VideoFilePath; tint?: HexColorString }
| { src: VideoFilePath; tint?: HexColorString; scaleX: number; scaleY: number };
| { src: VideoFilePath; tint?: Color }
| { src: VideoFilePath; tint?: Color; scaleX: number; scaleY: number };
};
weaponPotency: Record<string, PotencySynthetic[]>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/module/system/client-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MigrationList, MigrationRunner } from "@module/migration/index.ts";
import { UserPF2e } from "@module/user/document.ts";
import * as R from "remeda";

class ClientDatabaseBackendPF2e extends ClientDatabaseBackend {
class ClientDatabaseBackendPF2e extends foundry.data.ClientDatabaseBackend {
protected override async _getDocuments(
documentClass: typeof foundry.abstract.Document,
context: DatabaseBackendGetContext,
Expand Down
2 changes: 1 addition & 1 deletion src/module/user/sheet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { UserPF2e } from "./document.ts";

/** Player-specific settings, stored as flags on each User */
export class UserConfigPF2e<TUser extends UserPF2e> extends UserConfig<TUser> {
export class UserConfigPF2e<TUser extends UserPF2e> extends foundry.applications.sheets.UserConfig<TUser> {
override async getData(options: DocumentSheetOptions): Promise<UserConfigData<TUser>> {
const data = await super.getData(options);
data.actors = data.actors.filter((a) => a.type !== "party");
Expand Down
7 changes: 0 additions & 7 deletions src/scripts/hooks/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ export const Ready = {
canvas.colorManager.initialize();
}

// Sort item types for display in sidebar create-item dialog
game.system.documentTypes.Item.sort((typeA, typeB) => {
return game.i18n
.localize(CONFIG.Item.typeLabels[typeA] ?? "")
.localeCompare(game.i18n.localize(CONFIG.Item.typeLabels[typeB] ?? ""));
});

game.pf2e.system.moduleArt.refresh().then(() => {
if (game.modules.get("babele")?.active && game.i18n.lang !== "en") {
// For some reason, Babele calls its own "ready" hook twice, and only the second one is genuine.
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/register-sheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export function registerSheets(): void {
});

// USER
Users.unregisterSheet("core", UserConfig);
Users.unregisterSheet("core", foundry.applications.sheets.UserConfig);
Users.registerSheet("pf2e", UserConfigPF2e, {
makeDefault: true,
label: () => game.i18n.format("SHEETS.DefaultDocumentSheet", { document: game.i18n.localize("DOCUMENT.User") }),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
export {};
/**
* The Application responsible for configuring a single User document.
* @extends {DocumentSheet}
*
* @param user The User document being configured.
* @param [options] Additional rendering options which modify the behavior of the form.
*/
export declare class UserConfig<TUser extends User> extends DocumentSheet<TUser> {
static override get defaultOptions(): DocumentSheetOptions;

declare global {
/**
* The Application responsible for configuring a single User document.
* @extends {DocumentSheet}
*
* @param user The User document being configured.
* @param [options] Additional rendering options which modify the behavior of the form.
*/
class UserConfig<TUser extends User> extends DocumentSheet<TUser> {
static override get defaultOptions(): DocumentSheetOptions;

override get title(): string;
override get title(): string;

override getData(options: DocumentSheetOptions): Promise<UserConfigData<TUser>>;
override getData(options: DocumentSheetOptions): Promise<UserConfigData<TUser>>;

override activateListeners(html: JQuery): void;
override activateListeners(html: JQuery): void;

/** Handle changing the user avatar image by opening a FilePicker */
protected _onEditAvatar(event: JQuery.TriggeredEvent): void;
}
/** Handle changing the user avatar image by opening a FilePicker */
protected _onEditAvatar(event: JQuery.TriggeredEvent): void;
}

declare global {
interface UserConfigData<TUser extends User> extends DocumentSheetData<TUser> {
user: User;
actors: Actor<null>[];
Expand Down
2 changes: 1 addition & 1 deletion types/foundry/client/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ declare global {
};

/** Configure the DatabaseBackend used to perform Document operations */
DatabaseBackend: ClientDatabaseBackend;
DatabaseBackend: foundry.data.ClientDatabaseBackend;

/** Configuration for the Actor document */
Actor: {
Expand Down
88 changes: 43 additions & 45 deletions types/foundry/client/data/abstract/client-backend.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,47 @@ import type { Socket } from "socket.io";
import type { DatabaseBackend, Document } from "../../../common/abstract/module.d.ts";

/** The client-side database backend implementation which handles Document modification operations. */
declare global {
class ClientDatabaseBackend extends DatabaseBackend {
/* -------------------------------------------- */
/* Document Modification Operations */
/* -------------------------------------------- */

protected override _getDocuments(
documentClass: typeof Document,
request: DatabaseBackendGetContext,
user: User,
): Promise<CompendiumIndexData[] | Document[]>;

protected override _createDocuments(
documentClass: typeof Document,
context: DatabaseBackendCreateContext<Document>,
user: User,
): Promise<ClientDocument[]>;

protected override _updateDocuments(
documentClass: typeof Document,
context: DatabaseBackendUpdateContext<Document>,
user: User,
): Promise<Document[]>;

protected override _deleteDocuments(
documentClass: typeof Document,
context: DatabaseBackendDeleteContext,
user: User,
): Promise<Document[]>;

/* -------------------------------------------- */
/* Socket Workflows */
/* -------------------------------------------- */

/** Activate the Socket event listeners used to receive responses from events which modify database documents */
activateSocketListeners(socket: Socket): void;

/* -------------------------------------------- */
/* Helper Methods */
/* -------------------------------------------- */

override getFlagScopes(): string[];

override getCompendiumScopes(): string[];
}
export declare class ClientDatabaseBackend extends DatabaseBackend {
/* -------------------------------------------- */
/* Document Modification Operations */
/* -------------------------------------------- */

protected override _getDocuments(
documentClass: typeof Document,
request: DatabaseBackendGetContext,
user: User,
): Promise<CompendiumIndexData[] | Document[]>;

protected override _createDocuments(
documentClass: typeof Document,
context: DatabaseBackendCreateContext<Document>,
user: User,
): Promise<ClientDocument[]>;

protected override _updateDocuments(
documentClass: typeof Document,
context: DatabaseBackendUpdateContext<Document>,
user: User,
): Promise<Document[]>;

protected override _deleteDocuments(
documentClass: typeof Document,
context: DatabaseBackendDeleteContext,
user: User,
): Promise<Document[]>;

/* -------------------------------------------- */
/* Socket Workflows */
/* -------------------------------------------- */

/** Activate the Socket event listeners used to receive responses from events which modify database documents */
activateSocketListeners(socket: Socket): void;

/* -------------------------------------------- */
/* Helper Methods */
/* -------------------------------------------- */

override getFlagScopes(): string[];

override getCompendiumScopes(): string[];
}
1 change: 1 addition & 0 deletions types/foundry/client/foundry/applications/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as sheets from "./sheets.ts";
1 change: 1 addition & 0 deletions types/foundry/client/foundry/applications/sheets.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { UserConfig } from "../../application/form-application/document-sheet/user-config.ts";
2 changes: 2 additions & 0 deletions types/foundry/client/foundry/data/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "../../../common/data/module.ts";
export { ClientDatabaseBackend } from "../../data/abstract/client-backend.ts";
13 changes: 13 additions & 0 deletions types/foundry/client/foundry/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** Abstract class definitions for fundamental concepts used throughout the Foundry Virtual Tabletop framework. */
export * as abstract from "../../common/abstract/module.ts";
/** Constant definitions used throughout the Foundry Virtual Tabletop framework. */
export * as CONST from "../../common/constants.ts";
/** Document definitions used throughout the Foundry Virtual Tabletop framework. */
export * as documents from "../../common/documents/module.ts";
/** Package data definitions, validations, and schema. */
export * as packages from "../../common/packages/module.ts";
/** Utility functions providing helpful functionality. */
export * as utils from "../../common/utils/module.ts";
export * as applications from "./applications/index.ts";
/** Data schema definitions for data models. */
export * as data from "./data/index.ts";
25 changes: 8 additions & 17 deletions types/foundry/client/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import type GSAP from "gsap";
import type HANDLEBARS from "handlebars";
import { showdown as SHOWDOWN } from "showdownf";
import "gsap";
import "handlebars";
import SHOWDOWN from "showdown";
import * as Foundry from "./foundry/index.ts";

declare global {
const CONST: typeof Constants;

namespace globalThis {
const Color = Utils.Color;
export import Handlebars = HANDLEBARS;
const gsap = GSAP;
export import showdown = SHOWDOWN;

namespace foundry {
const CONST = Constants;
const abstract = Abstract;
const data = Data;
const documents = Documents;
const utils = Utils;
}
export import CONST = Foundry.CONST;
export import Color = Foundry.utils.Color;
export import foundry = Foundry;
const showdown: typeof SHOWDOWN;
}
}
7 changes: 7 additions & 0 deletions types/foundry/client/pixi/placeables/token.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ declare global {
*/
updateLightSource({ defer, deleted }?: { defer?: boolean; deleted?: boolean }): void;

/**
* Update the VisionSource instance associated with this Token.
* @param {object} [options] Options which affect how the vision source is updated
* @param {boolean} [options.deleted] Indicate that this vision source has been deleted.
*/
initializeVisionSource(options?: { deleted?: boolean }): void;

/**
* Update an Token vision source associated for this token.
* @param [defer] Defer refreshing the LightingLayer to manually call that refresh later.
Expand Down
3 changes: 2 additions & 1 deletion types/foundry/common/data/fields.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as abstract from "../abstract/module.d.ts";
import type Color from "../utils/color.d.ts";
import type { TombstoneDataSchema } from "./data.d.ts";
import type { DataModelValidationFailure } from "./validation-failure.d.ts";

Expand Down Expand Up @@ -832,7 +833,7 @@ export class ColorField<
TRequired extends boolean = false,
TNullable extends boolean = true,
THasInitial extends boolean = true,
> extends StringField<HexColorString, HexColorString, TRequired, TNullable, THasInitial> {
> extends StringField<HexColorString, Color, TRequired, TNullable, THasInitial> {
protected static override get _defaults(): StringFieldOptions<HexColorString, boolean, boolean, boolean>;

protected override _validateType(value: unknown): boolean;
Expand Down
2 changes: 1 addition & 1 deletion types/foundry/common/data/module.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./data.ts";
export * as fields from "./fields.ts";
export * as validation from "./validation-failure.ts";
export * as validators from "./validators.ts";
export * from "./data.ts";
27 changes: 0 additions & 27 deletions types/foundry/common/module.d.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
import * as Abstract from "./abstract/module.ts";
import * as Constants from "./constants.ts";
import * as Data from "./data/module.ts";
import * as Documents from "./documents/module.ts";
import * as Packages from "./packages/module.ts";
import * as Utils from "./utils/module.ts";

// global-modifying module
import "./primitives/module.d.ts";
import "./types.ts";

declare global {
const CONST: typeof Constants;
namespace globalThis {
namespace foundry {
/** Constant definitions used throughout the Foundry Virtual Tabletop framework. */
export import CONST = Constants;
/** Abstract class definitions for fundamental concepts used throughout the Foundry Virtual Tabletop framework. */
export import abstract = Abstract;
/** Data schema definitions for data models. */
export import data = Data;
/** Document definitions used throughout the Foundry Virtual Tabletop framework. */
export import documents = Documents;
/** Package data definitions, validations, and schema. */
export import packages = Packages;
/** Utility functions providing helpful functionality. */
export import utils = Utils;
}
}
}
Loading

0 comments on commit 3868fe0

Please sign in to comment.