import { FoundryPage, UserRole, DocumentOwnershipLevel } from "./types/index.js"; import { DeprecationTracker } from "./deprecations.js"; /** * Provides methods for direct manipulation of the Foundry VTT state. */ export declare class FoundryState { private page; private systemId; private deprecationTracker?; private adapter; constructor(page: FoundryPage, systemId?: string, deprecationTracker?: DeprecationTracker | undefined); /** * Sets the system adapter to use. */ setSystem(systemId: string): void; /** * Creates a new Foundry VTT document. * * Routed through {@link getGameAdapter} rather than a raw page.evaluate - * core Document Data Model behavior, kept behind the same version-adapted * seam as createEmbeddedDocuments, in case a future Foundry generation * changes it (see #86). * * @param documentName The type of document (e.g., "Actor", "Item"). * @param data The document data. */ createDocument(documentName: string, data: Record): Promise; /** * Updates an existing document in Foundry VTT. * @param documentName The name of the document type. * @param id The ID of the document to update. * @param delta The data to update. */ updateDocument(documentName: string, id: string, delta: Record): Promise; /** * Deletes a document in Foundry VTT. * @param documentName The name of the document type. * @param id The ID of the document to delete. */ deleteDocument(documentName: string, id: string): Promise; /** * Gets a document by its ID. * @param documentName The name of the document type. * @param id The ID of the document. */ getDocument(documentName: string, id: string): Promise; /** * Gets a document by its name. * @param documentName The name of the document type. * @param name The name of the document. */ getDocumentByName(documentName: string, name: string): Promise; /** * Creates a new User. */ createUser(name: string, role?: UserRole, password?: string): Promise; /** * Sets a user's role. */ setUserRole(userId: string, role: UserRole): Promise; /** * Configures a specific permission for a user role. */ setRolePermission(permission: string, role: UserRole, allowed: boolean): Promise; /** * Grants currency to an actor. * @param actorName The name of the actor. * @param amount The amount of currency to grant. * @param currency The type of currency (e.g., "gp", "sp"). */ grantCurrency(actorName: string, amount: number, currency?: string): Promise; /** * Gets the verification parameters for a currency update. */ getCurrencyVerifyParams(actorName: string, amount: number, currency?: string): { key: string; predicate: (data: Record, extra?: Record) => boolean; }; /** * Sets an actor's HP. * @param actorName The name of the actor. * @param value The new HP value. * @param max The new max HP value (optional). */ setActorHP(actorName: string, value: number, max?: number): Promise; /** * Rolls a specific roll for an actor. * @param actorName The name of the actor. * @param formula The roll formula (e.g., "1d20 + 5"). * @param label A label for the roll. */ roll(actorName: string, formula: string, label?: string): Promise; /** * Executes a macro by name. * @param name The name of the macro. * @param args Arguments to pass to the macro. */ executeMacro(name: string, ...args: unknown[]): Promise; /** * Manually triggers a Foundry VTT hook. * @param hookName The name of the hook (e.g., "renderActorSheet"). * @param args Arguments to pass to the hook. */ triggerHook(hookName: string, ...args: unknown[]): Promise; /** * Emits a socket event via the Foundry VTT socket. * @param eventName The name of the event. * @param data The data to emit. */ emitSocket(eventName: string, data: unknown): Promise; /** * Waits for a specific Foundry VTT hook to be called. * @param hookName The name of the hook. * @param timeout The timeout in milliseconds. * @returns The first argument passed to the hook. */ waitForHook(hookName: string, timeout?: number): Promise; /** * Waits for a specific socket event to be received. * @param eventName The name of the event. * @param timeout The timeout in milliseconds. */ waitForSocket(eventName: string, timeout?: number): Promise; /** * Sets a user's default/"assigned" character by updating `user.character`. * * This does **not** grant the user any ownership of the actor — it only * sets which actor Foundry treats as "theirs" for UI conveniences (e.g. * the character portrait in the player list). Many modules gate actual * visibility/interaction on document ownership instead * (`actor.ownership[userId]`), which this method does not touch. Use * {@link setActorOwnership} for that — and note that raw ownership is * stored data, not effective permission; use `actor.testUserPermission()` * for a real capability check (it also accounts for GM/role overrides). */ assignActorToUser(userId: string, actorId: string): Promise; /** * Sets a user's stored document ownership level on an actor * (`actor.ownership[userId]`), independent of {@link assignActorToUser}. * This is what most modules that gate behavior on "does this user own * this actor" actually read (e.g. Owner-only vs. Observer-or-above * visibility rules). It is stored data, not effective permission — a GM * or elevated role can still have access despite a lower/absent entry * here. For a real capability check, use `actor.testUserPermission()`. */ setActorOwnership(actorId: string, userId: string, level?: DocumentOwnershipLevel): Promise; /** * Updates an existing user. */ updateUser(userId: string, delta: Record): Promise; /** * Creates a test actor. */ createTestActor(name?: string): Promise; /** * Creates a test Item embedded on an existing actor, using the current * system adapter's minimal-but-valid item shape ({@link * SystemStateAdapter.getTestItemData}) rather than a payload hardcoded * for one system - different systems can reject the same minimal Item * data (e.g. pf2e 8.5.0 tightened `_validateType`), so this needs the * same per-system seam createTestActor already has. */ createTestItem(parentId: string, name?: string): Promise<{} | null>; /** * Creates one or more embedded documents on an existing parent document - * e.g. Items on an Actor (inventory, conditions), Tokens on a Scene, * Combatants on a Combat. This is distinct from {@link createDocument}: * that creates top-level world documents (`documentClass.create()`), * while embedded documents live on a parent instance * (`parent.createEmbeddedDocuments()`) and only make sense in that * context - e.g. an Item embedded on an Actor is that actor's inventory * entry, not a standalone world Item. * * Routed through {@link getGameAdapter} (not a raw page.evaluate here) * because this is core Document Data Model behavior, not * system-specific - kept behind the same version-adapted seam as * createDocument/updateDocument in GameAdapter, in case a future Foundry * generation changes it, even though it's been stable since V12. * * @param parentType The parent's document type, e.g. "Actor", "Scene". * @param parentId The parent document's ID. * @param embeddedName The embedded document type, e.g. "Item", "Token". * @param data One data object per document to create. */ createEmbeddedDocuments(parentType: string, parentId: string, embeddedName: string, data: Record[], options?: Record): Promise; /** * Convenience singular form of {@link createEmbeddedDocuments} - creates * exactly one embedded document and returns it directly instead of a * one-element array. */ createEmbeddedDocument(parentType: string, parentId: string, embeddedName: string, data: Record, options?: Record): Promise<{} | null>; /** * Sets or updates a Foundry VTT setting. * * This calls `game.settings.set()` directly, bypassing Foundry's * Settings *form* UI entirely — including the native "Reload * required" confirmation dialog that form shows for settings * registered with `requiresReload: true` (that dialog is form * behavior, not a `game.settings.set()` side effect; see * `handleReload()` in helpers.ts, which only applies to the * UI-driven path). A setting written this way still behaves as * "stale" client-side until a reload happens. * * Pass `{ reload: true }` to have this method reload the page * itself when (and only when) the setting is registered with * `requiresReload: true` — otherwise handle the reload yourself * (`page.reload()` + `waitForReady(page)`) or drive the actual * Settings form UI and use `handleReload()`. */ setSetting(module: string, key: string, value: unknown, options?: { reload?: boolean; }): Promise; }