protections

This commit is contained in:
François-Xavier Guillois
2023-06-05 15:27:58 +02:00
parent af5ce9efcd
commit 7d7ec478e5
16 changed files with 207 additions and 285 deletions
-89
View File
@@ -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;
}
}
}
-76
View File
@@ -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.
}
}
-76
View File
@@ -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.
}
}
+141 -1
View File
@@ -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});
}
}
+1 -1
View File
@@ -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;
+2
View File
@@ -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
View File
@@ -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
+1 -1
View File
@@ -2,7 +2,7 @@
"id": "totem",
"title": "Totem",
"description": "The Totem system for FoundryVTT!",
"version": "0.0.9",
"version": "0.0.10",
"compatibility": {
"minimum": 10,
"verified": "10.287",
+1 -1
View File
@@ -17,7 +17,7 @@
<i class="fas fa-address-card"></i>
</a>
<a class="item" data-tab="instincts" title="{{localize "TOTEM.tab_instincts_label"}}">
<a class="item" data-tab="totem" title="{{localize "TOTEM.tab_instincts_label"}}">
<i class="fas fa-star"></i>
</a>
<a class="item" data-tab="equipment" title="{{localize "TOTEM.tab_equipment_label"}}">
+29
View File
@@ -0,0 +1,29 @@
<ol class="items-list">
<li class="item flexrow items-header">
<div class="item-name" style="flex:4;">{{ localize 'IDENTITY.name'}}</div>
<div class="item-clew">{{ localize 'TOTEM.clew'}}</div>
<div class="item-mobility">{{ localize 'TOTEM.mobility'}}</div>
<div class="item-rarity">{{ localize 'TOTEM.rarity'}}</div>
<div class="item-reliability">{{ localize 'TOTEM.reliability'}}</div>
<div class="item-controls">
<a class="item-control item-create" title="Create item" data-type="defense"><i class="fas fa-plus"></i> Add item</a>
</div>
</li>
{{#each defenses as |item id|}}
<li class="item flexrow" data-item-id="{{item._id}}">
<div class="item-name" style="flex:4;">
<div class="item-image">
<a class="item-control item-edit" data-roll-type="item"><img src="{{item.img}}" title="{{item.name}}" width="24" height="24"/></a>
</div>
<a class="item-control item-edit" title="Edit Item">{{item.name}}</a>
</div>
<p><a class="item-control item-edit" title="Edit Item">{{item.system.level}}</a></p>
<p><a class="item-control item-edit" title="Edit Item">{{item.system.mobility}}</a></p>
<p><a class="item-control item-edit" title="Edit Item">{{item.system.rarity}}</a></p>
<p><a class="item-control item-edit" title="Edit Item">{{item.system.reliability}}</a></p>
<div class="item-controls">
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
</div>
</li>
{{/each}}
</ol>
-23
View File
@@ -2,29 +2,6 @@
<img class="profile-img" src="{{actor.img}}" data-edit="img" title="{{actor.name}}" height="100" width="100"/>
</div>
<ul class="padding-with-frieze unstyled paper">
<li>
<div class="flexrow flex-group-center items-center">
<label for="system.identity.height" class="resource-label flexlarge align-left">{{ localize "IDENTITY.height"}}</label>
<input type="number" name="system.identity.height" value="{{ system.identity.height }}" data-dtype="Number"/>
<span>cm</span>
</div>
</li>
<li>
<div class="flexrow flex-group-center items-center">
<label for="system.identity.weight" class="resource-label flexlarge align-left">{{ localize "IDENTITY.weight"}}</label>
<input type="number" name="system.identity.weight" value="{{ system.identity.weight }}" data-dtype="Number"/>
<span>kgs</span>
</div>
</li>
<li>
<div class="flexcol flex-group-center items-center w-full">
<label for="system.identity.gender" class="resource-label flexlarge align-left">{{ localize "IDENTITY.gender"}}</label>
<select name="system.identity.gender" class="w-full">
{{selectOptions config.sexes selected=system.identity.gender localize=true}}
</select>
</div>
</li>
<li>
<div class="flexcol flex-group-center items-center w-full">
<label for="system.identity.origin" class="resource-label flexlarge align-left">{{ localize "IDENTITY.origin"}}</label>
+8 -8
View File
@@ -1,8 +1,6 @@
{{> "systems/totem/templates/actor/parts/actor-features.html"}}
<ol class="items-list">
<li class="item flexrow items-header">
<div class="item-name">Name</div>
<div class="item-formula">Roll Formula</div>
<div class="item-name">Nom</div>
<div class="item-controls">
<a class="item-control item-create" title="Create item" data-type="item"><i class="fas fa-plus"></i> Add item</a>
</div>
@@ -11,15 +9,17 @@
<li class="item flexrow" data-item-id="{{item._id}}">
<div class="item-name">
<div class="item-image">
<a class="rollable" data-roll-type="item"><img src="{{item.img}}" title="{{item.name}}" width="24" height="24"/></a>
<a class="item-control item-edit" data-roll-type="item"><img src="{{item.img}}" title="{{item.name}}" width="24" height="24"/></a>
</div>
<h4>{{item.name}}</h4>
</div>
<div class="item-formula item-prop">{{item.system.formula}}</div>
<p><a class="item-control item-edit" title="Edit Item">{{item.name}}</a></p>
<div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
</div>
</li>
{{/each}}
</ol>
</ol>
<h4>{{localize 'ITEMS.weapons'}}</h4>
{{> "systems/totem/templates/actor/parts/actor-weapons.hbs"}}
<h4>{{localize 'ITEMS.defenses'}}</h4>
{{> "systems/totem/templates/actor/parts/actor-defenses.hbs"}}
+21
View File
@@ -0,0 +1,21 @@
<ol class="items-list">
<li class="item flexrow items-header">
<div class="item-name">Name</div>
<div class="item-controls">
<a class="item-control item-create" title="Create item" data-type="weapon"><i class="fas fa-plus"></i> Add item</a>
</div>
</li>
{{#each weapons as |item id|}}
<li class="item flexrow" data-item-id="{{item._id}}">
<div class="item-name">
<div class="item-image">
<a class="item-control item-edit" data-roll-type="item"><img src="{{item.img}}" title="{{item.name}}" width="24" height="24"/></a>
</div>
</div>
<p><a class="item-control item-edit" title="Edit Item">{{item.name}}</a></p>
<div class="item-controls">
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
</div>
</li>
{{/each}}
</ol>
+2 -1
View File
@@ -24,7 +24,8 @@
{{#if (eq skill.category sckey) }}
<div class="ability flexrow flex-group-center">
<label style="flex:80%;" for="system.skills.{{skey}}.value" class="resource-label rollable flexlarge align-left" data-roll="+@skills.{{skey}}d10" data-label="{{ smarttl "SKILLS" skey }}">{{ smarttl "SKILLS" skey }} ({{skill.rarity}})</label>
<label style="flex:80%;" for="system.skills.{{skey}}.value" class="resource-label rollable flexlarge align-left" data-roll="+@skills.{{skey}}d10" data-label="{{ smarttl "SKILLS" skey }}">{{ smarttl "SKILLS" skey }}
{{#if (eq skill.rarity 1)}}<sup>*</sup>{{/if}}{{#if (eq skill.rarity 2)}}<sup>**</sup>{{/if}}</label>
<input type="text" name="system.skills.{{skey}}.value" value="{{skill.value}}" data-dtype="Number"/>
</div>
{{/if}}
@@ -1,6 +1,5 @@
<!-- HEADER -->
<header class="char-header flexrow flex-group-center items-center">
{{ log system }}
<section class="char-details" style="flex:50%;">
<h1 class="char-name flexrow flex-group-left">
<label>{{ localize 'IDENTITY.name' }}</label>
-1
View File
@@ -6,7 +6,6 @@
</div>
</header>
<section class="sheet-body">
{{ log item }}
<div class="tab flexrow" data-group="primary" data-tab="description">
<aside style="flex:1">
<div class="resource">