Merge branch '077-common-checks-macros-with-effects' into 76-common-checks-in-actor-sheets
This commit is contained in:
commit
537e41bf5f
5 changed files with 80 additions and 49 deletions
|
@ -198,8 +198,8 @@
|
|||
"DS4.ErrorUnexpectedAttackType": "Unerwartete Angriffsart '{actualType}', erwartete Angriffarten: {expectedTypes}",
|
||||
"DS4.ErrorCanvasIsNotInitialized": "Canvas ist noch nicht initialisiert.",
|
||||
"DS4.WarningItemMustBeEquippedToBeRolled": "Um für das Item '{name}' ({id}) vom Typ '{type}' zu würfeln, muss es ausgerüstet sein.",
|
||||
"DS4.WarningMustControlActorToUseRollItemMacro": "Um ein ein Item Würfel Makro zu nutzen muss ein Aktor kontolliert werden.",
|
||||
"DS4.WarningMustControlActorToUseRollCheckMacro": "Um ein ein Proben Würfel Makro zu nutzen muss ein Aktor kontolliert werden.",
|
||||
"DS4.WarningMustControlActorToUseRollItemMacro": "Um ein ein Item-Würfel-Makro zu nutzen muss ein Aktor kontrolliert werden.",
|
||||
"DS4.WarningMustControlActorToUseRollCheckMacro": "Um ein ein Proben-Würfel-Makro zu nutzen muss ein Aktor kontrolliert werden.",
|
||||
"DS4.WarningControlledActorDoesNotHaveItem": "Der kontrollierte Aktor '{actorName}' ({actorId}) hat kein Item mit der ID '{itemId}'.",
|
||||
"DS4.WarningItemIsNotRollable": "Für das Item '{name}' ({id}) vom Typ '{type}' kann nicht gewürfelt werden.",
|
||||
"DS4.WarningMacrosCanOnlyBeCreatedForOwnedItems": "Makros können nur für besessene Items angelegt werden.",
|
||||
|
|
|
@ -116,13 +116,13 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item, DS4ActorPreparedData>
|
|||
* The list of properties that are derived from others, given in dot notation.
|
||||
*/
|
||||
get derivedDataProperties(): Array<string> {
|
||||
return Object.keys(DS4.i18n.combatValues)
|
||||
.map((combatValue) => `data.combatValues.${combatValue}.total`)
|
||||
.concat(
|
||||
Object.keys(DS4.i18n.checks)
|
||||
.filter((check) => check !== "defend")
|
||||
.map((check) => `data.checks.${check}`),
|
||||
const combatValueProperties = Object.keys(DS4.i18n.combatValues).map(
|
||||
(combatValue) => `data.combatValues.${combatValue}.total`,
|
||||
);
|
||||
const checkProperties = Object.keys(DS4.i18n.checks)
|
||||
.filter((check) => check !== "defend")
|
||||
.map((check) => `data.checks.${check}`);
|
||||
return combatValueProperties.concat(checkProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
21
src/module/macros/helpers.ts
Normal file
21
src/module/macros/helpers.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { DS4Actor } from "../actor/actor";
|
||||
import { getCanvas } from "../helpers";
|
||||
|
||||
/**
|
||||
* Gets the currently active actor based on how {@link ChatMessage} determines
|
||||
* the current speaker.
|
||||
* @returns The currently active {@link DS4Actor} if any, and `undefined` otherwise.
|
||||
*/
|
||||
export function getActiveActor(): DS4Actor | undefined {
|
||||
const speaker = ChatMessage.getSpeaker();
|
||||
|
||||
const speakerToken = speaker.token ? getCanvas().tokens.get(speaker.token) : undefined;
|
||||
if (speakerToken) {
|
||||
return speakerToken.actor as DS4Actor;
|
||||
}
|
||||
|
||||
const speakerActor = speaker.actor ? game.actors?.get(speaker.actor) : undefined;
|
||||
if (speakerActor) {
|
||||
return speakerActor as DS4Actor;
|
||||
}
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
import { DS4Actor } from "../actor/actor";
|
||||
import { Check } from "../actor/actor-prepared-data";
|
||||
import { DS4 } from "../config";
|
||||
import { getCanvas } from "../helpers";
|
||||
import notifications from "../ui/notifications";
|
||||
import { getActiveActor } from "./helpers";
|
||||
|
||||
/**
|
||||
* Creates a macro from a check drop.
|
||||
|
@ -11,10 +10,21 @@ import notifications from "../ui/notifications";
|
|||
* @param slot - The hotbar slot to use.
|
||||
*/
|
||||
export async function createRollCheckMacro(check: Check, slot: string): Promise<void> {
|
||||
const macro = await getOrCreateRollCheckMacro(check);
|
||||
game.user?.assignHotbarMacro(macro, slot);
|
||||
}
|
||||
|
||||
async function getOrCreateRollCheckMacro(check: Check): Promise<Macro | null> {
|
||||
const command = `game.ds4.macros.rollCheck("${check}");`;
|
||||
const macro =
|
||||
game.macros?.entities.find((m) => m.name === DS4.i18n.checks[check] && m.data.command === command) ??
|
||||
(await Macro.create(
|
||||
|
||||
const existingMacro = game.macros?.entities.find(
|
||||
(m) => m.name === DS4.i18n.checks[check] && m.data.command === command,
|
||||
);
|
||||
if (existingMacro) {
|
||||
return existingMacro;
|
||||
}
|
||||
|
||||
return Macro.create(
|
||||
{
|
||||
command,
|
||||
name: DS4.i18n.checks[check],
|
||||
|
@ -23,21 +33,17 @@ export async function createRollCheckMacro(check: Check, slot: string): Promise<
|
|||
flags: { "ds4.checkMacro": true },
|
||||
},
|
||||
{ displaySheet: false },
|
||||
));
|
||||
game.user?.assignHotbarMacro(macro, slot);
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the roll check macro for the given check.
|
||||
*/
|
||||
export async function rollCheck(check: Check): Promise<void> {
|
||||
const speaker = ChatMessage.getSpeaker();
|
||||
const actor = (getCanvas().tokens.get(speaker.token ?? "")?.actor ?? game.actors?.get(speaker.actor ?? "")) as
|
||||
| DS4Actor
|
||||
| null
|
||||
| undefined;
|
||||
const actor = getActiveActor();
|
||||
if (!actor) {
|
||||
return notifications.warn(game.i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro"));
|
||||
}
|
||||
|
||||
return actor.rollCheck(check);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { DS4Actor } from "../actor/actor";
|
||||
import { getCanvas } from "../helpers";
|
||||
import { DS4ItemData } from "../item/item-data";
|
||||
import notifications from "../ui/notifications";
|
||||
import { getActiveActor } from "./helpers";
|
||||
|
||||
/**
|
||||
* Creates a macro from an item drop.
|
||||
|
@ -10,10 +9,19 @@ import notifications from "../ui/notifications";
|
|||
* @param slot - The hotbar slot to use
|
||||
*/
|
||||
export async function createRollItemMacro(itemData: DS4ItemData, slot: string): Promise<void> {
|
||||
const macro = await getOrCreateRollItemMacro(itemData);
|
||||
game.user?.assignHotbarMacro(macro, slot);
|
||||
}
|
||||
|
||||
async function getOrCreateRollItemMacro(itemData: DS4ItemData): Promise<Macro | null> {
|
||||
const command = `game.ds4.macros.rollItem("${itemData._id}");`;
|
||||
const macro =
|
||||
game.macros?.entities.find((m) => m.name === itemData.name && m.data.command === command) ??
|
||||
(await Macro.create(
|
||||
|
||||
const existingMacro = game.macros?.entities.find((m) => m.name === itemData.name && m.data.command === command);
|
||||
if (existingMacro) {
|
||||
return existingMacro;
|
||||
}
|
||||
|
||||
return Macro.create(
|
||||
{
|
||||
command,
|
||||
name: itemData.name,
|
||||
|
@ -22,22 +30,18 @@ export async function createRollItemMacro(itemData: DS4ItemData, slot: string):
|
|||
flags: { "ds4.itemMacro": true },
|
||||
},
|
||||
{ displaySheet: false },
|
||||
));
|
||||
game.user?.assignHotbarMacro(macro, slot);
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the roll item macro for the given itemId.
|
||||
*/
|
||||
export async function rollItem(itemId: string): Promise<void> {
|
||||
const speaker = ChatMessage.getSpeaker();
|
||||
const actor = (getCanvas().tokens.get(speaker.token ?? "")?.actor ?? game.actors?.get(speaker.actor ?? "")) as
|
||||
| DS4Actor
|
||||
| null
|
||||
| undefined;
|
||||
const actor = getActiveActor();
|
||||
if (!actor) {
|
||||
return notifications.warn(game.i18n.localize("DS4.WarningMustControlActorToUseRollItemMacro"));
|
||||
}
|
||||
|
||||
const item = actor.items?.get(itemId);
|
||||
if (!item) {
|
||||
return notifications.warn(
|
||||
|
|
Loading…
Reference in a new issue