Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Add RegionDocumentPF2e and RegionBehaviorPF2e and implement RegionBehaviorPF2e#isOfType" #14882

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ import type {
TileDocumentPF2e,
TokenDocumentPF2e,
} from "@scene";
import type { RegionDocumentPF2e } from "@scene/region/document.ts";
import type { RegionBehaviorPF2e } from "@scene/region/region-behavior/document.ts";
import type { ActorDeltaPF2e } from "@scene/token-document/actor-delta.ts";
import type { PF2ECONFIG, StatusEffectIconTheme } from "@scripts/config/index.ts";
import type { DicePF2e } from "@scripts/dice.ts";
Expand Down Expand Up @@ -203,8 +201,8 @@ type ConfiguredConfig = Config<
ItemPF2e,
MacroPF2e,
MeasuredTemplateDocumentPF2e,
RegionDocumentPF2e<ScenePF2e | null>,
RegionBehaviorPF2e<RegionDocumentPF2e<ScenePF2e | null>>,
RegionDocument<ScenePF2e | null>,
RegionBehavior<RegionDocument<ScenePF2e | null>>,
TileDocumentPF2e,
TokenDocumentPF2e,
WallDocument<ScenePF2e | null>,
Expand Down
9 changes: 4 additions & 5 deletions src/module/actor/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
extractRollSubstitutions,
extractRollTwice,
} from "@module/rules/helpers.ts";
import { RegionBehaviorTypeInstances } from "@scene/region/region-behavior/types.ts";
import { EnvironmentTypeData } from "@scene/region-behaviors/terrain.ts";
import { eventToRollParams } from "@scripts/sheet-util.ts";
import { CheckCheckContext, CheckPF2e, CheckRoll } from "@system/check/index.ts";
import { DamageDamageContext, DamagePF2e } from "@system/damage/index.ts";
Expand Down Expand Up @@ -271,10 +271,9 @@ function createEnvironmentRollOptions(actor: ActorPF2e): Record<string, boolean>
const top = region.elevation.top ?? Infinity;
if (token.elevation < bottom || token.elevation > top) continue;

