forked from foundryvtt/pf2e
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…ndryvtt#8421) The method was made #private in V11, so we're locked out.
- Loading branch information
Showing
6 changed files
with
55 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,6 @@ | ||
import { ChatMessagePF2e } from "./chat-message/index.ts"; | ||
|
||
export class MacroPF2e extends Macro { | ||
/** Raise permission requirement of world macro visibility to observer */ | ||
override get visible(): boolean { | ||
return this.permission >= CONST.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER; | ||
} | ||
|
||
/** Allow unbound variables to be shadowed in script's evaluation scope */ | ||
protected override _executeScript({ | ||
actor, | ||
token, | ||
}: { actor?: Actor<TokenDocument<Scene | null> | null>; token?: Token | null } = {}): void { | ||
// Add variables to the evaluation scope | ||
const speaker = ChatMessagePF2e.getSpeaker(); | ||
const character = game.user.character; | ||
actor ??= game.actors.get(speaker.actor ?? ""); | ||
token ??= canvas.ready ? canvas.tokens.get(speaker.token ?? "") : null; | ||
|
||
// Attempt script execution | ||
const AsyncFunction = async function () {}.constructor as { new (...args: string[]): Function }; | ||
const command = ["{", this.command, "}"].join("\n"); | ||
const fn = new AsyncFunction("speaker", "actor", "token", "character", command); | ||
try { | ||
return fn.call(this, speaker, actor, token, character); | ||
} catch { | ||
ui.notifications.error("There was an error in your macro syntax. See the console (F12) for details"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,67 @@ | ||
import type { Document, DocumentMetadata } from "../abstract/module.d.ts"; | ||
import type { DataModel, Document, DocumentMetadata } from "../abstract/module.d.ts"; | ||
import type { BaseUser } from "./module.d.ts"; | ||
import type * as fields from "../data/fields.d.ts"; | ||
|
||
/** The Macro document model. */ | ||
export default class BaseMacro extends Document<null> { | ||
static override get metadata(): MacroMetadata; | ||
|
||
static override defineSchema(): MacroSchema; | ||
|
||
/** The default icon used for newly created Macro documents. */ | ||
static DEFAULT_ICON: ImageFilePath; | ||
|
||
/* -------------------------------------------- */ | ||
/* Model Methods */ | ||
/* -------------------------------------------- */ | ||
|
||
override testUserPermission(user: BaseUser, permission: unknown, options?: { exact?: boolean }): boolean; | ||
|
||
/* -------------------------------------------- */ | ||
/* Database Event Handlers */ | ||
/* -------------------------------------------- */ | ||
|
||
protected override _preCreate( | ||
data: PreDocumentId<MacroSource>, | ||
options: DocumentModificationContext<null>, | ||
user: BaseUser | ||
): Promise<void>; | ||
|
||
/** Is a user able to update an existing Macro document? */ | ||
protected static _canUpdate(user: BaseUser, doc: BaseMacro, data: MacroSource): boolean; | ||
/* -------------------------------------------- */ | ||
/* Deprecations and Compatibility */ | ||
/* -------------------------------------------- */ | ||
|
||
/** Is a user able to delete an existing Macro document? */ | ||
protected static _canDelete(user: BaseUser, doc: BaseMacro): boolean; | ||
/** @inheritdoc */ | ||
static shimData(data: object, options: object): object; | ||
} | ||
|
||
export default interface BaseMacro extends Document<null> { | ||
export default interface BaseMacro extends Document<null>, ModelPropsFromSchema<MacroSchema> { | ||
readonly _source: MacroSource; | ||
|
||
get documentName(): (typeof BaseMacro)["metadata"]["name"]; | ||
} | ||
|
||
export interface MacroSource { | ||
_id: string; | ||
name: string; | ||
type: "chat" | "script"; | ||
img: ImageFilePath; | ||
actorIds: string[]; | ||
author: string; | ||
command: string; | ||
scope: string; | ||
folder?: string | null; | ||
sort: number; | ||
ownership: Record<string, DocumentOwnershipLevel>; | ||
flags: DocumentFlags; | ||
} | ||
|
||
interface MacroMetadata extends DocumentMetadata { | ||
name: "Macro"; | ||
collection: "macros"; | ||
label: "DOCUMENT.Macro"; | ||
isPrimary: true; | ||
types: ["script", "chat"]; | ||
permissions: { | ||
create: "PLAYER"; | ||
update: (typeof BaseMacro)["_canUpdate"]; | ||
delete: (typeof BaseMacro)["_canDelete"]; | ||
}; | ||
} | ||
|
||
type MacroSchema = { | ||
_id: fields.DocumentIdField; | ||
name: fields.StringField<string, string, true, false, false>; | ||
type: fields.StringField<MacroType, MacroType, true, false, true>; | ||
author: fields.ForeignDocumentField<DataModel>; | ||
img: fields.FilePathField<ImageFilePath>; | ||
scope: fields.StringField<MacroScope, MacroScope, true, false, true>; | ||
command: fields.StringField<string, string, true, false, true>; | ||
folder: fields.ForeignDocumentField; | ||
sort: fields.IntegerSortField; | ||
ownership: fields.DocumentOwnershipField; | ||
flags: fields.ObjectField<DocumentFlags>; | ||
_stats: fields.DocumentStatsField; | ||
}; | ||
|
||
type MacroSource = SourceFromSchema<MacroSchema>; |