- Closes GH-81
- Updates the functionality with checkboxes and new FormDataExtended api.
- Fixes Traumas for FVTT 0.7.2+.
- Version update to be FVTT 0.7.2+ compatible.
This commit is contained in:
Megastruktur 2020-10-18 13:21:37 +03:00
parent 0572faf7d9
commit 22467a1f5e
9 changed files with 25 additions and 106 deletions

View File

@ -1,3 +1,8 @@
v2.5
- Updates the functionality with checkboxes and new FormDataExtended api.
- Fixes Traumas for FVTT 0.7.2+.
- Version update to be FVTT 0.7.2+ compatible.
v2.4
- Fixed Rolls: roll position is shown correctly now

View File

@ -95,12 +95,6 @@ export class BladesActorSheet extends BladesSheet {
return this.object.update(formData);
}
/** override */
_getFormData(form) {
const FD = BladesHelpers.getFormDataHelper(form, this.editors);
return FD;
}
/* -------------------------------------------- */
}

View File

@ -101,14 +101,6 @@ export class BladesCrewSheet extends BladesSheet {
});
}
/* -------------------------------------------- */
/** override */
_getFormData(form) {
const FD = BladesHelpers.getFormDataHelper(form, this.editors);
return FD;
}
/* -------------------------------------------- */
/* Form Submission */
/* -------------------------------------------- */

View File

@ -20,76 +20,6 @@ export class BladesHelpers {
});
}
/**
* _getFormData() override helper.
* @param {*} form
*/
static getFormDataHelper(form, editors) {
const FD = new FormData(form);
const dtypes = {};
const editorTargets = Object.keys(editors);
// 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(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;
}
/**
* Add item modification if logic exists.
* @param {Object} item_data

View File

@ -40,12 +40,4 @@ export class BladesItemSheet extends ItemSheet {
}
/* -------------------------------------------- */
/** override */
_getFormData(form) {
const FD = BladesHelpers.getFormDataHelper(form, this.editors);
return FD;
}
/* -------------------------------------------- */
}

View File

@ -102,6 +102,7 @@ export class BladesSheet extends ActorSheet {
this.actor.rollAttributePopup(attribute_name);
}
/* -------------------------------------------- */
}

View File

@ -73,7 +73,14 @@ Hooks.once("init", async function() {
Handlebars.registerHelper('traumacounter', function(selected, options) {
let html = options.fn(this);
var count = selected.length;
var count = 0;
for (const trauma in selected) {
if (selected[trauma] === true) {
count++;
}
}
if (count > 4) count = 4;
const rgx = new RegExp(' value=\"' + count + '\"');

View File

@ -3,7 +3,7 @@
"title": "Blades in the Dark",
"description": "Blades in the dark game system.",
"version": "2.5",
"minimumCoreVersion": "0.7.0",
"minimumCoreVersion": "0.7.2",
"compatibleCoreVersion": "0.7.4",
"templateVersion": 1,
"author": "megastruktur",

View File

@ -96,7 +96,7 @@
<input type="radio" id="character-stress-0" name="data.stress.value" value="0" dtype="Radio">
<label class="black-label" for="character-stress-0">{{localize data.stress.name}}</label>
{{#times_from_1 data.stress.max}}
<input type="radio" id="character-stress-{{this}}" name="data.stress.value" value="{{this}}" dtype="Radio">
<label for="character-stress-{{this}}"></label>
@ -113,7 +113,7 @@
<input type="radio" id="character-trauma-counter-0" name="data.trauma.value" value="0">
{{#times_from_1 data.trauma.max}}
<input type="radio" id="character-trauma-counter-{{this}}" name="data.trauma.value" value="{{this}}">
<input type="radio" id="character-trauma-counter-{{this}}" name="data.trauma.value" value="{{this}}" disabled>
<label for="character-trauma-counter-{{this}}"></label>
{{/times_from_1}}
</div>
@ -122,40 +122,38 @@
</div>
<div id="trauma-list">
{{#multiboxes data.trauma.list}}
<label>
<input type="checkbox" name="data.trauma.list" value="cold">
<input type="checkbox" name="data.trauma.list.cold" value="cold" {{checked data.trauma.list.cold}}>
<span class="checkmark">{{localize "BITD.TraumaCold"}}</span>
</label>
<label>
<input type="checkbox" name="data.trauma.list" value="haunted">
<input type="checkbox" name="data.trauma.list.haunted" value="haunted" {{checked data.trauma.list.haunted}}>
<span class="checkmark">{{localize "BITD.TraumaHaunted"}}</span>
</label>
<label>
<input type="checkbox" name="data.trauma.list" value="obsessed">
<input type="checkbox" name="data.trauma.list.obsessed" value="obsessed" {{checked data.trauma.list.obsessed}}>
<span class="checkmark">{{localize "BITD.TraumaObsessed"}}</span>
</label>
<label>
<input type="checkbox" name="data.trauma.list" value="paranoid">
<input type="checkbox" name="data.trauma.list.paranoid" value="paranoid" {{checked data.trauma.list.paranoid}}>
<span class="checkmark">{{localize "BITD.TraumaParanoid"}}</span>
</label>
<label>
<input type="checkbox" name="data.trauma.list" value="reckless">
<input type="checkbox" name="data.trauma.list.reckless" value="reckless" {{checked data.trauma.list.reckless}}>
<span class="checkmark">{{localize "BITD.TraumaReckless"}}</span>
</label>
<label>
<input type="checkbox" name="data.trauma.list" value="soft">
<input type="checkbox" name="data.trauma.list.soft" value="soft" {{checked data.trauma.list.soft}}>
<span class="checkmark">{{localize "BITD.TraumaSoft"}}</span>
</label>
<label>
<input type="checkbox" name="data.trauma.list" value="unstable">
<input type="checkbox" name="data.trauma.list.unstable" value="unstable" {{checked data.trauma.list.unstable}}>
<span class="checkmark">{{localize "BITD.TraumaUnstable"}}</span>
</label>
<label>
<input type="checkbox" name="data.trauma.list" value="vicious">
<input type="checkbox" name="data.trauma.list.vicious" value="vicious" {{checked data.trauma.list.vicious}}>
<span class="checkmark">{{localize "BITD.TraumaVicious"}}</span>
</label>
{{/multiboxes}}
</div>
</div>