forked from public/bol
initial import
This commit is contained in:
122
module/actor/actor-sheet.js
Normal file
122
module/actor/actor-sheet.js
Normal file
@ -0,0 +1,122 @@
|
||||
/**
|
||||
* Extend the basic ActorSheet with some very simple modifications
|
||||
* @extends {ActorSheet}
|
||||
*/
|
||||
export class BoLActorSheet extends ActorSheet {
|
||||
|
||||
/** @override */
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
classes: ["bol", "sheet", "actor"],
|
||||
template: "systems/bol/templates/actor/actor-sheet.hbs",
|
||||
width: 600,
|
||||
height: 600,
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "stats" }]
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
getData() {
|
||||
console.debug("getData");
|
||||
const actor = super.getData();
|
||||
console.log(actor.data);
|
||||
actor.data.details = actor.data.data.details;
|
||||
actor.data.attributes = Object.values(actor.data.data.attributes);
|
||||
actor.data.aptitudes = Object.values(actor.data.data.aptitudes);
|
||||
actor.data.resources = Object.values(actor.data.data.resources);
|
||||
actor.data.equipment = actor.data.items.filter(i => i.type === "item");
|
||||
actor.data.features = {
|
||||
"origin" : actor.data.items.find(i => i.type === "feature" && i.data.subtype === "origin"),
|
||||
"race" : actor.data.items.find(i => i.type === "feature" && i.data.subtype === "race"),
|
||||
"careers" : actor.data.items.filter(i => i.type === "feature" && i.data.subtype === "career"),
|
||||
"boons" : actor.data.items.filter(i => i.type === "feature" && i.data.subtype === "boon"),
|
||||
"flaws" : actor.data.items.filter(i => i.type === "feature" && i.data.subtype === "flaw")
|
||||
};
|
||||
// data.attributes = ["String", "Number", "Boolean"];
|
||||
// for (let attr of Object.values(data.data.attributes)) {
|
||||
// attr.isCheckbox = attr.dtype === "Boolean";
|
||||
// }
|
||||
return actor;
|
||||
}
|
||||
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// Everything below here is only needed if the sheet is editable
|
||||
if (!this.options.editable) return;
|
||||
|
||||
// Add Inventory Item
|
||||
html.find('.item-create').click(this._onItemCreate.bind(this));
|
||||
|
||||
// Update Inventory Item
|
||||
html.find('.item-edit').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
const item = this.actor.items.get(li.data("itemId"));
|
||||
console.log(item);
|
||||
item.sheet.render(true);
|
||||
});
|
||||
|
||||
// Delete Inventory Item
|
||||
html.find('.item-delete').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
this.actor.deleteEmbeddedDocuments("Item", [li.data("itemId")])
|
||||
li.slideUp(200, () => this.render(false));
|
||||
});
|
||||
|
||||
// Rollable abilities.
|
||||
html.find('.rollable').click(this._onRoll.bind(this));
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Handle creating a new Owned Item for the actor using initial data defined in the HTML dataset
|
||||
* @param {Event} event The originating click event
|
||||
* @private
|
||||
*/
|
||||
_onItemCreate(event) {
|
||||
event.preventDefault();
|
||||
const header = event.currentTarget;
|
||||
// Get the type of item to create.
|
||||
const type = header.dataset.type;
|
||||
// Grab any data associated with this control.
|
||||
const data = duplicate(header.dataset);
|
||||
// Initialize a default name.
|
||||
const name = `New ${type.capitalize()}`;
|
||||
// Prepare the item object.
|
||||
const itemData = {
|
||||
name: name,
|
||||
type: type,
|
||||
data: data
|
||||
};
|
||||
// Remove the type from the dataset since it's in the itemData.type prop.
|
||||
delete itemData.data["type"];
|
||||
|
||||
// Finally, create the item!
|
||||
return this.actor.createEmbeddedDocuments("Item", [itemData]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle clickable rolls.
|
||||
* @param {Event} event The originating click event
|
||||
* @private
|
||||
*/
|
||||
_onRoll(event) {
|
||||
event.preventDefault();
|
||||
const element = event.currentTarget;
|
||||
const dataset = element.dataset;
|
||||
|
||||
if (dataset.roll) {
|
||||
let roll = new Roll(dataset.roll, this.actor.data.data);
|
||||
let label = dataset.label ? `Rolling ${dataset.label}` : '';
|
||||
roll.roll().toMessage({
|
||||
speaker: ChatMessage.getSpeaker({ actor: this.actor }),
|
||||
flavor: label
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
37
module/actor/actor.js
Normal file
37
module/actor/actor.js
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
|
||||
* @extends {Actor}
|
||||
*/
|
||||
export class BoLActor extends Actor {
|
||||
/** @override */
|
||||
prepareData() {
|
||||
super.prepareData();
|
||||
|
||||
console.debug("prepareData");
|
||||
|
||||
const actorData = this.data;
|
||||
// console.log(actorData);
|
||||
// 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 === 'character') this._prepareCharacterData(actorData);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Prepare Character type specific data
|
||||
// */
|
||||
// _prepareCharacterData(actorData) {
|
||||
// const data = actorData.data;
|
||||
//
|
||||
// // Make modifications to data here. For example:
|
||||
//
|
||||
// // Loop through ability scores, and add their modifiers to our sheet output.
|
||||
// for (let [key, ability] of Object.entries(data.abilities)) {
|
||||
// // Calculate the modifier using d20 rules.
|
||||
// ability.mod = Math.floor((ability.value - 10) / 2);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
Reference in New Issue
Block a user