for (const behavior of region.behaviors.filter(
(b): b is RegionBehaviorTypeInstances["pf2eEnvironment"] => b.type === "pf2eEnvironment",
)) {
const system = behavior.system;
for (const behavior of region.behaviors.filter((b) => b.type === "pf2eEnvironment")) {
// todo: remove once type resolution is possible
const system = behavior.system as EnvironmentTypeData;
switch (system.mode) {
case "add": {
for (const terrain of system.environmentTypes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resetActors } from "@actor/helpers.ts";
import type { RegionEventPF2e } from "@scene/region/types.ts";
import type { TokenDocumentPF2e } from "@scene";
import type { RegionEventType } from "types/foundry/client-esm/data/region-behaviors/base.d.ts";
import type { SetField, StringField } from "types/foundry/common/data/fields.d.ts";

Expand Down Expand Up @@ -30,7 +30,7 @@ class EnvironmentBehaviorTypePF2e extends foundry.data.regionBehaviors.RegionBeh
};
}

protected override async _handleRegionEvent(event: RegionEventPF2e): Promise<void> {
protected override async _handleRegionEvent(event: RegionEvent<TokenDocumentPF2e>): Promise<void> {
if (event.name === "tokenEnter" || event.name === "tokenExit") {
if (event.data.token.actor) resetActors([event.data.token.actor], { tokens: true });
}
Expand All @@ -39,9 +39,7 @@ class EnvironmentBehaviorTypePF2e extends foundry.data.regionBehaviors.RegionBeh

interface EnvironmentBehaviorTypePF2e
extends foundry.data.regionBehaviors.RegionBehaviorType<EnvironmentTypeSchema>,
ModelPropsFromSchema<EnvironmentTypeSchema> {
readonly _source: SourceFromSchema<EnvironmentTypeSchema>;
}
ModelPropsFromSchema<EnvironmentTypeSchema> {}

type EnvironmentTypeSchema = {
environmentTypes: SetField<StringField>;
Expand Down
11 changes: 0 additions & 11 deletions src/module/scene/region/document.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/module/scene/region/region-behavior/document.ts

This file was deleted.

41 changes: 0 additions & 41 deletions src/module/scene/region/region-behavior/types.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/module/scene/region/types.ts

This file was deleted.

11 changes: 2 additions & 9 deletions src/module/scene/token-document/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ import type { TokenPF2e } from "@module/canvas/index.ts";
import { ChatMessagePF2e } from "@module/chat-message/document.ts";
import type { CombatantPF2e, EncounterPF2e } from "@module/encounter/index.ts";
import { computeSightAndDetectionForRBV } from "@scene/helpers.ts";
import { RegionDocumentPF2e } from "@scene/region/document.ts";
import { objectHasKey, sluggify } from "@util";
import * as R from "remeda";
import type { ScenePF2e } from "../document.ts";
import { TokenAura } from "./aura/index.ts";
import { TokenFlagsPF2e } from "./data.ts";
import type { TokenConfigPF2e } from "./sheet.ts";

class TokenDocumentPF2e<
TParent extends ScenePF2e | null = ScenePF2e | null,
TRegionDocument extends RegionDocumentPF2e<TParent> = RegionDocumentPF2e<TParent>,
> extends TokenDocument<TParent, TRegionDocument> {
class TokenDocumentPF2e<TParent extends ScenePF2e | null = ScenePF2e | null> extends TokenDocument<TParent> {
/** Has this document completed `DataModel` initialization? */
declare initialized: boolean;

Expand Down Expand Up @@ -452,10 +448,7 @@ class TokenDocumentPF2e<
}
}

interface TokenDocumentPF2e<
TParent extends ScenePF2e | null = ScenePF2e | null,
TRegionDocument extends RegionDocumentPF2e<TParent> = RegionDocumentPF2e<TParent>,
> extends TokenDocument<TParent, TRegionDocument> {
interface TokenDocumentPF2e<TParent extends ScenePF2e | null = ScenePF2e | null> extends TokenDocument<TParent> {
flags: TokenFlagsPF2e;

get actor(): ActorPF2e<this | null> | null;
Expand Down
6 changes: 1 addition & 5 deletions src/scripts/hooks/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import {
} from "@module/canvas/index.ts";
import { setPerceptionModes } from "@module/canvas/perception/modes.ts";
import { PointVisionSourcePF2e } from "@module/canvas/perception/point-vision-source.ts";
import { RegionDocumentPF2e } from "@scene/region/document.ts";
import { RegionBehaviorPF2e } from "@scene/region/region-behavior/document.ts";
import { EnvironmentBehaviorTypePF2e } from "@scene/region/region-behavior/types/environment.ts";
import { EnvironmentBehaviorTypePF2e } from "@scene/region-behaviors/terrain.ts";
import { PF2ECONFIG } from "@scripts/config/index.ts";
import { registerHandlebarsHelpers } from "@scripts/handlebars.ts";
import { registerFonts } from "@scripts/register-fonts.ts";
Expand Down Expand Up @@ -53,8 +51,6 @@ export const Init = {
CONFIG.Canvas.layers.templates.layerClass = TemplateLayerPF2e;
CONFIG.Canvas.visionSourceClass = PointVisionSourcePF2e;

CONFIG.Region.documentClass = RegionDocumentPF2e;
CONFIG.RegionBehavior.documentClass = RegionBehaviorPF2e;
CONFIG.RegionBehavior.dataModels.pf2eEnvironment = EnvironmentBehaviorTypePF2e;
CONFIG.RegionBehavior.typeLabels.pf2eEnvironment = "PF2E.Region.Environment.Label";
CONFIG.RegionBehavior.typeIcons.pf2eEnvironment = "fa-solid fa-mountain-sun";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ExecuteMacroRegionBehaviorType
extends RegionBehaviorType<ExecuteMacroRegionBehaviorTypeSchema>,
ModelPropsFromSchema<ExecuteMacroRegionBehaviorTypeSchema> {}

export type ExecuteMacroRegionBehaviorTypeSchema = {
type ExecuteMacroRegionBehaviorTypeSchema = {
/** The events that are handled by the behavior. */
events: EventsField;
/** The Macro UUID. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface ExecuteScriptRegionBehaviorType
extends RegionBehaviorType<ExecuteScriptRegionBehaviorTypeSchema>,
ModelPropsFromSchema<ExecuteScriptRegionBehaviorTypeSchema> {}

export type ExecuteScriptRegionBehaviorTypeSchema = {
type ExecuteScriptRegionBehaviorTypeSchema = {
/** The events that are handled by the behavior. */
events: EventsField;
/** The source code of the script. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface PauseGameRegionBehaviorType
extends RegionBehaviorType<PauseGameRegionBehaviorTypeSchema>,
ModelPropsFromSchema<PauseGameRegionBehaviorTypeSchema> {}

export type PauseGameRegionBehaviorTypeSchema = {
type PauseGameRegionBehaviorTypeSchema = {
/** Disable the behavior once a player-controlled Token enters the region? */
once: fields.BooleanField;
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface TeleportTokenRegionBehaviorType
extends RegionBehaviorType<TeleportTokenRegionBehaviorTypeSchema>,
ModelPropsFromSchema<TeleportTokenRegionBehaviorTypeSchema> {}

export type TeleportTokenRegionBehaviorTypeSchema = {
type TeleportTokenRegionBehaviorTypeSchema = {
/** The destination Region the Token is teleported to. */
destination: fields.DocumentUUIDField;
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ToggleBehaviorRegionBehaviorType
extends RegionBehaviorType<ToggleBehaviorRegionBehaviorTypeSchema>,
ModelPropsFromSchema<ToggleBehaviorRegionBehaviorTypeSchema> {}

export type ToggleBehaviorRegionBehaviorTypeSchema = {
type ToggleBehaviorRegionBehaviorTypeSchema = {
/** The events that are handled by the behavior. */
events: EventsField;
/** The Region Behavior UUIDs that are enabled. */
Expand Down
12 changes: 3 additions & 9 deletions types/foundry/client/data/documents/region-document.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ declare global {
static _activateSocketListeners(socket: unknown): void;

/** The tokens inside this region. */
tokens: Set<TokenDocument>;
tokens: Set<TokenDocument<TParent>>;

/**
* Trigger the Region event.
Expand Down Expand Up @@ -76,10 +76,7 @@ declare global {
TDocument extends RegionDocument = RegionDocument,
TUser extends User = User,
TTokenDocument extends TokenDocument = TokenDocument,
TCombatant extends Combatant<Combat | null, TTokenDocument | null> = Combatant<
Combat | null,
TTokenDocument | null
>,
TCombatant extends Combatant<Combat, TTokenDocument> = Combatant<Combat, TTokenDocument>,
> extends BaseRegionEvent<TDocument, TUser> {
name: "tokenRoundStart" | "tokenRoundEnd" | "tokenTurnStart" | "tokenTurnEnd";
data: {
Expand Down Expand Up @@ -124,10 +121,7 @@ declare global {
type RegionEvent<
TTokenDocument extends TokenDocument = TokenDocument,
TUser extends User = User,
TCombatant extends Combatant<Combat | null, TTokenDocument | null> = Combatant<
Combat | null,
TTokenDocument | null
>,
TCombatant extends Combatant<Combat, TTokenDocument> = Combatant<Combat, TTokenDocument>,
TDocument extends RegionDocument = RegionDocument,
> =
| BehaviorStatusRegionEvent<TDocument, TUser>
Expand Down
12 changes: 3 additions & 9 deletions types/foundry/client/data/documents/token-document.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type { CanvasBaseToken } from "./client-base-mixes.d.ts";

declare global {
class TokenDocument<
TParent extends Scene | null = Scene | null,
TRegionDocument extends RegionDocument<TParent> = RegionDocument<TParent>,
> extends CanvasBaseToken<TParent> {
class TokenDocument<TParent extends Scene | null = Scene | null> extends CanvasBaseToken<TParent> {
/* -------------------------------------------- */
/* Properties */
/* -------------------------------------------- */
Expand All @@ -13,7 +10,7 @@ declare global {
actors: Collection<Actor>;

/** The Regions this Token is currently in. */
regions: Set<TRegionDocument> | null;
regions: Set<RegionDocument> | null;

/**
* A lazily evaluated reference to the Actor this Token modifies.
Expand Down Expand Up @@ -197,10 +194,7 @@ declare global {
static getTrackedAttributeChoices(attributes?: TrackedAttributesDescription): TrackedAttributesDescription;
}

interface TokenDocument<
TParent extends Scene | null = Scene | null,
TRegionDocument extends RegionDocument<TParent> = RegionDocument<TParent>,
> extends CanvasBaseToken<TParent> {
interface TokenDocument<TParent extends Scene | null = Scene | null> extends CanvasBaseToken<TParent> {
delta: ActorDelta<this> | null;

get object(): Token<this> | null;
Expand Down
Loading