Cleaning up

This commit is contained in:
Peter Varaksin 2020-04-18 00:48:29 +03:00
parent 43633acd0d
commit eaa157f08b
4 changed files with 70 additions and 84806 deletions

View file

@ -2,7 +2,7 @@
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
export class SimpleActorSheet extends ActorSheet {
export class BladesActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
@ -125,4 +125,69 @@ export class SimpleActorSheet extends ActorSheet {
// Update the Actor
return this.object.update(formData);
}
/** @override */
_getFormData(form) {
const FD = new FormData(form);
const dtypes = {};
const editorTargets = Object.keys(this.editors);
console.log('YAMAMMMMMMAAAAAAAAAAAAAA!!!!');
// Always include checkboxes
for ( let el of form.elements ) {
if ( !el.name ) continue;
// Handle Radio groups
if ( form[el.name] instanceof RadioNodeList ) {
const inputs = Array.from(form[el.name]);
if ( inputs.every(i => i.disabled) ) FD.delete(k);
let values = "";
let type = "Checkboxes";
values = inputs.map(i => i.checked ? i.value : false).filter(i => i);
FD.set(el.name, JSON.stringify(values));
dtypes[el.name] = 'Radio';
}
// Remove disabled elements
else if ( el.disabled ) FD.delete(el.name);
// Checkboxes
else if ( el.type == "checkbox" ) {
FD.set(el.name, el.checked || false);
dtypes[el.name] = "Boolean";
}
// Include dataset dtype
else if ( el.dataset.dtype ) dtypes[el.name] = el.dataset.dtype;
}
// Process editable images
for ( let img of form.querySelectorAll('img[data-edit]') ) {
if ( img.getAttribute("disabled") ) continue;
let basePath = window.location.origin+"/";
if ( ROUTE_PREFIX ) basePath += ROUTE_PREFIX+"/";
FD.set(img.dataset.edit, img.src.replace(basePath, ""));
}
// Process editable divs (excluding MCE editors)
for ( let div of form.querySelectorAll('div[data-edit]') ) {
if ( div.getAttribute("disabled") ) continue;
else if ( editorTargets.includes(div.dataset.edit) ) continue;
FD.set(div.dataset.edit, div.innerHTML.trim());
}
// Handle MCE editors
Object.values(this.editors).forEach(ed => {
if ( ed.mce ) {
FD.delete(ed.mce.id);
if ( ed.changed ) FD.set(ed.target, ed.mce.getContent());
}
});
// Record target data types for casting
FD._dtypes = dtypes;
return FD;
}
}

View file

@ -6,14 +6,14 @@
// Import Modules
import { SimpleItemSheet } from "./item-sheet.js";
import { SimpleActorSheet } from "./actor-sheet.js";
import { BladesActorSheet } from "./actor-sheet.js";
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks.once("init", async function() {
console.log(`Initializing Simple Worldbuilding System`);
console.log(`Initializing Blades In the Dark System`);
/**
* Set an initiative formula for the system
@ -26,7 +26,7 @@ Hooks.once("init", async function() {
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
Actors.registerSheet("dnd5e", SimpleActorSheet, { makeDefault: true });
Actors.registerSheet("dnd5e", BladesActorSheet, { makeDefault: true });
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("dnd5e", SimpleItemSheet, {makeDefault: true});
@ -55,7 +55,7 @@ Hooks.once("init", async function() {
const rgx = new RegExp(' value=\"' + count + '\"');
return html.replace(rgx, "$& checked=\"checked\"");
});
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long