87 lines
2.3 KiB
JavaScript
87 lines
2.3 KiB
JavaScript
/**
|
|
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
|
|
* @extends {Actor}
|
|
*/
|
|
|
|
import { RdDUtility } from "./rdd-utility.js";
|
|
|
|
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) {
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
rollCompetence( compName ) {
|
|
|
|
let compItem = RdDUtility.findCompetence( this.data.items, compName);
|
|
console.log("Roll !", compItem );
|
|
renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', compItem).then(dlg =>
|
|
{
|
|
new Dialog(
|
|
{
|
|
title: "Test de compétence",
|
|
content: dlg,
|
|
buttons:
|
|
{
|
|
rollButton:
|
|
{
|
|
label: "Lancer"
|
|
//callback: html => dialogOptions.callback(html, roll)
|
|
}
|
|
},
|
|
default: "rollButton"
|
|
}).render(true);
|
|
});
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @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;
|
|
}
|
|
}
|