Improve Simple Worldbuilding sheet layout and macro syntax

This commit is contained in:
Andrew 2020-04-18 16:14:51 -07:00
parent 6dbee061d6
commit d405a18f53
8 changed files with 350 additions and 138 deletions

35
module/actor.js Normal file
View file

@ -0,0 +1,35 @@
/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
* @extends {Actor}
*/
export class SimpleActor extends Actor {
/** @override */
getRollData() {
const data = super.getRollData();
const shorthand = game.settings.get("worldbuilding", "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;
}
}