Merge branch 'release/3.12'

This commit is contained in:
Megastruktur 2021-11-02 11:12:10 +03:00
commit 888d4c5f6d
6 changed files with 26 additions and 153 deletions

View file

@ -1,3 +1,7 @@
v.3.12
- Fix cohort scale and quality calculation #161
- Removed itemLogic calls #160
v.3.11
- Fix the version number

View file

@ -25,111 +25,6 @@ export class BladesHelpers {
return dupe_list;
}
/**
* Add item modification if logic exists.
* @param {Object} item_data
* @param {Document} entity
*/
static async callItemLogic(item_data, entity) {
if ('logic' in item_data.data && item_data.data.logic !== '') {
let logic = JSON.parse(item_data.data.logic);
// Should be an array to support multiple expressions
if (!Array.isArray(logic)) {
logic = [logic];
}
if (logic) {
let logic_update = { "_id": entity.id };
logic.forEach(expression => {
// Different logic behav. dep on operator.
switch (expression.operator) {
// Add when creating.
case "addition":
foundry.utils.mergeObject(
logic_update,
{[expression.attribute]: Number(BladesHelpers.getNestedProperty(entity, prefix + expression.attribute)) + expression.value},
{insertKeys: true}
);
break;
// Change name property.
case "attribute_change":
foundry.utils.mergeObject(
logic_update,
{[expression.attribute]: expression.value},
{insertKeys: true}
);
break;
}
});
await Actor.updateDocuments( logic_update );
}
}
}
/**
* Undo Item modifications when item is removed.
* @todo
* - Remove all items and then Add them back to
* sustain the logic mods
* @param {Object} item_data
* @param {Document} entity
*/
static async undoItemLogic(item_data, entity) {
if ('logic' in item_data.data && item_data.data.logic !== '') {
let logic = JSON.parse(item_data.data.logic)
// Should be an array to support multiple expressions
if (!Array.isArray(logic)) {
logic = [logic];
}
if (logic) {
let logic_update = { "_id": entity.id };
var entity_data = entity.data;
logic.forEach(expression => {
// Different logic behav. dep on operator.
switch (expression.operator) {
// Subtract when removing.
case "addition":
foundry.utils.mergeObject(
logic_update,
{[expression.attribute]: Number(BladesHelpers.getNestedProperty(entity, expression.attribute)) - expression.value},
{insertKeys: true}
);
break;
// Change name back to default.
case "attribute_change":
// Get the array path to take data.
let default_expression_attribute_path = expression.attribute + '_default';
let default_name = default_expression_attribute_path.split(".").reduce((o, i) => o[i], entity_data);
foundry.utils.mergeObject(
logic_update,
{[expression.attribute]: default_name},
{insertKeys: true}
);
break;
}
});
await Actor.updateDocuments( logic_update );
}
}
}
/**
* Get a nested dynamic attribute.
* @param {Object} obj

View file

@ -24,46 +24,18 @@ export class BladesItem extends Item {
/* -------------------------------------------- */
/** @override */
async _onCreate( data, options, userId ) {
super._onCreate( data, options, userId );
if( userId === game.user.id ) {
let actor = this.parent ? this.parent : null;
if( ( actor?.documentName === "Actor" ) && ( actor?.permission >= CONST.ENTITY_PERMISSIONS.OWNER ) ) {
await BladesHelpers.callItemLogic( data, actor );
}
}
}
/* -------------------------------------------- */
/** @override */
async _onDelete( options, userId ) {
super._onDelete( options, userId );
let actor = this.parent ? this.parent : null;
let data = this.data;
if ( ( actor?.documentName === "Actor" ) && ( actor?.permission >= CONST.ENTITY_PERMISSIONS.OWNER ) ) {
await BladesHelpers.undoItemLogic( data, actor );
}
}
/* -------------------------------------------- */
/* override */
prepareData() {
super.prepareData();
const item_data = this.data;
const data = item_data.data;
if (item_data.type === "cohort") {
this._prepareCohort(data);
}
if (item_data.type === "faction") {
@ -80,7 +52,7 @@ export class BladesItem extends Item {
/**
* Prepares Cohort data
*
* @param {object} data
* @param {object} data
*/
_prepareCohort(data) {
@ -88,22 +60,22 @@ export class BladesItem extends Item {
let scale = 0;
// Adds Scale and Quality
if (this.actor) {
switch (data.cohort[0]) {
if (this.actor.data) {
switch (data.cohort) {
case "Gang":
scale = parseInt(this.actor.data.data.tier[0]);
quality = parseInt(this.actor.data.data.tier[0]);
scale = parseInt(this.actor.data.data.tier);
quality = parseInt(this.actor.data.data.tier);
break;
case "Expert":
scale = 1;
quality = parseInt(this.actor.data.data.tier[0]) + 1;
scale = 0;
quality = parseInt(this.actor.data.data.tier) + 1;
break;
}
}
data.scale = scale;
data.quality = quality;
this.data.data = data;
}
}

View file

@ -2,7 +2,7 @@
"name": "blades-in-the-dark",
"title": "Blades in the Dark",
"description": "Blades in the dark game system.",
"version": "3.11",
"version": "3.12",
"minimumCoreVersion": "0.8.5",
"compatibleCoreVersion": "0.8.9",
"templateVersion": 1,
@ -47,7 +47,7 @@
],
"url": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/",
"manifest": "https://raw.githubusercontent.com/megastruktur/foundryvtt-blades-in-the-dark/master/system.json",
"download": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/archive/3.11.zip",
"download": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/archive/3.12.zip",
"packs": [
{
"name": "class",

View file

@ -136,7 +136,7 @@
"name": "",
"reputation": [0],
"lair": "",
"tier": [0],
"tier": "",
"deity": "",
"hold": ["strong"],
"experience": [0],

View file

@ -6,7 +6,7 @@
<h1 class="charname"><input name="name" type="text" value="{{item.name}}" placeholder="{{localize 'BITD.Name'}}"/></h1>
</div>
</header>
<section class="flex-vertical">
<div class="label-stripe">{{localize "BITD.Information"}}</div>
@ -56,11 +56,13 @@
</section>
{{!-- Scale and Quality if attached to Actor --}}
{{#if data.quality}}
{{#if (eq document.parent.documentName "Actor")}}
<section id="quality-scale" class="flex-vertical">
<div class="label-stripe">{{localize "BITD.ScaleAndQuality"}}</div>
<div>{{localize "BITD.Quality"}}: {{data.quality}}</div>
<div>{{localize "BITD.Scale"}}: {{data.scale}}</div>
<div>
{{localize "BITD.Quality"}}: {{data.quality}}
{{localize "BITD.Scale"}}: {{data.scale}}
</div>
</section>
{{/if}}
@ -97,7 +99,7 @@
</section>
<section id="cohort-harm" class="flex-vertical">
<div class="label-stripe">{{localize "BITD.Harm"}}</div>
<div id="harm-list" class="flex-horizontal">
@ -110,7 +112,7 @@
</div>
</section>
<section class="flex">
<section class="flex-horizontal" style="justify-content: unset;">
<input id="cohort-armor" type="checkbox" name="data.armor" value="{{data.armor}}" {{checked data.armor}}>
<label for="cohort-armor">{{localize "BITD.Armor"}}</label>
</section>