Simplify getting the source name of effects

This commit is contained in:
Johannes Loher 2021-07-20 02:35:55 +02:00
parent e39d245aff
commit 4d2a7d1686
6 changed files with 17 additions and 17 deletions

View file

@ -125,7 +125,7 @@
"DS4.EffectEnabled": "Aktiv", "DS4.EffectEnabled": "Aktiv",
"DS4.EffectEnabledAbbr": "A", "DS4.EffectEnabledAbbr": "A",
"DS4.EffectLabel": "Bezeichnung", "DS4.EffectLabel": "Bezeichnung",
"DS4.EffectSource": "Quelle", "DS4.EffectSourceName": "Quelle",
"DS4.ActorName": "Name", "DS4.ActorName": "Name",
"DS4.ActorImageAltText": "Bild des Aktors", "DS4.ActorImageAltText": "Bild des Aktors",
"DS4.ActorTypeCharacter": "Charakter", "DS4.ActorTypeCharacter": "Charakter",

View file

@ -125,7 +125,7 @@
"DS4.EffectEnabled": "Enabled", "DS4.EffectEnabled": "Enabled",
"DS4.EffectEnabledAbbr": "E", "DS4.EffectEnabledAbbr": "E",
"DS4.EffectLabel": "Label", "DS4.EffectLabel": "Label",
"DS4.EffectSource": "Source", "DS4.EffectSourceName": "Source",
"DS4.ActorName": "Name", "DS4.ActorName": "Name",
"DS4.ActorImageAltText": "Image of the Actor", "DS4.ActorImageAltText": "Image of the Actor",
"DS4.ActorTypeCharacter": "Character", "DS4.ActorTypeCharacter": "Character",

View file

@ -21,4 +21,11 @@ export class DS4ActiveEffect extends ActiveEffect {
} }
return super.apply(actor, change); return super.apply(actor, change);
} }
/**
* A public wrapper for {@link ActiveEffect#_getSourceName}.
*/
async getSourceName(): Promise<string> {
return this._getSourceName();
}
} }

View file

@ -11,7 +11,6 @@ import { getCanvas, getGame } from "../../helpers";
import { DS4Item } from "../../item/item"; import { DS4Item } from "../../item/item";
import { DS4Settings, getDS4Settings } from "../../settings"; import { DS4Settings, getDS4Settings } from "../../settings";
import notifications from "../../ui/notifications"; import notifications from "../../ui/notifications";
import { DS4Actor } from "../actor";
import { isCheck } from "../actor-data-properties"; import { isCheck } from "../actor-data-properties";
/** /**
@ -61,16 +60,10 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
}), }),
); );
const enrichedEffectPromises = this.actor.effects.toObject().map(async (effect) => { const enrichedEffectPromises = this.actor.effects.map(async (effect) => {
const originatingDocument = effect.origin !== undefined ? await fromUuid(effect.origin) : undefined;
const source =
(originatingDocument instanceof DS4Actor || originatingDocument instanceof DS4Item
? originatingDocument.name
: null) ?? undefined;
return { return {
...effect, ...effect.toObject(),
source, sourceName: await effect.getSourceName(),
}; };
}); });
const enrichedEffects = await Promise.all(enrichedEffectPromises); const enrichedEffects = await Promise.all(enrichedEffectPromises);
@ -335,5 +328,5 @@ interface DS4ActorSheetData extends ActorSheet.Data<ActorSheet.Options> {
type ActiveEffectDataSource = foundry.data.ActiveEffectData["_source"]; type ActiveEffectDataSource = foundry.data.ActiveEffectData["_source"];
interface EnrichedActiveEffectDataSource extends ActiveEffectDataSource { interface EnrichedActiveEffectDataSource extends ActiveEffectDataSource {
source?: string; sourceName: string;
} }

View file

@ -22,8 +22,8 @@ SPDX-License-Identifier: MIT
{{!-- label --}} {{!-- label --}}
<div title="{{effectData.label}}">{{effectData.label}}</div> <div title="{{effectData.label}}">{{effectData.label}}</div>
{{!-- source --}} {{!-- source name --}}
<div>{{effectData.source}}</div> <div>{{effectData.sourceName}}</div>
{{!-- control buttons --}} {{!-- control buttons --}}
{{> systems/ds4/templates/sheets/actor/components/overview-control-buttons.hbs {{> systems/ds4/templates/sheets/actor/components/overview-control-buttons.hbs

View file

@ -18,8 +18,8 @@ SPDX-License-Identifier: MIT
{{!-- label --}} {{!-- label --}}
<div>{{localize 'DS4.EffectLabel'}}</div> <div>{{localize 'DS4.EffectLabel'}}</div>
{{!-- origin --}} {{!-- source name --}}
<div>{{localize 'DS4.EffectSource'}}</div> <div>{{localize 'DS4.EffectSourceName'}}</div>
{{!-- control buttons placeholder --}} {{!-- control buttons placeholder --}}
<div></div> <div></div>