V10 compatibility with 0.7.0-alpha1 release

This commit is contained in:
Andrew 2022-08-23 21:23:59 -04:00
parent 107aec3244
commit e23893b6ca
12 changed files with 125 additions and 126 deletions

View file

@ -23,12 +23,16 @@ export class SimpleActorSheet extends ActorSheet {
/* -------------------------------------------- */ /* -------------------------------------------- */
/** @inheritdoc */ /** @inheritdoc */
getData() { async getData(options) {
const context = super.getData(); const context = await super.getData(options);
EntitySheetHelper.getAttributeData(context.data); EntitySheetHelper.getAttributeData(context.data);
context.shorthand = !!game.settings.get("worldbuilding", "macroShorthand"); context.shorthand = !!game.settings.get("worldbuilding", "macroShorthand");
context.systemData = context.data.data; context.systemData = context.data.system;
context.dtypes = ATTRIBUTE_TYPES; context.dtypes = ATTRIBUTE_TYPES;
context.biographyHTML = await TextEditor.enrichHTML(context.systemData.biography, {
secrets: this.document.isOwner,
async: true
});
return context; return context;
} }

View file

@ -9,9 +9,9 @@ export class SimpleActor extends Actor {
/** @inheritdoc */ /** @inheritdoc */
prepareDerivedData() { prepareDerivedData() {
super.prepareDerivedData(); super.prepareDerivedData();
this.data.data.groups = this.data.data.groups || {}; this.system.groups = this.system.groups || {};
this.data.data.attributes = this.data.data.attributes || {}; this.system.attributes = this.system.attributes || {};
EntitySheetHelper.clampResourceValues(this.data.data.attributes); EntitySheetHelper.clampResourceValues(this.system.attributes);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -39,7 +39,7 @@ export class SimpleActor extends Actor {
getRollData() { getRollData() {
// Copy the actor's system data // Copy the actor's system data
const data = this.toObject(false).data; const data = this.toObject(false);
const shorthand = game.settings.get("worldbuilding", "macroShorthand"); const shorthand = game.settings.get("worldbuilding", "macroShorthand");
const formulaAttributes = []; const formulaAttributes = [];
const itemAttributes = []; const itemAttributes = [];
@ -47,7 +47,7 @@ export class SimpleActor extends Actor {
// Handle formula attributes when the short syntax is disabled. // Handle formula attributes when the short syntax is disabled.
this._applyShorthand(data, formulaAttributes, shorthand); this._applyShorthand(data, formulaAttributes, shorthand);
// Map all items data using their slugified names // Map all item data using their slugified names
this._applyItems(data, itemAttributes, shorthand); this._applyItems(data, itemAttributes, shorthand);
// Evaluate formula replacements on items. // Evaluate formula replacements on items.
@ -111,10 +111,10 @@ export class SimpleActor extends Actor {
// Map all items data using their slugified names // Map all items data using their slugified names
data.items = this.items.reduce((obj, item) => { data.items = this.items.reduce((obj, item) => {
const key = item.name.slugify({strict: true}); const key = item.name.slugify({strict: true});
const itemData = item.toObject(false).data; const itemData = item.toObject(false);
// Add items to shorthand and note which ones are formula attributes. // Add items to shorthand and note which ones are formula attributes.
for ( let [k, v] of Object.entries(itemData.attributes) ) { for ( let [k, v] of Object.entries(itemData.system.attributes) ) {
// When building the attribute list, prepend the item name for later use. // When building the attribute list, prepend the item name for later use.
if ( v.dtype === "Formula" ) itemAttributes.push(`${key}..${k}`); if ( v.dtype === "Formula" ) itemAttributes.push(`${key}..${k}`);
// Add shortened version of the attributes. // Add shortened version of the attributes.
@ -252,11 +252,11 @@ export class SimpleActor extends Actor {
/** @inheritdoc */ /** @inheritdoc */
async modifyTokenAttribute(attribute, value, isDelta = false, isBar = true) { async modifyTokenAttribute(attribute, value, isDelta = false, isBar = true) {
const current = foundry.utils.getProperty(this.data.data, attribute); const current = foundry.utils.getProperty(this.system, attribute);
if ( !isBar || !isDelta || (current?.dtype !== "Resource") ) { if ( !isBar || !isDelta || (current?.dtype !== "Resource") ) {
return super.modifyTokenAttribute(attribute, value, isDelta, isBar); return super.modifyTokenAttribute(attribute, value, isDelta, isBar);
} }
const updates = {[`data.${attribute}.value`]: Math.clamped(current.value + value, current.min, current.max)}; const updates = {[`system.${attribute}.value`]: Math.clamped(current.value + value, current.min, current.max)};
const allowed = Hooks.call("modifyTokenAttribute", {attribute, value, isDelta, isBar}, updates); const allowed = Hooks.call("modifyTokenAttribute", {attribute, value, isDelta, isBar}, updates);
return allowed !== false ? this.update(updates) : this; return allowed !== false ? this.update(updates) : this;
} }

View file

@ -1,11 +1,10 @@
import { ATTRIBUTE_TYPES } from "./constants.js";
export class EntitySheetHelper { export class EntitySheetHelper {
static getAttributeData(data) { static getAttributeData(data) {
// Determine attribute type. // Determine attribute type.
for ( let attr of Object.values(data.data.attributes) ) { for ( let attr of Object.values(data.system.attributes) ) {
if ( attr.dtype ) { if ( attr.dtype ) {
attr.isCheckbox = attr.dtype === "Boolean"; attr.isCheckbox = attr.dtype === "Boolean";
attr.isResource = attr.dtype === "Resource"; attr.isResource = attr.dtype === "Resource";
@ -14,10 +13,10 @@ export class EntitySheetHelper {
} }
// Initialize ungrouped attributes for later. // Initialize ungrouped attributes for later.
data.data.ungroupedAttributes = {}; data.system.ungroupedAttributes = {};
// Build an array of sorted group keys. // Build an array of sorted group keys.
const groups = data.data.groups || {}; const groups = data.system.groups || {};
let groupKeys = Object.keys(groups).sort((a, b) => { let groupKeys = Object.keys(groups).sort((a, b) => {
let aSort = groups[a].label ?? a; let aSort = groups[a].label ?? a;
let bSort = groups[b].label ?? b; let bSort = groups[b].label ?? b;
@ -26,10 +25,10 @@ export class EntitySheetHelper {
// Iterate over the sorted groups to add their attributes. // Iterate over the sorted groups to add their attributes.
for ( let key of groupKeys ) { for ( let key of groupKeys ) {
let group = data.data.attributes[key] || {}; let group = data.system.attributes[key] || {};
// Initialize the attributes container for this group. // Initialize the attributes container for this group.
if ( !data.data.groups[key]['attributes'] ) data.data.groups[key]['attributes'] = {}; if ( !data.system.groups[key]['attributes'] ) data.system.groups[key]['attributes'] = {};
// Sort the attributes within the group, and then iterate over them. // Sort the attributes within the group, and then iterate over them.
Object.keys(group).sort((a, b) => a.localeCompare(b)).forEach(attr => { Object.keys(group).sort((a, b) => a.localeCompare(b)).forEach(attr => {
@ -39,20 +38,20 @@ export class EntitySheetHelper {
group[attr]['isCheckbox'] = group[attr]['dtype'] === 'Boolean'; group[attr]['isCheckbox'] = group[attr]['dtype'] === 'Boolean';
group[attr]['isResource'] = group[attr]['dtype'] === 'Resource'; group[attr]['isResource'] = group[attr]['dtype'] === 'Resource';
group[attr]['isFormula'] = group[attr]['dtype'] === 'Formula'; group[attr]['isFormula'] = group[attr]['dtype'] === 'Formula';
data.data.groups[key]['attributes'][attr] = group[attr]; data.system.groups[key]['attributes'][attr] = group[attr];
}); });
} }
// Sort the remaining attributes attributes. // Sort the remaining attributes.
Object.keys(data.data.attributes).filter(a => !groupKeys.includes(a)).sort((a, b) => a.localeCompare(b)).forEach(key => { const keys = Object.keys(data.system.attributes).filter(a => !groupKeys.includes(a));
data.data.ungroupedAttributes[key] = data.data.attributes[key]; keys.sort((a, b) => a.localeCompare(b));
}); for ( const key of keys ) data.system.ungroupedAttributes[key] = data.system.attributes[key];
// Modify attributes on items. // Modify attributes on items.
if ( data.items ) { if ( data.items ) {
data.items.forEach(item => { data.items.forEach(item => {
// Iterate over attributes. // Iterate over attributes.
for ( let [k, v] of Object.entries(item.data.attributes) ) { for ( let [k, v] of Object.entries(item.system.attributes) ) {
// Grouped attributes. // Grouped attributes.
if ( !v.dtype ) { if ( !v.dtype ) {
for ( let [gk, gv] of Object.entries(v) ) { for ( let [gk, gv] of Object.entries(v) ) {
@ -212,9 +211,9 @@ export class EntitySheetHelper {
static getAttributeHtml(items, index, group = false) { static getAttributeHtml(items, index, group = false) {
// Initialize the HTML. // Initialize the HTML.
let result = '<div style="display: none;">'; let result = '<div style="display: none;">';
// Iterate over the supplied keys and build their inputs (including whether or not they need a group key). // Iterate over the supplied keys and build their inputs (including whether they need a group key).
for (let [key, item] of Object.entries(items)) { for (let [key, item] of Object.entries(items)) {
result = result + `<input type="${item.type}" name="data.attributes${group ? '.' + group : '' }.attr${index}.${key}" value="${item.value}"/>`; result = result + `<input type="${item.type}" name="system.attributes${group ? '.' + group : '' }.attr${index}.${key}" value="${item.value}"/>`;
} }
// Close the HTML and return. // Close the HTML and return.
return result + '</div>'; return result + '</div>';
@ -229,8 +228,8 @@ export class EntitySheetHelper {
* @returns {boolean} * @returns {boolean}
*/ */
static validateGroup(groupName, document) { static validateGroup(groupName, document) {
let groups = Object.keys(document.data.data.groups || {}); let groups = Object.keys(document.system.groups || {});
let attributes = Object.keys(document.data.data.attributes).filter(a => !groups.includes(a)); let attributes = Object.keys(document.system.attributes).filter(a => !groups.includes(a));
// Check for duplicate group keys. // Check for duplicate group keys.
if ( groups.includes(groupName) ) { if ( groups.includes(groupName) ) {
@ -270,8 +269,8 @@ export class EntitySheetHelper {
const a = event.currentTarget; const a = event.currentTarget;
const group = a.dataset.group; const group = a.dataset.group;
let dtype = a.dataset.dtype; let dtype = a.dataset.dtype;
const attrs = app.object.data.data.attributes; const attrs = app.object.system.attributes;
const groups = app.object.data.data.groups; const groups = app.object.system.groups;
const form = app.form; const form = app.form;
// Determine the new attribute key for ungrouped attributes. // Determine the new attribute key for ungrouped attributes.
@ -365,7 +364,7 @@ export class EntitySheetHelper {
// Verify the new group key is valid, and use it to create the group. // Verify the new group key is valid, and use it to create the group.
if ( newValue.length > 0 && EntitySheetHelper.validateGroup(newValue, app.object) ) { if ( newValue.length > 0 && EntitySheetHelper.validateGroup(newValue, app.object) ) {
let newKey = document.createElement("div"); let newKey = document.createElement("div");
newKey.innerHTML = `<input type="text" name="data.groups.${newValue}.key" value="${newValue}"/>`; newKey.innerHTML = `<input type="text" name="system.groups.${newValue}.key" value="${newValue}"/>`;
// Append the form element and submit the form. // Append the form element and submit the form.
newKey = newKey.children[0]; newKey = newKey.children[0];
form.appendChild(newKey); form.appendChild(newKey);
@ -419,7 +418,7 @@ export class EntitySheetHelper {
let groupKeys = []; let groupKeys = [];
// Handle the free-form attributes list // Handle the free-form attributes list
const formAttrs = foundry.utils.expandObject(formData)?.data?.attributes || {}; const formAttrs = foundry.utils.expandObject(formData)?.system?.attributes || {};
const attributes = Object.values(formAttrs).reduce((obj, v) => { const attributes = Object.values(formAttrs).reduce((obj, v) => {
let attrs = []; let attrs = [];
let group = null; let group = null;
@ -454,24 +453,24 @@ export class EntitySheetHelper {
}, {}); }, {});
// Remove attributes which are no longer used // Remove attributes which are no longer used
for ( let k of Object.keys(document.data.data.attributes) ) { for ( let k of Object.keys(document.system.attributes) ) {
if ( !attributes.hasOwnProperty(k) ) attributes[`-=${k}`] = null; if ( !attributes.hasOwnProperty(k) ) attributes[`-=${k}`] = null;
} }
// Remove grouped attributes which are no longer used. // Remove grouped attributes which are no longer used.
for ( let group of groupKeys) { for ( let group of groupKeys) {
if ( document.data.data.attributes[group] ) { if ( document.system.attributes[group] ) {
for ( let k of Object.keys(document.data.data.attributes[group]) ) { for ( let k of Object.keys(document.system.attributes[group]) ) {
if ( !attributes[group].hasOwnProperty(k) ) attributes[group][`-=${k}`] = null; if ( !attributes[group].hasOwnProperty(k) ) attributes[group][`-=${k}`] = null;
} }
} }
} }
// Re-combine formData // Re-combine formData
formData = Object.entries(formData).filter(e => !e[0].startsWith("data.attributes")).reduce((obj, e) => { formData = Object.entries(formData).filter(e => !e[0].startsWith("system.attributes")).reduce((obj, e) => {
obj[e[0]] = e[1]; obj[e[0]] = e[1];
return obj; return obj;
}, {_id: document.id, "data.attributes": attributes}); }, {_id: document.id, "system.attributes": attributes});
return formData; return formData;
} }
@ -485,40 +484,26 @@ export class EntitySheetHelper {
* @returns {object} The updated formData object. * @returns {object} The updated formData object.
*/ */
static updateGroups(formData, document) { static updateGroups(formData, document) {
// Handle the free-form groups list const formGroups = foundry.utils.expandObject(formData).system.groups || {};
const formGroups = expandObject(formData).data.groups || {}; const documentGroups = Object.keys(document.system.groups || {});
const documentGroups = Object.keys(document.data.data.groups || {});
const groups = Object.values(formGroups).reduce((obj, v) => { // Identify valid groups submitted on the form
// If there are duplicate groups, collapse them. const groups = Object.entries(formGroups).reduce((obj, [k, v]) => {
if ( Array.isArray(v["key"]) ) { const validGroup = documentGroups.includes(k) || this.validateGroup(k, document);
v["key"] = v["key"][0]; if ( validGroup ) obj[k] = v;
}
// Trim and clean up.
let k = v["key"].trim();
// Validate groups.
let isValidGroup = true;
// Skip validation for existing/duplicate groups since they're collapsed above.
if ( !documentGroups.includes(k) ) {
isValidGroup = this.validateGroup(k, document);
}
// Delete the key and add the group to the reducer if valid.
delete v["key"];
if (isValidGroup) obj[k] = v;
return obj; return obj;
}, {}); }, {});
// Remove groups which are no longer used // Remove groups which are no longer used
if (groups) { for ( let k of Object.keys(document.system.groups)) {
for ( let k of Object.keys(document.data.data.groups)) { if ( !groups.hasOwnProperty(k) ) groups[`-=${k}`] = null;
if ( !groups.hasOwnProperty(k) ) groups[`-=${k}`] = null;
}
} }
// Re-combine formData // Re-combine formData
formData = Object.entries(formData).filter(e => !e[0].startsWith("data.groups")).reduce((obj, e) => { formData = Object.entries(formData).filter(e => !e[0].startsWith("system.groups")).reduce((obj, e) => {
obj[e[0]] = e[1]; obj[e[0]] = e[1];
return obj; return obj;
}, {_id: document.id, "data.groups": groups}); }, {_id: document.id, "system.groups": groups});
return formData; return formData;
} }
@ -531,7 +516,7 @@ export class EntitySheetHelper {
// Collect data // Collect data
const documentName = this.metadata.name; const documentName = this.metadata.name;
const folders = game.folders.filter(f => (f.data.type === documentName) && f.displayed); const folders = game.folders.filter(f => (f.type === documentName) && f.displayed);
const label = game.i18n.localize(this.metadata.label); const label = game.i18n.localize(this.metadata.label);
const title = game.i18n.format("DOCUMENT.Create", {type: label}); const title = game.i18n.format("DOCUMENT.Create", {type: label});
@ -547,8 +532,7 @@ export class EntitySheetHelper {
} }
// Render the document creation form // Render the document creation form
const useEntity = game.worldbuilding.useEntity; const template = "templates/sidebar/document-create.html";
const template = `templates/sidebar/${useEntity ? "entity" : "document" }-create.html`;
const html = await renderTemplate(template, { const html = await renderTemplate(template, {
name: data.name || game.i18n.format("DOCUMENT.New", {type: label}), name: data.name || game.i18n.format("DOCUMENT.New", {type: label}),
folder: data.folder, folder: data.folder,
@ -575,7 +559,7 @@ export class EntitySheetHelper {
const template = collection.get(form.type.value); const template = collection.get(form.type.value);
if ( template ) { if ( template ) {
createData = foundry.utils.mergeObject(template.toObject(), createData); createData = foundry.utils.mergeObject(template.toObject(), createData);
createData.type = template.data.type; createData.type = template.type;
delete createData.flags.worldbuilding.isTemplate; delete createData.flags.worldbuilding.isTemplate;
} }

View file

@ -22,18 +22,22 @@ export class SimpleItemSheet extends ItemSheet {
/* -------------------------------------------- */ /* -------------------------------------------- */
/** @inheritdoc */ /** @inheritdoc */
getData() { async getData(options) {
const context = super.getData(); const context = await super.getData(options);
EntitySheetHelper.getAttributeData(context.data); EntitySheetHelper.getAttributeData(context.data);
context.systemData = context.data.data; context.systemData = context.data.system;
context.dtypes = ATTRIBUTE_TYPES; context.dtypes = ATTRIBUTE_TYPES;
context.descriptionHTML = await TextEditor.enrichHTML(context.systemData.description, {
secrets: this.document.isOwner,
async: true
});
return context; return context;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
/** @inheritdoc */ /** @inheritdoc */
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);
// Everything below here is only needed if the sheet is editable // Everything below here is only needed if the sheet is editable

View file

@ -9,9 +9,9 @@ export class SimpleItem extends Item {
/** @inheritdoc */ /** @inheritdoc */
prepareDerivedData() { prepareDerivedData() {
super.prepareDerivedData(); super.prepareDerivedData();
this.data.data.groups = this.data.data.groups || {}; this.system.groups = this.system.groups || {};
this.data.data.attributes = this.data.data.attributes || {}; this.system.attributes = this.system.attributes || {};
EntitySheetHelper.clampResourceValues(this.data.data.attributes); EntitySheetHelper.clampResourceValues(this.system.attributes);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View file

@ -33,8 +33,7 @@ Hooks.once("init", async function() {
game.worldbuilding = { game.worldbuilding = {
SimpleActor, SimpleActor,
createWorldbuildingMacro, createWorldbuildingMacro
useEntity: foundry.utils.isNewerVersion("9", game.version ?? game.data.version)
}; };
// Define custom Document classes // Define custom Document classes
@ -108,17 +107,17 @@ Hooks.on("hotbarDrop", (bar, data, slot) => createWorldbuildingMacro(data, slot)
* Adds the actor template context menu. * Adds the actor template context menu.
*/ */
Hooks.on("getActorDirectoryEntryContext", (html, options) => { Hooks.on("getActorDirectoryEntryContext", (html, options) => {
const idAttr = game.worldbuilding.useEntity ? "entityId" : "documentId";
// Define an actor as a template. // Define an actor as a template.
options.push({ options.push({
name: game.i18n.localize("SIMPLE.DefineTemplate"), name: game.i18n.localize("SIMPLE.DefineTemplate"),
icon: '<i class="fas fa-stamp"></i>', icon: '<i class="fas fa-stamp"></i>',
condition: li => { condition: li => {
const actor = game.actors.get(li.data(idAttr)); const actor = game.actors.get(li.data("documentId"));
return !actor.isTemplate; return !actor.isTemplate;
}, },
callback: li => { callback: li => {
const actor = game.actors.get(li.data(idAttr)); const actor = game.actors.get(li.data("documentId"));
actor.setFlag("worldbuilding", "isTemplate", true); actor.setFlag("worldbuilding", "isTemplate", true);
} }
}); });
@ -128,11 +127,11 @@ Hooks.on("getActorDirectoryEntryContext", (html, options) => {
name: game.i18n.localize("SIMPLE.UnsetTemplate"), name: game.i18n.localize("SIMPLE.UnsetTemplate"),
icon: '<i class="fas fa-times"></i>', icon: '<i class="fas fa-times"></i>',
condition: li => { condition: li => {
const actor = game.actors.get(li.data(idAttr)); const actor = game.actors.get(li.data("documentId"));
return actor.isTemplate; return actor.isTemplate;
}, },
callback: li => { callback: li => {
const actor = game.actors.get(li.data(idAttr)); const actor = game.actors.get(li.data("documentId"));
actor.setFlag("worldbuilding", "isTemplate", false); actor.setFlag("worldbuilding", "isTemplate", false);
} }
}); });
@ -142,17 +141,17 @@ Hooks.on("getActorDirectoryEntryContext", (html, options) => {
* Adds the item template context menu. * Adds the item template context menu.
*/ */
Hooks.on("getItemDirectoryEntryContext", (html, options) => { Hooks.on("getItemDirectoryEntryContext", (html, options) => {
const idAttr = game.worldbuilding.useEntity ? "entityId" : "documentId";
// Define an item as a template. // Define an item as a template.
options.push({ options.push({
name: game.i18n.localize("SIMPLE.DefineTemplate"), name: game.i18n.localize("SIMPLE.DefineTemplate"),
icon: '<i class="fas fa-stamp"></i>', icon: '<i class="fas fa-stamp"></i>',
condition: li => { condition: li => {
const item = game.items.get(li.data(idAttr)); const item = game.items.get(li.data("documentId"));
return !item.isTemplate; return !item.isTemplate;
}, },
callback: li => { callback: li => {
const item = game.items.get(li.data(idAttr)); const item = game.items.get(li.data("documentId"));
item.setFlag("worldbuilding", "isTemplate", true); item.setFlag("worldbuilding", "isTemplate", true);
} }
}); });
@ -162,11 +161,11 @@ Hooks.on("getItemDirectoryEntryContext", (html, options) => {
name: game.i18n.localize("SIMPLE.UnsetTemplate"), name: game.i18n.localize("SIMPLE.UnsetTemplate"),
icon: '<i class="fas fa-times"></i>', icon: '<i class="fas fa-times"></i>',
condition: li => { condition: li => {
const item = game.items.get(li.data(idAttr)); const item = game.items.get(li.data("documentId"));
return item.isTemplate; return item.isTemplate;
}, },
callback: li => { callback: li => {
const item = game.items.get(li.data(idAttr)); const item = game.items.get(li.data("documentId"));
item.setFlag("worldbuilding", "isTemplate", false); item.setFlag("worldbuilding", "isTemplate", false);
} }
}); });

View file

@ -3,12 +3,13 @@
* @extends {TokenDocument} * @extends {TokenDocument}
*/ */
export class SimpleTokenDocument extends TokenDocument { export class SimpleTokenDocument extends TokenDocument {
/** @inheritdoc */ /** @inheritdoc */
getBarAttribute(barName, {alternative}={}) { getBarAttribute(barName, {alternative}={}) {
const data = super.getBarAttribute(barName, {alternative}); const data = super.getBarAttribute(barName, {alternative});
const attr = alternative || this.data[barName]?.attribute; const attr = alternative || this[barName]?.attribute;
if ( !data || !attr || !this.actor ) return data; if ( !data || !attr || !this.actor ) return data;
const current = foundry.utils.getProperty(this.actor.data.data, attr); const current = foundry.utils.getProperty(this.actor.system, attr);
if ( current?.dtype === "Resource" ) data.min = parseInt(current.min || 0); if ( current?.dtype === "Resource" ) data.min = parseInt(current.min || 0);
data.editable = true; data.editable = true;
return data; return data;
@ -23,7 +24,7 @@ export class SimpleTokenDocument extends TokenDocument {
foundry.utils.mergeObject(data, model); foundry.utils.mergeObject(data, model);
} }
for ( const actor of game.actors ) { for ( const actor of game.actors ) {
if ( actor.isTemplate ) foundry.utils.mergeObject(data, actor.toObject().data); if ( actor.isTemplate ) foundry.utils.mergeObject(data, actor.toObject());
} }
return super.getTrackedAttributes(data); return super.getTrackedAttributes(data);
} }
@ -42,8 +43,7 @@ export class SimpleToken extends Token {
if ( "min" in data ) { if ( "min" in data ) {
// Copy the data to avoid mutating what the caller gave us. // Copy the data to avoid mutating what the caller gave us.
data = {...data}; data = {...data};
// Shift the value and max by the min to ensure that the bar's percentage is drawn accurately if this resource has // Shift the value and max by the min to draw the bar percentage accurately for a non-zero min
// a non-zero min.
data.value -= data.min; data.value -= data.min;
data.max -= data.min; data.max -= data.min;
} }

View file

@ -1,11 +1,16 @@
{ {
"name": "worldbuilding", "id": "worldbuilding",
"version": "0.7.0-alpha1",
"title": "Simple World-Building", "title": "Simple World-Building",
"url": "https://gitlab.com/foundrynet/worldbuilding/",
"description": "A minimalist game system which provides configurable Actor and Item templates to support free-form system agnostic game-play.", "description": "A minimalist game system which provides configurable Actor and Item templates to support free-form system agnostic game-play.",
"version": "0.6.5", "license": "LICENSE.txt",
"minimumCoreVersion": "0.8.9", "authors": [
"compatibleCoreVersion": "9", {
"author": "Atropos", "name": "Atropos",
"url": "https://foundryvtt.com"
}
],
"esmodules": ["module/simple.js"], "esmodules": ["module/simple.js"],
"styles": ["styles/simple.css"], "styles": ["styles/simple.css"],
"packs": [], "packs": [],
@ -16,12 +21,15 @@
"path": "lang/en.json" "path": "lang/en.json"
} }
], ],
"compatibility": {
"minimum": "10",
"verified": "10.278",
"maximum": "10"
},
"gridDistance": 5, "gridDistance": 5,
"gridUnits": "ft", "gridUnits": "ft",
"primaryTokenAttribute": "health", "primaryTokenAttribute": "health",
"secondaryTokenAttribute": "power", "secondaryTokenAttribute": "power",
"url": "https://gitlab.com/foundrynet/worldbuilding/",
"manifest": "https://raw.githubusercontent.com/foundryvtt/worldbuilding/master/system.json", "manifest": "https://raw.githubusercontent.com/foundryvtt/worldbuilding/master/system.json",
"download": "https://github.com/foundryvtt/worldbuilding/archive/refs/tags/release-065.zip", "download": "https://github.com/foundryvtt/worldbuilding/archive/refs/tags/release-065.zip"
"license": "LICENSE.txt"
} }

View file

@ -8,14 +8,14 @@
<input name="name" type="text" value="{{data.name}}" placeholder="Name" /> <input name="name" type="text" value="{{data.name}}" placeholder="Name" />
</h1> </h1>
<div class="resource"> <div class="resource">
<input type="number" name="data.health.value" value="{{systemData.health.value}}"/> <input type="number" name="system.health.value" value="{{systemData.health.value}}"/>
<span> / </span> <span> / </span>
<input type="number" name="data.health.max" value="{{systemData.health.max}}"/> <input type="number" name="system.health.max" value="{{systemData.health.max}}"/>
</div> </div>
<div class="resource"> <div class="resource">
<input type="number" name="data.power.value" value="{{systemData.power.value}}"/> <input type="number" name="system.power.value" value="{{systemData.power.value}}"/>
<span> / </span> <span> / </span>
<input type="number" name="data.power.max" value="{{systemData.power.max}}"/> <input type="number" name="system.power.max" value="{{systemData.power.max}}"/>
</div> </div>
</div> </div>
</header> </header>
@ -32,7 +32,7 @@
{{!-- Biography Tab --}} {{!-- Biography Tab --}}
<div class="tab description" data-group="primary" data-tab="description"> <div class="tab description" data-group="primary" data-tab="description">
{{editor content=systemData.biography target="data.biography" button=true owner=owner editable=editable rollData=rollData}} {{editor biographyHTML target="system.biography" button=true editable=editable engine="prosemirror"}}
</div> </div>
{{!-- Owned Items Tab --}} {{!-- Owned Items Tab --}}
@ -44,7 +44,7 @@
<h4 class="item-name">{{item.name}}</h4> <h4 class="item-name">{{item.name}}</h4>
{{!-- Iterate through all attributes on the item and output buttons for any that are formula. --}} {{!-- Iterate through all attributes on the item and output buttons for any that are formula. --}}
<div class="item-buttons"> <div class="item-buttons">
{{#each item.data.attributes as |itemAttr key|}} {{#each item.system.attributes as |itemAttr key|}}
{{#if itemAttr.dtype}} {{#if itemAttr.dtype}}
{{#if itemAttr.isFormula}} {{#if itemAttr.isFormula}}
{{!-- Use the items.name.key format for shorthand. --}} {{!-- Use the items.name.key format for shorthand. --}}
@ -112,4 +112,4 @@
</div> </div>
</div> </div>
</section> </section>
</form> </form>

View file

@ -7,11 +7,11 @@
</h1> </h1>
<div class="resource"> <div class="resource">
<label>Quantity</label> <label>Quantity</label>
<input type="number" name="data.quantity" value="{{systemData.quantity}}"/> <input type="number" name="system.quantity" value="{{systemData.quantity}}"/>
</div> </div>
<div class="resource"> <div class="resource">
<label>Weight</label> <label>Weight</label>
<input type="number" name="data.weight" value="{{systemData.weight}}"/> <input type="number" name="system.weight" value="{{systemData.weight}}"/>
</div> </div>
</div> </div>
</header> </header>
@ -27,7 +27,7 @@
{{!-- Description Tab --}} {{!-- Description Tab --}}
<div class="tab" data-group="primary" data-tab="description"> <div class="tab" data-group="primary" data-tab="description">
{{editor content=systemData.description target="data.description" button=true owner=owner editable=editable rollData=rollData}} {{editor descriptionHTML target="system.description" button=true editable=editable engine="prosemirror"}}
</div> </div>
{{!-- Attributes Tab --}} {{!-- Attributes Tab --}}
@ -53,4 +53,4 @@
</div> </div>
</div> </div>
</section> </section>
</form> </form>

View file

@ -6,50 +6,50 @@
{{#if attr.isFormula}} {{#if attr.isFormula}}
<a class="attribute-roll" data-label="{{attr.label}}" data-roll="{{attr.value}}"><i class="fas fa-dice-d20"></i></a> <a class="attribute-roll" data-label="{{attr.label}}" data-roll="{{attr.value}}"><i class="fas fa-dice-d20"></i></a>
{{/if}} {{/if}}
<input class="attribute-key" type="text" name="data.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.key" value="{{key}}" placeholder="{{localize "SIMPLE.AttributeKey"}}"/> <input class="attribute-key" type="text" name="system.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.key" value="{{key}}" placeholder="{{localize "SIMPLE.AttributeKey"}}"/>
</div> </div>
{{!-- Handle booleans. --}} {{!-- Handle booleans. --}}
{{#if attr.isCheckbox}} {{#if attr.isCheckbox}}
<label class="attribute-value checkbox"><input type="checkbox" name="data.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.value" <label class="attribute-value checkbox"><input type="checkbox" name="system.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.value"
{{checked attr.value}} /></label> {{checked attr.value}} /></label>
{{else}} {{else}}
{{!-- Handle resources. --}} {{!-- Handle resources. --}}
{{#if attr.isResource}} {{#if attr.isResource}}
<div class="attribute-group flexrow"> <div class="attribute-group flexrow">
<span class="attribute-col flexcol"> <span class="attribute-col flexcol">
<label for="data.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.min">{{localize "SIMPLE.ResourceMin"}}</label> <label for="system.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.min">{{localize "SIMPLE.ResourceMin"}}</label>
<input class="attribute-value" type="text" name="data.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.min" value="{{attr.min}}" <input class="attribute-value" type="text" name="system.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.min" value="{{attr.min}}"
data-dtype="Number" /> data-dtype="Number" />
</span> </span>
<span class="attribute-col flexcol"> <span class="attribute-col flexcol">
<label for="data.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.value">{{localize "SIMPLE.ResourceValue"}}</label> <label for="system.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.value">{{localize "SIMPLE.ResourceValue"}}</label>
<input class="attribute-value" type="text" name="data.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.value" <input class="attribute-value" type="text" name="system.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.value"
value="{{attr.value}}" data-dtype="Number" /> value="{{attr.value}}" data-dtype="Number" />
</span> </span>
<span class="attribute-col flexcol"> <span class="attribute-col flexcol">
<label for="data.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.max">{{localize "SIMPLE.ResourceMax"}}</label> <label for="system.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.max">{{localize "SIMPLE.ResourceMax"}}</label>
<input class="attribute-value" type="text" name="data.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.max" value="{{attr.max}}" <input class="attribute-value" type="text" name="system.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.max" value="{{attr.max}}"
data-dtype="Number" /> data-dtype="Number" />
</span> </span>
</div> </div>
{{!-- Handle other input types. --}} {{!-- Handle other input types. --}}
{{else}} {{else}}
<input class="attribute-value" type="text" name="data.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.value" value="{{attr.value}}" <input class="attribute-value" type="text" name="system.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.value" value="{{attr.value}}"
data-dtype="{{attr.dtype}}" placeholder="{{localize "SIMPLE.AttributeValue"}}"/> data-dtype="{{attr.dtype}}" placeholder="{{localize "SIMPLE.AttributeValue"}}"/>
{{/if}} {{/if}}
{{/if}} {{/if}}
<input class="attribute-label" type="text" name="data.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.label" value="{{attr.label}}" <input class="attribute-label" type="text" name="system.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.label" value="{{attr.label}}"
placeholder="{{localize "SIMPLE.AttributeLabel"}}"/> placeholder="{{localize "SIMPLE.AttributeLabel"}}"/>
<select class="attribute-dtype" name="data.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.dtype"> <select class="attribute-dtype" name="system.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.dtype">
{{#select attr.dtype}} {{#select attr.dtype}}
{{#each ../dtypes as |t|}} {{#each ../dtypes as |t|}}
<option value="{{t}}">{{t}}</option> <option value="{{t}}">{{t}}</option>
{{/each}} {{/each}}
{{/select}} {{/select}}
</select> </select>
<input type="hidden" name="data.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.group" value="{{attr.group}}" /> <input type="hidden" name="system.attributes.{{#if attr.group}}{{attr.group}}.{{/if}}{{key}}.group" value="{{attr.group}}" />
<a class="attribute-control" data-action="delete"><i class="fas fa-trash"></i></a> <a class="attribute-control" data-action="delete"><i class="fas fa-trash"></i></a>
</li> </li>
{{/each}} {{/each}}
</ol> </ol>
</section> </section>

View file

@ -2,9 +2,9 @@
{{#each groups as |group groupKey|}} {{#each groups as |group groupKey|}}
<li class="group" data-group="{{groupKey}}"> <li class="group" data-group="{{groupKey}}">
<div class="group-header flexrow"> <div class="group-header flexrow">
<input class="group-key" type="text" readonly name="data.groups.{{groupKey}}.key" value="{{groupKey}}" /> <input class="group-key" type="text" readonly name="system.groups.{{groupKey}}.key" value="{{groupKey}}" />
<input class="group-label" type="text" name="data.groups.{{groupKey}}.label" value="{{group.label}}" placeholder="Group Label" /> <input class="group-label" type="text" name="system.groups.{{groupKey}}.label" value="{{group.label}}" placeholder="Group Label" />
<select class="group-dtype" name="data.groups.{{groupKey}}.dtype"> <select class="group-dtype" name="system.groups.{{groupKey}}.dtype">
{{#select group.dtype}} {{#select group.dtype}}
{{#each ../dtypes as |t|}} {{#each ../dtypes as |t|}}
<option value="{{t}}">{{t}}</option> <option value="{{t}}">{{t}}</option>
@ -18,4 +18,4 @@
{{> "systems/worldbuilding/templates/parts/sheet-attributes.html" attributes=group.attributes group=groupKey dtypes=../dtypes}} {{> "systems/worldbuilding/templates/parts/sheet-attributes.html" attributes=group.attributes group=groupKey dtypes=../dtypes}}
</li> </li>
{{/each}} {{/each}}
</ol> </ol>