feat: update for v10
This commit is contained in:
parent
6277e27056
commit
f25b46a226
63 changed files with 41349 additions and 24332 deletions
|
@ -37,14 +37,14 @@ export class DS4ActorSheet extends ActorSheet {
|
|||
get template() {
|
||||
const basePath = "systems/ds4/templates/sheets/actor";
|
||||
if (!getGame().user?.isGM && this.actor.limited) return `${basePath}/limited-sheet.hbs`;
|
||||
return `${basePath}/${this.actor.data.type}-sheet.hbs`;
|
||||
return `${basePath}/${this.actor.type}-sheet.hbs`;
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async getData(options) {
|
||||
async getData(options = {}) {
|
||||
const itemsByType = Object.fromEntries(
|
||||
Object.entries(this.actor.itemTypes).map(([itemType, items]) => {
|
||||
return [itemType, items.map((item) => item.data).sort((a, b) => (a.sort || 0) - (b.sort || 0))];
|
||||
return [itemType, [...items].sort((a, b) => (a.sort || 0) - (b.sort || 0))];
|
||||
}),
|
||||
);
|
||||
|
||||
|
@ -53,35 +53,39 @@ export class DS4ActorSheet extends ActorSheet {
|
|||
...effect.toObject(),
|
||||
sourceName: await effect.getCurrentSourceName(),
|
||||
factor: effect.factor,
|
||||
isEffectivelyEnabled: !effect.data.disabled && !effect.isSurpressed,
|
||||
isEffectivelyEnabled: !effect.disabled && !effect.isSurpressed,
|
||||
};
|
||||
});
|
||||
const enrichedEffects = await Promise.all(enrichedEffectPromises);
|
||||
|
||||
const data = {
|
||||
const context = {
|
||||
...this.addTooltipsToData(await super.getData(options)),
|
||||
config: DS4,
|
||||
itemsByType,
|
||||
enrichedEffects,
|
||||
settings: getDS4Settings(),
|
||||
};
|
||||
return data;
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds tooltips to the attributes, traits, and combatValues of the actor data of the given {@link ActorSheet.Data}.
|
||||
* @param {object} data
|
||||
* Adds tooltips to the attributes, traits, and combatValues of the given context object.
|
||||
* @param {object} context
|
||||
* @protected
|
||||
*/
|
||||
addTooltipsToData(data) {
|
||||
const valueGroups = [data.data.data.attributes, data.data.data.traits, data.data.data.combatValues];
|
||||
addTooltipsToData(context) {
|
||||
const valueGroups = [
|
||||
context.data.system.attributes,
|
||||
context.data.system.traits,
|
||||
context.data.system.combatValues,
|
||||
];
|
||||
|
||||
valueGroups.forEach((valueGroup) => {
|
||||
Object.values(valueGroup).forEach((attribute) => {
|
||||
attribute.tooltip = this.getTooltipForValue(attribute);
|
||||
});
|
||||
});
|
||||
return data;
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,13 +158,9 @@ export class DS4ActorSheet extends ActorSheet {
|
|||
* @protected
|
||||
*/
|
||||
onCreateItem(event) {
|
||||
const { type, ...data } = foundry.utils.deepClone(event.currentTarget.dataset);
|
||||
const { type } = foundry.utils.deepClone(event.currentTarget.dataset);
|
||||
const name = getGame().i18n.localize(`DS4.New${type.capitalize()}Name`);
|
||||
const itemData = {
|
||||
name: name,
|
||||
type: type,
|
||||
data: data,
|
||||
};
|
||||
const itemData = { name, type };
|
||||
Item.create(itemData, { parent: this.actor, pack: this.actor.pack ?? undefined });
|
||||
}
|
||||
|
||||
|
@ -394,24 +394,25 @@ export class DS4ActorSheet extends ActorSheet {
|
|||
const dataPath = target.dataset["dataPath"];
|
||||
enforce(dataPath !== undefined, `Could not find property 'dataPath' in the dataset of ${target}`);
|
||||
const dataPath2 = target.dataset["dataPath2"];
|
||||
/** @type {import("../../documents/item/item").DS4Item[]}*/
|
||||
const items = this.actor.items.filter((item) => item.type === type);
|
||||
items.sort((a, b) => a.data.sort - b.data.sort);
|
||||
items.sort((a, b) => a.sort - b.sort);
|
||||
|
||||
/**
|
||||
* @param {boolean} invert Whether or not to inverse the sort order
|
||||
* @returns {(a: import("../../documents/item/item").DS4Item, b: import("../../documents/item/item").DS4Item) => number} A function for sorting items
|
||||
*/
|
||||
const sortFunction = (invert) => (a, b) => {
|
||||
const propertyA = getProperty(a.data, dataPath);
|
||||
const propertyB = getProperty(b.data, dataPath);
|
||||
const propertyA = getProperty(a, dataPath);
|
||||
const propertyB = getProperty(b, dataPath);
|
||||
const comparison =
|
||||
typeof propertyA === "string" || typeof propertyB === "string"
|
||||
? compareAsStrings(propertyA, propertyB, invert)
|
||||
: compareAsNumbers(propertyA, propertyB, invert);
|
||||
|
||||
if (comparison === 0 && dataPath2 !== undefined) {
|
||||
const propertyA = getProperty(a.data, dataPath);
|
||||
const propertyB = getProperty(b.data, dataPath);
|
||||
const propertyA = getProperty(a, dataPath);
|
||||
const propertyB = getProperty(b, dataPath);
|
||||
return typeof propertyA === "string" || typeof propertyB === "string"
|
||||
? compareAsStrings(propertyA, propertyB, invert)
|
||||
: compareAsNumbers(propertyA, propertyB, invert);
|
||||
|
@ -441,14 +442,14 @@ export class DS4ActorSheet extends ActorSheet {
|
|||
* @override
|
||||
*/
|
||||
async _onDropItem(event, data) {
|
||||
const item = await Item.fromDropData(data);
|
||||
if (item && !this.actor.canOwnItemType(item.data.type)) {
|
||||
const item = await Item.implementation.fromDropData(data);
|
||||
if (item && !this.actor.canOwnItemType(item.type)) {
|
||||
notifications.warn(
|
||||
getGame().i18n.format("DS4.WarningActorCannotOwnItem", {
|
||||
actorName: this.actor.name,
|
||||
actorType: this.actor.data.type,
|
||||
actorType: this.actor.type,
|
||||
itemName: item.name,
|
||||
itemType: item.data.type,
|
||||
itemType: item.type,
|
||||
}),
|
||||
);
|
||||
return false;
|
||||
|
|
|
@ -13,4 +13,13 @@ export class DS4CharacterActorSheet extends DS4ActorSheet {
|
|||
classes: ["sheet", "ds4-actor-sheet", "ds4-character-sheet"],
|
||||
});
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async getData(options = {}) {
|
||||
const context = await super.getData(options);
|
||||
context.data.system.profile.biography = await TextEditor.enrichHTML(context.data.system.profile.biography, {
|
||||
async: true,
|
||||
});
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,4 +13,14 @@ export class DS4CreatureActorSheet extends DS4ActorSheet {
|
|||
classes: ["sheet", "ds4-actor-sheet", "ds4-creature-sheet"],
|
||||
});
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async getData(options = {}) {
|
||||
const context = await super.getData(options);
|
||||
context.data.system.baseInfo.description = await TextEditor.enrichHTML(
|
||||
context.data.system.baseInfo.description,
|
||||
{ async: true },
|
||||
);
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
import { DS4 } from "../config";
|
||||
import { DS4ActiveEffect } from "../documents/active-effect";
|
||||
import { isDS4ItemDataTypePhysical } from "../documents/item/item-data-source-base";
|
||||
import { notifications } from "../ui/notifications";
|
||||
import { enforce, getGame } from "../utils/utils";
|
||||
import { disableOverriddenFields } from "./sheet-helpers";
|
||||
|
@ -29,19 +28,22 @@ export class DS4ItemSheet extends ItemSheet {
|
|||
/** @override */
|
||||
get template() {
|
||||
const basePath = "systems/ds4/templates/sheets/item";
|
||||
return `${basePath}/${this.item.data.type}-sheet.hbs`;
|
||||
return `${basePath}/${this.item.type}-sheet.hbs`;
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async getData() {
|
||||
const data = {
|
||||
...(await super.getData()),
|
||||
async getData(options = {}) {
|
||||
const superContext = await super.getData(options);
|
||||
superContext.data.system.description = await TextEditor.enrichHTML(superContext.data.system.description, {
|
||||
async: true,
|
||||
});
|
||||
const context = {
|
||||
...superContext,
|
||||
config: DS4,
|
||||
isOwned: this.item.isOwned,
|
||||
actor: this.item.actor,
|
||||
isPhysical: isDS4ItemDataTypePhysical(this.item.data.data),
|
||||
};
|
||||
return data;
|
||||
return context;
|
||||
}
|
||||
|
||||
/** @override */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue