[Feature] Add Default Icons for Document Subtypes (#584)

Fixes #458

Co-authored-by: Joaquin Pereyra <joaquinpereyra98@users.noreply.github.com>
This commit is contained in:
joaquinpereyra98 2025-08-04 22:38:56 -03:00 committed by GitHub
parent 481652bf3f
commit 0feec77512
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 206 additions and 13 deletions

View file

@ -105,6 +105,13 @@ export default class DhpAdversary extends BaseDataActor {
};
}
/* -------------------------------------------- */
/**@inheritdoc */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/actors/dragon-head.svg';
/* -------------------------------------------- */
get attackBonus() {
return this.attack.roll.bonus;
}

View file

@ -69,6 +69,16 @@ export default class BaseDataActor extends foundry.abstract.TypeDataModel {
return schema;
}
/* -------------------------------------------- */
/**
* The default icon used for newly created Actors documents
* @type {string}
*/
static DEFAULT_ICON = null;
/* -------------------------------------------- */
/**
* Obtain a data object used to evaluate any dice rolls associated with this Item Type
* @param {object} [options] - Options which modify the getRollData method.

View file

@ -7,8 +7,10 @@ import { ActionField } from '../fields/actionField.mjs';
import DHCharacterSettings from '../../applications/sheets-configs/character-settings.mjs';
export default class DhCharacter extends BaseDataActor {
/**@override */
static LOCALIZATION_PREFIXES = ['DAGGERHEART.ACTORS.Character'];
/**@inheritdoc */
static get metadata() {
return foundry.utils.mergeObject(super.metadata, {
label: 'TYPES.Actor.character',
@ -18,6 +20,7 @@ export default class DhCharacter extends BaseDataActor {
});
}
/**@inheritdoc */
static defineSchema() {
const fields = foundry.data.fields;
@ -303,6 +306,8 @@ export default class DhCharacter extends BaseDataActor {
};
}
/* -------------------------------------------- */
get tier() {
const currentLevel = this.levelData.level.current;
return currentLevel === 1

View file

@ -9,6 +9,7 @@ import { resourceField, bonusField } from '../fields/actorField.mjs';
export default class DhCompanion extends BaseDataActor {
static LOCALIZATION_PREFIXES = ['DAGGERHEART.ACTORS.Companion'];
/**@inheritdoc */
static get metadata() {
return foundry.utils.mergeObject(super.metadata, {
label: 'TYPES.Actor.companion',
@ -18,6 +19,7 @@ export default class DhCompanion extends BaseDataActor {
});
}
/**@inheritdoc */
static defineSchema() {
const fields = foundry.data.fields;
@ -87,6 +89,13 @@ export default class DhCompanion extends BaseDataActor {
};
}
/* -------------------------------------------- */
/**@inheritdoc */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/actors/capybara.svg';
/* -------------------------------------------- */
get proficiency() {
return this.partner?.system?.proficiency ?? 1;
}

View file

@ -3,8 +3,10 @@ import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayFie
import DHEnvironmentSettings from '../../applications/sheets-configs/environment-settings.mjs';
export default class DhEnvironment extends BaseDataActor {
/**@override */
static LOCALIZATION_PREFIXES = ['DAGGERHEART.ACTORS.Environment'];
/**@inheritdoc */
static get metadata() {
return foundry.utils.mergeObject(super.metadata, {
label: 'TYPES.Actor.environment',
@ -14,6 +16,7 @@ export default class DhEnvironment extends BaseDataActor {
});
}
/**@inheritdoc */
static defineSchema() {
const fields = foundry.data.fields;
return {
@ -37,6 +40,13 @@ export default class DhEnvironment extends BaseDataActor {
};
}
/* -------------------------------------------- */
/**@inheritdoc */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/actors/forest.svg';
/* -------------------------------------------- */
get features() {
return this.parent.items.filter(x => x.type === 'feature');
}

View file

@ -19,10 +19,26 @@ export default class DHAncestry extends BaseDataItem {
};
}
/* -------------------------------------------- */
/**@override */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/items/family-tree.svg';
/* -------------------------------------------- */
/**
* Gets the primary feature.
* @type {foundry.documents.Item|null} Returns the item of the first feature with type "primary" or null if none is found.
*/
get primaryFeature() {
return this.features.find(x => x.type === CONFIG.DH.ITEM.featureSubTypes.primary)?.item;
}
/**
* Gets the secondary feature.
* @type {foundry.documents.Item|null} Returns the item of the first feature with type "secondary" or null if none is found.
*/
get secondaryFeature() {
return this.features.find(x => x.type === CONFIG.DH.ITEM.featureSubTypes.secondary)?.item;
}

View file

@ -42,12 +42,20 @@ export default class DHArmor extends AttachableItem {
};
}
/* -------------------------------------------- */
/**@override */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/items/chest-armor.svg';
/* -------------------------------------------- */
get customActions() {
return this.actions.filter(
action => !this.armorFeatures.some(feature => feature.actionIds.includes(action.id))
);
}
/**@inheritdoc */
async _preUpdate(changes, options, user) {
const allowed = await super._preUpdate(changes, options, user);
if (allowed === false) return false;
@ -68,7 +76,7 @@ export default class DHArmor extends AttachableItem {
return acc;
}, {});
for (var feature of added) {
for (const feature of added) {
const featureData = armorFeatures[feature.value];
if (featureData.effects?.length > 0) {
const embeddedItems = await this.parent.createEmbeddedDocuments(

View file

@ -79,6 +79,16 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
return schema;
}
/* -------------------------------------------- */
/**
* The default icon used for newly created Item documents
* @type {string}
*/
static DEFAULT_ICON = null;
/* -------------------------------------------- */
/**
* Convenient access to the item's actor, if it exists.
* @returns {foundry.documents.Actor | null}

View file

@ -81,6 +81,13 @@ export default class DHBeastform extends BaseDataItem {
};
}
/* -------------------------------------------- */
/**@override */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/items/wolf-head.svg';
/* -------------------------------------------- */
async _preCreate() {
if (!this.actor) return;

View file

@ -53,6 +53,13 @@ export default class DHClass extends BaseDataItem {
};
}
/* -------------------------------------------- */
/**@override */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/items/laurel-crown.svg';
/* -------------------------------------------- */
get hopeFeatures() {
return this.features.filter(x => x.type === CONFIG.DH.ITEM.featureSubTypes.hope).map(x => x.item);
}

View file

@ -13,10 +13,15 @@ export default class DHCommunity extends BaseDataItem {
/** @inheritDoc */
static defineSchema() {
const fields = foundry.data.fields;
return {
...super.defineSchema(),
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
};
}
/* -------------------------------------------- */
/**@override */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/items/village.svg';
}

View file

@ -22,4 +22,10 @@ export default class DHConsumable extends BaseDataItem {
consumeOnUse: new fields.BooleanField({ initial: false })
};
}
/* -------------------------------------------- */
/**@override */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/items/round-potion.svg';
}

View file

@ -33,6 +33,13 @@ export default class DHDomainCard extends BaseDataItem {
};
}
/* -------------------------------------------- */
/**@override */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/items/card-play.svg';
/* -------------------------------------------- */
/**@inheritdoc */
async _preCreate(data, options, user) {
const allowed = await super._preCreate(data, options, user);

View file

@ -13,6 +13,13 @@ export default class DHFeature extends BaseDataItem {
});
}
/* -------------------------------------------- */
/**@override */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/items/stars-stack.svg';
/* -------------------------------------------- */
/** @inheritDoc */
static defineSchema() {
const fields = foundry.data.fields;

View file

@ -19,4 +19,11 @@ export default class DHLoot extends BaseDataItem {
...super.defineSchema()
};
}
/* -------------------------------------------- */
/**@override */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/items/open-treasure-chest.svg';
/* -------------------------------------------- */
}

View file

@ -28,6 +28,13 @@ export default class DHSubclass extends BaseDataItem {
};
}
/* -------------------------------------------- */
/**@override */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/items/laurels.svg';
/* -------------------------------------------- */
get foundationFeatures() {
return this.features.filter(x => x.type === CONFIG.DH.ITEM.featureSubTypes.foundation).map(x => x.item);
}

View file

@ -80,6 +80,13 @@ export default class DHWeapon extends AttachableItem {
};
}
/* -------------------------------------------- */
/**@override */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/items/battered-axe.svg';
/* -------------------------------------------- */
get actionsList() {
return [this.attack, ...this.actions];
}

View file

@ -22,6 +22,23 @@ export default class DhpActor extends Actor {
return this.system.metadata.isNPC;
}
/* -------------------------------------------- */
/**@inheritdoc */
static getDefaultArtwork(actorData) {
const { type } = actorData;
const Model = CONFIG.Actor.dataModels[type];
const img = Model.DEFAULT_ICON ?? this.DEFAULT_ICON;
return {
img,
texture: {
src: img
}
};
}
/* -------------------------------------------- */
/** @inheritDoc */
getEmbeddedDocument(embeddedName, id, options) {
let doc;
@ -39,6 +56,7 @@ export default class DhpActor extends Actor {
return doc;
}
/**@inheritdoc */
async _preCreate(data, options, user) {
if ((await super._preCreate(data, options, user)) === false) return false;
@ -455,6 +473,7 @@ export default class DhpActor extends Actor {
return ActiveEffect.implementation.create(effect, { parent: this, keepId: true });
}
/**@inheritdoc */
getRollData() {
const rollData = super.getRollData();
rollData.system = this.system.getRollData();
@ -540,8 +559,8 @@ export default class DhpActor extends Actor {
updates.forEach(
u =>
(u.value =
u.key === 'fear' || this.system?.resources?.[u.key]?.isReversed === false ? u.value * -1 : u.value)
(u.value =
u.key === 'fear' || this.system?.resources?.[u.key]?.isReversed === false ? u.value * -1 : u.value)
);
await this.modifyResource(updates);
@ -587,9 +606,9 @@ export default class DhpActor extends Actor {
updates.forEach(
u =>
(u.value = !(u.key === 'fear' || this.system?.resources?.[u.key]?.isReversed === false)
? u.value * -1
: u.value)
(u.value = !(u.key === 'fear' || this.system?.resources?.[u.key]?.isReversed === false)
? u.value * -1
: u.value)
);
await this.modifyResource(updates);

View file

@ -74,8 +74,8 @@ export default class DHItem extends foundry.documents.Item {
isInventoryItem === true
? 'Inventory Items' //TODO localize
: isInventoryItem === false
? 'Character Items' //TODO localize
: 'Other'; //TODO localize
? 'Character Items' //TODO localize
: 'Other'; //TODO localize
return { value: type, label, group };
}
@ -118,6 +118,19 @@ export default class DHItem extends foundry.documents.Item {
return labels;
}
/* -------------------------------------------- */
/**@inheritdoc */
static getDefaultArtwork(itemData) {
const { type } = itemData;
const Model = CONFIG.Item.dataModels[type];
const img = Model.DEFAULT_ICON ?? this.DEFAULT_ICON;
return { img };
}
/* -------------------------------------------- */
async use(event) {
const actions = new Set(this.system.actionsList);
if (actions?.size) {
@ -139,10 +152,10 @@ export default class DHItem extends foundry.documents.Item {
this.type === 'ancestry'
? game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.ancestryTitle')
: this.type === 'community'
? game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.communityTitle')
: this.type === 'feature'
? game.i18n.localize('TYPES.Item.feature')
: game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.subclassFeatureTitle'),
? game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.communityTitle')
: this.type === 'feature'
? game.i18n.localize('TYPES.Item.feature')
: game.i18n.localize('DAGGERHEART.UI.Chat.foundationCard.subclassFeatureTitle'),
origin: origin,
img: this.img,
item: {