Refactor for better readability (addressed CR comments)
This commit is contained in:
parent
30aed22c03
commit
e545e3f030
5 changed files with 80 additions and 49 deletions
|
@ -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,33 +10,40 @@ import notifications from "../ui/notifications";
|
|||
* @param slot - The hotbar slot to use.
|
||||
*/
|
||||
export async function createRollCheckMacro(check: Check, slot: string): Promise<void> {
|
||||
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(
|
||||
{
|
||||
command,
|
||||
name: DS4.i18n.checks[check],
|
||||
type: "script",
|
||||
// TODO: img, should be addressed in https://git.f3l.de/dungeonslayers/ds4/-/issues/79
|
||||
flags: { "ds4.checkMacro": true },
|
||||
},
|
||||
{ displaySheet: false },
|
||||
));
|
||||
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 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],
|
||||
type: "script",
|
||||
// TODO: img, should be addressed in https://git.f3l.de/dungeonslayers/ds4/-/issues/79
|
||||
flags: { "ds4.checkMacro": true },
|
||||
},
|
||||
{ displaySheet: false },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue