protections
This commit is contained in:
@@ -1,89 +0,0 @@
|
||||
import { TotemActor } from "./actor.mjs";
|
||||
/**
|
||||
* @extends {TotemActor}
|
||||
*/
|
||||
export class TotemCharacter extends TotemActor {
|
||||
|
||||
/** @override */
|
||||
prepareData() {
|
||||
// Prepare data for the actor. Calling the super version of this executes
|
||||
// the following, in order: data reset (to clear active effects),
|
||||
// prepareBaseData(), prepareEmbeddedDocuments() (including active effects),
|
||||
// prepareDerivedData().
|
||||
super.prepareData();
|
||||
}
|
||||
|
||||
/** @override */
|
||||
prepareBaseData() {
|
||||
// Data modifications in this step occur before processing embedded
|
||||
// documents or derived data.
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
* Augment the basic actor data with additional dynamic data. Typically,
|
||||
* you'll want to handle most of your calculated/derived data in this step.
|
||||
* Data calculated in this step should generally not exist in template.json
|
||||
* (such as ability modifiers rather than ability scores) and should be
|
||||
* available both inside and outside of character sheets (such as if an actor
|
||||
* is queried and has a roll executed directly from it).
|
||||
*/
|
||||
prepareDerivedData() {
|
||||
const actorData = this;
|
||||
const systemData = actorData.system;
|
||||
const flags = actorData.flags.totem || {};
|
||||
|
||||
// Make separate methods for each Actor type (character, npc, etc.) to keep
|
||||
// things organized.
|
||||
this._prepareCharacterData(actorData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare Character type specific data
|
||||
*/
|
||||
_prepareCharacterData(actorData) {
|
||||
if (actorData.type !== 'character') return;
|
||||
|
||||
// Make modifications to data here. For example:
|
||||
const systemData = actorData.system;
|
||||
|
||||
// Loop through ability scores, and add their modifiers to our sheet output.
|
||||
for (let [key, ability] of Object.entries(systemData.abilities)) {
|
||||
// Calculate the modifier using d20 rules.
|
||||
ability.mod = Math.floor((ability.value - 10) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override getRollData() that's supplied to rolls.
|
||||
*/
|
||||
getRollData() {
|
||||
const data = super.getRollData();
|
||||
|
||||
// Prepare character roll data.
|
||||
this._getCharacterRollData(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare character roll data.
|
||||
*/
|
||||
_getCharacterRollData(data) {
|
||||
if (this.type !== 'character') return;
|
||||
|
||||
// Copy the ability scores to the top level, so that rolls can use
|
||||
// formulas like `@str.mod + 4`.
|
||||
if (data.abilities) {
|
||||
for (let [k, v] of Object.entries(data.abilities)) {
|
||||
data[k] = foundry.utils.deepClone(v);
|
||||
}
|
||||
}
|
||||
|
||||
// Add level for easier access, or fall back to 0.
|
||||
if (data.attributes.level) {
|
||||
data.lvl = data.attributes.level.value ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
import { TotemActor } from "./actor.mjs";
|
||||
/**
|
||||
* Extend the base Actor document by defining a custom roll data structure which is ideal for the Simple system.
|
||||
* @extends {TotemActor}
|
||||
*/
|
||||
export class TotemCreature extends TotemActor {
|
||||
|
||||
/** @override */
|
||||
prepareData() {
|
||||
// Prepare data for the actor. Calling the super version of this executes
|
||||
// the following, in order: data reset (to clear active effects),
|
||||
// prepareBaseData(), prepareEmbeddedDocuments() (including active effects),
|
||||
// prepareDerivedData().
|
||||
super.prepareData();
|
||||
}
|
||||
|
||||
/** @override */
|
||||
prepareBaseData() {
|
||||
// Data modifications in this step occur before processing embedded
|
||||
// documents or derived data.
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
* Augment the basic actor data with additional dynamic data. Typically,
|
||||
* you'll want to handle most of your calculated/derived data in this step.
|
||||
* Data calculated in this step should generally not exist in template.json
|
||||
* (such as ability modifiers rather than ability scores) and should be
|
||||
* available both inside and outside of character sheets (such as if an actor
|
||||
* is queried and has a roll executed directly from it).
|
||||
*/
|
||||
prepareDerivedData() {
|
||||
const actorData = this;
|
||||
const systemData = actorData.system;
|
||||
const flags = actorData.flags.totem || {};
|
||||
|
||||
// Make separate methods for each Actor type (character, npc, etc.) to keep
|
||||
// things organized.
|
||||
this._prepareNpcData(actorData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prepare NPC type specific data.
|
||||
*/
|
||||
_prepareNpcData(actorData) {
|
||||
if (actorData.type !== 'npc') return;
|
||||
|
||||
// Make modifications to data here. For example:
|
||||
const systemData = actorData.system;
|
||||
systemData.xp = (systemData.cr * systemData.cr) * 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override getRollData() that's supplied to rolls.
|
||||
*/
|
||||
getRollData() {
|
||||
const data = super.getRollData();
|
||||
|
||||
// Prepare character roll data.
|
||||
this._getNpcRollData(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare NPC roll data.
|
||||
*/
|
||||
_getNpcRollData(data) {
|
||||
if (this.type !== 'creature') return;
|
||||
|
||||
// Process additional NPC data here.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
import { TotemActor } from "./actor.mjs";
|
||||
/**
|
||||
* Extend the base Actor document by defining a custom roll data structure which is ideal for the Simple system.
|
||||
* @extends {TotemActor}
|
||||
*/
|
||||
export class TotemNpc extends TotemActor {
|
||||
|
||||
/** @override */
|
||||
prepareData() {
|
||||
// Prepare data for the actor. Calling the super version of this executes
|
||||
// the following, in order: data reset (to clear active effects),
|
||||
// prepareBaseData(), prepareEmbeddedDocuments() (including active effects),
|
||||
// prepareDerivedData().
|
||||
super.prepareData();
|
||||
}
|
||||
|
||||
/** @override */
|
||||
prepareBaseData() {
|
||||
// Data modifications in this step occur before processing embedded
|
||||
// documents or derived data.
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
* Augment the basic actor data with additional dynamic data. Typically,
|
||||
* you'll want to handle most of your calculated/derived data in this step.
|
||||
* Data calculated in this step should generally not exist in template.json
|
||||
* (such as ability modifiers rather than ability scores) and should be
|
||||
* available both inside and outside of character sheets (such as if an actor
|
||||
* is queried and has a roll executed directly from it).
|
||||
*/
|
||||
prepareDerivedData() {
|
||||
const actorData = this;
|
||||
const systemData = actorData.system;
|
||||
const flags = actorData.flags.totem || {};
|
||||
|
||||
// Make separate methods for each Actor type (character, npc, etc.) to keep
|
||||
// things organized.
|
||||
this._prepareNpcData(actorData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prepare NPC type specific data.
|
||||
*/
|
||||
_prepareNpcData(actorData) {
|
||||
if (actorData.type !== 'npc') return;
|
||||
|
||||
// Make modifications to data here. For example:
|
||||
const systemData = actorData.system;
|
||||
systemData.xp = (systemData.cr * systemData.cr) * 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override getRollData() that's supplied to rolls.
|
||||
*/
|
||||
getRollData() {
|
||||
const data = super.getRollData();
|
||||
|
||||
// Prepare character roll data.
|
||||
this._getNpcRollData(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare NPC roll data.
|
||||
*/
|
||||
_getNpcRollData(data) {
|
||||
if (this.type !== 'npc') return;
|
||||
|
||||
// Process additional NPC data here.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,7 +42,7 @@ export class TotemActorSheet extends ActorSheet {
|
||||
|
||||
// Prepare character data and items.
|
||||
if (actorData.type == 'character') {
|
||||
this._prepareItems(context);
|
||||
this._prepareCharacterItems(context);
|
||||
}
|
||||
|
||||
// Prepare NPC data and items.
|
||||
@@ -59,5 +59,145 @@ export class TotemActorSheet extends ActorSheet {
|
||||
return context;
|
||||
}
|
||||
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// Render the item sheet for viewing/editing prior to the editable check.
|
||||
html.find('.item-edit').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
const item = this.actor.items.get(li.data("itemId"));
|
||||
item.sheet.render(true);
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Everything below here is only needed if the sheet is editable
|
||||
if (!this.isEditable) return;
|
||||
|
||||
// Add Inventory Item
|
||||
html.find('.item-create').click(this._onItemCreate.bind(this));
|
||||
|
||||
// Delete Inventory Item
|
||||
html.find('.item-delete').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
const item = this.actor.items.get(li.data("itemId"));
|
||||
item.delete();
|
||||
li.slideUp(200, () => this.render(false));
|
||||
});
|
||||
|
||||
// Active Effect management
|
||||
html.find(".effect-control").click(ev => onManageActiveEffect(ev, this.actor));
|
||||
|
||||
|
||||
// Drag events for macros.
|
||||
if (this.actor.isOwner) {
|
||||
let handler = ev => this._onDragStart(ev);
|
||||
html.find('li.item').each((i, li) => {
|
||||
if (li.classList.contains("inventory-header")) return;
|
||||
li.setAttribute("draggable", true);
|
||||
li.addEventListener("dragstart", handler, false);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Organize and classify Items for Character sheets.
|
||||
*
|
||||
* @param {Object} actorData The actor to prepare.
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
_prepareCharacterItems(context) {
|
||||
// Initialize containers.
|
||||
const gear = [];
|
||||
const traits = [];
|
||||
const defenses = [];
|
||||
const specialties = [];
|
||||
const abilities = [];
|
||||
const weapons = [];
|
||||
const evolutions = [];
|
||||
const traumas = [];
|
||||
const backgrounds = [];
|
||||
const rumors = [];
|
||||
|
||||
// Iterate through items, allocating to containers
|
||||
for (let i of context.items) {
|
||||
i.img = i.img || DEFAULT_TOKEN;
|
||||
// Append to gear.
|
||||
if (i.type === 'item') {
|
||||
gear.push(i);
|
||||
}
|
||||
else if (i.type === 'trait') {
|
||||
traits.push(i);
|
||||
}
|
||||
else if (i.type === 'defense') {
|
||||
defenses.push(i);
|
||||
}
|
||||
else if (i.type === 'weapon') {
|
||||
weapons.push(i);
|
||||
}
|
||||
else if (i.type === 'specialty') {
|
||||
specialties.push(i);
|
||||
}
|
||||
else if (i.type === 'ability') {
|
||||
abilities.push(i);
|
||||
}
|
||||
else if (i.type === 'evolution') {
|
||||
evolutions.push(i);
|
||||
}
|
||||
else if (i.type === 'trauma') {
|
||||
traumas.push(i);
|
||||
}
|
||||
else if (i.type === 'background') {
|
||||
backgrounds.push(i);
|
||||
}
|
||||
else if (i.type === 'rumor') {
|
||||
rumors.push(i);
|
||||
}
|
||||
/* // Append to cephalie.
|
||||
else if (i.type === 'spell') {
|
||||
if (i.system.spellLevel != undefined) {
|
||||
cephalie[i.system.spellLevel].push(i);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
// Assign and return
|
||||
context.gear = gear;
|
||||
context.weapons = weapons;
|
||||
context.defenses = defenses;
|
||||
context.traits = traits;
|
||||
context.specialties = specialties;
|
||||
context.abilities = abilities;
|
||||
context.evolutions = evolutions;
|
||||
context.traumas = traumas;
|
||||
context.backgrounds = backgrounds;
|
||||
context.rumors = rumors;
|
||||
console.log("context", context);
|
||||
}
|
||||
|
||||
|
||||
async _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,
|
||||
system: data
|
||||
};
|
||||
// Remove the type from the dataset since it's in the itemData.type prop.
|
||||
delete itemData.system["type"];
|
||||
|
||||
// Finally, create the item!
|
||||
return await Item.create(itemData, {parent: this.actor});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export class TotemItemSheet extends ItemSheet {
|
||||
|
||||
// Use a safe clone of the item data for further operations.
|
||||
const itemData = context.item;
|
||||
|
||||
|
||||
// Retrieve the roll data for TinyMCE editors.
|
||||
context.rollData = {};
|
||||
let actor = this.object?.parent ?? null;
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
"systems/totem/templates/actor/parts/character-features.hbs",
|
||||
"systems/totem/templates/actor/parts/character-header.hbs",
|
||||
"systems/totem/templates/actor/parts/actor-items.html",
|
||||
"systems/totem/templates/actor/parts/actor-weapons.hbs",
|
||||
"systems/totem/templates/actor/parts/actor-defenses.hbs",
|
||||
"systems/totem/templates/actor/parts/actor-effects.html",
|
||||
|
||||
// additional templates
|
||||
|
||||
+1
-6
@@ -3,9 +3,6 @@ import { registerSettings } from "./system/settings.mjs";
|
||||
|
||||
// Import document classes.
|
||||
import { TotemActor } from "./documents/actor.mjs";
|
||||
import { TotemCharacter } from "./documents/character.mjs";
|
||||
import { TotemNpc } from "./documents/npc.mjs";
|
||||
import { TotemCreature } from "./documents/creature.mjs";
|
||||
|
||||
import { TotemCharacterSheet } from "./sheets/character-sheet.mjs";
|
||||
import { TotemNpcSheet } from "./sheets/npc-sheet.mjs";
|
||||
@@ -30,9 +27,7 @@ Hooks.once('init', async function() {
|
||||
// Add utility classes to the global game object so that they're more easily
|
||||
// accessible in global contexts.
|
||||
game.totem = {
|
||||
TotemCharacter,
|
||||
TotemNpc,
|
||||
TotemCreature,
|
||||
TotemActor,
|
||||
TotemItem,
|
||||
TotemRoll,
|
||||
TotemCombat
|
||||
|
||||
Reference in New Issue
Block a user