54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
/**
|
|
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
|
|
* @extends {Actor}
|
|
*/
|
|
export class RdDActor extends Actor {
|
|
prepareData() {
|
|
super.prepareData();
|
|
|
|
const actorData = this.data;
|
|
const data = actorData.data;
|
|
const flags = actorData.flags;
|
|
|
|
// Make separate methods for each Actor type (character, npc, etc.) to keep
|
|
// things organized.
|
|
if (actorData.type === 'personnage') this._prepareCharacterData(actorData);
|
|
}
|
|
|
|
/**
|
|
* Prepare Character type specific data
|
|
*/
|
|
_prepareCharacterData(actorData) {
|
|
|
|
}
|
|
|
|
/** @override */
|
|
getRollData() {
|
|
const data = super.getRollData();
|
|
const shorthand = game.settings.get("foundryvtt-reve-de-dragon", "macroShorthand");
|
|
|
|
// Re-map all attributes onto the base roll data
|
|
if ( !!shorthand ) {
|
|
for ( let [k, v] of Object.entries(data.attributes) ) {
|
|
if ( !(k in data) ) data[k] = v.value;
|
|
}
|
|
delete data.attributes;
|
|
}
|
|
|
|
// Map all items data using their slugified names
|
|
data.items = this.data.items.reduce((obj, i) => {
|
|
let key = i.name.slugify({strict: true});
|
|
let itemData = duplicate(i.data);
|
|
if ( !!shorthand ) {
|
|
for ( let [k, v] of Object.entries(itemData.attributes) ) {
|
|
if ( !(k in itemData) ) itemData[k] = v.value;
|
|
}
|
|
delete itemData["attributes"];
|
|
}
|
|
obj[key] = itemData;
|
|
return obj;
|
|
}, {});
|
|
return data;
|
|
}
|
|
}
|