Add possibility to delete and edit effects in the actor sheet

This commit is contained in:
Johannes Loher 2021-07-22 02:02:35 +02:00
parent 4d2a7d1686
commit 808dab7f5a
15 changed files with 91 additions and 51 deletions

View file

@ -130,7 +130,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
html.find(".item-change").on("change", this.onItemChange.bind(this));
html.find(".effect-create").on("click", this.onEffectCreate.bind(this));
html.find(".control-effect").on("click", this.onControlEffect.bind(this));
html.find(".rollable-item").on("click", this.onRollItem.bind(this));
@ -244,17 +244,44 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
}
}
protected onEffectCreate(event: JQuery.ClickEvent): void {
protected onControlEffect(event: JQuery.ClickEvent): void {
event.preventDefault();
const a = event.currentTarget;
switch (a.dataset["action"]) {
case "create":
return this.onCreateEffect();
case "edit":
return this.onEditEffect(event);
case "delete":
return this.onDeleteEffect(event);
}
}
protected onCreateEffect(): void {
const createData = {
label: "New Effect",
icon: "icons/svg/aura.svg",
origin: this.actor.uuid,
};
ActiveEffect.create(createData, { parent: this.actor });
}
protected onEditEffect(event: JQuery.ClickEvent): void {
const id = $(event.currentTarget).parents(".effect").data("effectId");
const effect = this.actor.effects.get(id);
if (!effect) {
throw new Error(getGame().i18n.format("DS4.ErrorActorDoesNotHaveEffect", { id, actor: this.actor.name }));
}
effect.sheet.render(true);
}
protected onDeleteEffect(event: JQuery.ClickEvent): void {
const li = $(event.currentTarget).parents(".effect");
const id = li.data("effectId");
this.actor.deleteEmbeddedDocuments("ActiveEffect", [id]);
li.slideUp(200, () => this.render(false));
}
/**
* Handle clickable item rolls.
* @param event - The originating click event

View file

@ -15,6 +15,7 @@ export default async function registerHandlebarsPartials(): Promise<void> {
"systems/ds4/templates/sheets/actor/components/checks.hbs",
"systems/ds4/templates/sheets/actor/components/combat-value.hbs",
"systems/ds4/templates/sheets/actor/components/combat-values.hbs",
"systems/ds4/templates/sheets/actor/components/control-button-group.hbs",
"systems/ds4/templates/sheets/actor/components/core-value.hbs",
"systems/ds4/templates/sheets/actor/components/core-values.hbs",
"systems/ds4/templates/sheets/actor/components/creature-properties.hbs",
@ -24,7 +25,6 @@ export default async function registerHandlebarsPartials(): Promise<void> {
"systems/ds4/templates/sheets/actor/components/item-list-entry.hbs",
"systems/ds4/templates/sheets/actor/components/item-list-header.hbs",
"systems/ds4/templates/sheets/actor/components/items-overview.hbs",
"systems/ds4/templates/sheets/actor/components/overview-control-buttons.hbs",
"systems/ds4/templates/sheets/actor/components/profile.hbs",
"systems/ds4/templates/sheets/actor/components/rollable-image.hbs",
"systems/ds4/templates/sheets/actor/components/talent-rank-equation.hbs",