Push initial structure

This commit is contained in:
2020-05-22 00:48:43 +02:00
parent b385993422
commit 29054cd395
7 changed files with 243 additions and 205 deletions

View File

@ -2,13 +2,13 @@
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
export class SimpleActorSheet extends ActorSheet {
export class RdDActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["worldbuilding", "sheet", "actor"],
template: "systems/worldbuilding/templates/actor-sheet.html",
classes: ["rdd", "sheet", "actor"],
template: "systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html",
width: 600,
height: 600,
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}],
@ -18,18 +18,6 @@ export class SimpleActorSheet extends ActorSheet {
/* -------------------------------------------- */
/** @override */
getData() {
const data = super.getData();
data.dtypes = ["String", "Number", "Boolean"];
for ( let attr of Object.values(data.data.attributes) ) {
attr.isCheckbox = attr.dtype === "Boolean";
}
return data;
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
@ -51,8 +39,6 @@ export class SimpleActorSheet extends ActorSheet {
li.slideUp(200, () => this.render(false));
});
// Add or Remove Attribute
html.find(".attributes").on("click", ".attribute-control", this._onClickAttributeControl.bind(this));
}
/* -------------------------------------------- */
@ -66,64 +52,12 @@ export class SimpleActorSheet extends ActorSheet {
return position;
}
/* -------------------------------------------- */
/**
* Listen for click events on an attribute control to modify the composition of attributes in the sheet
* @param {MouseEvent} event The originating left click event
* @private
*/
async _onClickAttributeControl(event) {
event.preventDefault();
const a = event.currentTarget;
const action = a.dataset.action;
const attrs = this.object.data.data.attributes;
const form = this.form;
// Add new attribute
if ( action === "create" ) {
const nk = Object.keys(attrs).length + 1;
let newKey = document.createElement("div");
newKey.innerHTML = `<input type="text" name="data.attributes.attr${nk}.key" value="attr${nk}"/>`;
newKey = newKey.children[0];
form.appendChild(newKey);
await this._onSubmit(event);
}
// Remove existing attribute
else if ( action === "delete" ) {
const li = a.closest(".attribute");
li.parentElement.removeChild(li);
await this._onSubmit(event);
}
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
// Handle the free-form attributes list
const formAttrs = expandObject(formData).data.attributes || {};
const attributes = Object.values(formAttrs).reduce((obj, v) => {
let k = v["key"].trim();
if ( /[\s\.]/.test(k) ) return ui.notifications.error("Attribute keys may not contain spaces or periods");
delete v["key"];
obj[k] = v;
return obj;
}, {});
// Remove attributes which are no longer used
for ( let k of Object.keys(this.object.data.data.attributes) ) {
if ( !attributes.hasOwnProperty(k) ) attributes[`-=${k}`] = null;
}
// Re-combine formData
formData = Object.entries(formData).filter(e => !e[0].startsWith("data.attributes")).reduce((obj, e) => {
obj[e[0]] = e[1];
return obj;
}, {_id: this.object._id, "data.attributes": attributes});
// Update the Actor
return this.object.update(formData);
}

View File

@ -2,12 +2,43 @@
* 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 {
export class RdDActor extends Actor {
prepareData() {
super.prepareData();
const actorData = this.data;
const data = actorData.data;
const flags = actorData.flags;
const comp = { "base": [],
"mêlée": [],
"tir": [],
"particulières": [],
"spécialisées": [],
"connaissances": [],
"draconic": []
}
// 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) {
for (let i of actorData.items)
{
if (i.type === "compétence") {
comp[i.catégorie].push( i );
}
}
}
/** @override */
getRollData() {
const data = super.getRollData();
const shorthand = game.settings.get("worldbuilding", "macroShorthand");
const shorthand = game.settings.get("foundryvtt-reve-de-dragon", "macroShorthand");
// Re-map all attributes onto the base roll data
if ( !!shorthand ) {

View File

@ -2,7 +2,7 @@
* Extend the basic ItemSheet with some very simple modifications
* @extends {ItemSheet}
*/
export class SimpleItemSheet extends ItemSheet {
export class RdDItemSheet extends ItemSheet {
/** @override */
static get defaultOptions() {

View File

@ -5,16 +5,16 @@
*/
// Import Modules
import { SimpleActor } from "./actor.js";
import { SimpleItemSheet } from "./item-sheet.js";
import { SimpleActorSheet } from "./actor-sheet.js";
import { RdDActor } from "./actor.js";
import { RdDItemSheet } from "./item-sheet.js";
import { RdDActorSheet } from "./actor-sheet.js";
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks.once("init", async function() {
console.log(`Initializing Simple Worldbuilding System`);
console.log(`Initializing Reve de Dragon System`);
/**
* Set an initiative formula for the system
@ -26,16 +26,16 @@ Hooks.once("init", async function() {
};
// Define custom Entity classes
CONFIG.Actor.entityClass = SimpleActor;
CONFIG.Actor.entityClass = RdDActor;
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
Actors.registerSheet("dnd5e", SimpleActorSheet, { makeDefault: true });
Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorSheet, { makeDefault: true });
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("dnd5e", SimpleItemSheet, {makeDefault: true});
Items.registerSheet("foundryvtt-reve-de-dragon", RdDItemSheet, {makeDefault: true});
// Register system settings
game.settings.register("worldbuilding", "macroShorthand", {
game.settings.register("foundryvtt-reve-de-dragon", "macroShorthand", {
name: "Shortened Macro Syntax",
hint: "Enable a shortened macro syntax which allows referencing attributes directly, for example @str instead of @attributes.str.value. Disable this setting if you need the ability to reference the full attribute model, for example @attributes.str.label.",
scope: "world",