attribute_change logic and trauma refactoring

This commit is contained in:
Megastruktur 2020-08-21 18:03:37 +03:00
parent c2ff5bd704
commit 357446de0c
10 changed files with 87 additions and 41 deletions

View File

@ -4,6 +4,8 @@ v2.0
- Added Ghost
- Added Vampire
- Added Logic field to Item, Class and Ability
- Removed dice icons on Attributes
- Added new logic operator "name_change"
v1.2
- Non-Turf claims are no longer counted against Rep-Turf limit

View File

@ -58,6 +58,7 @@ Logic field is a json with params which allows to implement some logic when the
### Operators list
- `addition` - is added when item is attached and substracted when removed
- `attribute_change` - changes the "attribute" to value and when removed - uses the "attribute_default" to restore
## To be done in the nearest future
- Friends/rivals section

View File

@ -32,7 +32,6 @@ export class BladesCrewSheet extends BladesSheet {
if (item.type === "crew_type") {
// Object.entries(item.data.turfs).forEach(turf => {turfs_amount += (turf.value === true) ? 1 : 0});
Object.entries(item.data.turfs).forEach(([key, turf]) => {
console.log(turf);
if (turf.name === 'BITD.Turf') {
turfs_amount += (turf.value === true) ? 1 : 0;
}

View File

@ -97,21 +97,37 @@ export class BladesHelpers {
*/
static callItemLogic(item_data, entity) {
if ('logic' in item_data.data) {
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) {
// Different logic behav. dep on operator.
switch (logic.operator) {
// Add when creating.
case "addition":
entity.update({
[logic.attribute]: Number(BladesHelpers.getNestedProperty(entity, "data." + logic.attribute)) + logic.value
});
break;
}
logic.forEach(expression => {
// Different logic behav. dep on operator.
switch (expression.operator) {
// Add when creating.
case "addition":
entity.update({
[expression.attribute]: Number(BladesHelpers.getNestedProperty(entity, "data." + expression.attribute)) + expression.value
});
break;
// Change name property.
case "attribute_change":
entity.update({
[expression.attribute]: expression.value
});
break;
}
});
}
}
@ -128,20 +144,42 @@ export class BladesHelpers {
*/
static undoItemLogic(item_data, entity) {
if ('logic' in item_data.data) {
if ('logic' in item_data.data && item_data.data.logic !== '') {
let logic = JSON.parse(item_data.data.logic)
if (logic) {
// Different logic behav. dep on operator.
switch (logic.operator) {
// Subtract when removing.
case "addition":
entity.update({
[logic.attribute]: Number(BladesHelpers.getNestedProperty(entity, "data." + logic.attribute)) - logic.value
});
break;
// Should be an array to support multiple expressions
if (!Array.isArray(logic)) {
logic = [logic];
}
}
if (logic) {
var entity_data = entity.data;
logic.forEach(expression => {
// Different logic behav. dep on operator.
switch (expression.operator) {
// Subtract when removing.
case "addition":
entity.update({
[expression.attribute]: Number(BladesHelpers.getNestedProperty(entity, "data." + expression.attribute)) - expression.value
});
break;
// Change name back to default.
case "attribute_change":
console.log(entity);
// 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);
entity.update({
[expression.attribute]: default_name
});
break;
}
});
}
}

View File

@ -52,6 +52,11 @@ Hooks.once("init", async function() {
let html = options.fn(this);
// Fix for single non-array values.
if ( !Array.isArray(selected) ) {
selected = [selected];
}
if (typeof selected !== 'undefined') {
selected.forEach(selected_value => {
if (selected_value !== false) {
@ -153,7 +158,7 @@ Hooks.once("ready", function() {
// Determine whether a system migration is required
const currentVersion = game.settings.get("bitd", "systemMigrationVersion");
const NEEDS_MIGRATION_VERSION = 1.2;
const NEEDS_MIGRATION_VERSION = 2.0;
let needMigration = (currentVersion < NEEDS_MIGRATION_VERSION) || (currentVersion === null);

View File

@ -78,6 +78,7 @@ function _migrateActor(actor) {
// Migrate Trauma to Array
if (typeof actor.data.trauma === 'undefined') {
updateData[`data.trauma.list`] = actor.data.traumas;
updateData[`data.trauma.value`] = [actor.data.traumas.length];
updateData[`data.trauma.max`] = 4;
updateData[`data.trauma.max_default`] = 4;
updateData[`data.trauma.name_default`] = "BITD.Trauma";

View File

@ -2,7 +2,7 @@
"name": "blades-in-the-dark",
"title": "Blades in the Dark",
"description": "Blades in the dark game system.",
"version": "1.2",
"version": "2.0",
"minimumCoreVersion": "0.5.3",
"compatibleCoreVersion": "0.7.2",
"templateVersion": 1,
@ -26,8 +26,8 @@
}
],
"url": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/",
"manifest": "https://raw.githubusercontent.com/megastruktur/foundryvtt-blades-in-the-dark/1.2/system.json",
"download": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/archive/1.2.zip",
"manifest": "https://raw.githubusercontent.com/megastruktur/foundryvtt-blades-in-the-dark/2.0/system.json",
"download": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/archive/2.0.zip",
"packs": [
{
"name": "class",

View File

@ -13,6 +13,7 @@
"trauma": {
"max": 4,
"max_default": 4,
"value": [0],
"name": "BITD.Trauma",
"name_default": "BITD.Trauma",
"list": [0]

View File

@ -94,11 +94,11 @@
<div id="character-stress" class="big-teeth">
{{#multiboxes data.stress.value}}
<input type="radio" id="character-stress-0" name="data.stress" value="0" dtype="Radio">
<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="{{this}}" dtype="Radio">
<input type="radio" id="character-stress-{{this}}" name="data.stress.value" value="{{this}}" dtype="Radio">
<label for="character-stress-{{this}}"></label>
{{/times_from_1}}
@ -110,10 +110,10 @@
<div id="character-trauma" class="small-teeth-wrap">
<label class="black-label" for="character-trauma-counter-0">{{localize "BITD.Trauma"}}</label>
<div id="trauma-teeth" class="small-teeth">
<input type="radio" id="character-trauma-counter-0" name="trauma-counter" value="0">
<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="trauma-counter" value="{{this}}">
<input type="radio" id="character-trauma-counter-{{this}}" name="data.trauma.value" value="{{this}}">
<label for="character-trauma-counter-{{this}}"></label>
{{/times_from_1}}
</div>
@ -124,35 +124,35 @@
<div id="trauma-list">
{{#multiboxes data.trauma.list}}
<label>
<input type="checkbox" name="data.traumas" value="cold">
<input type="checkbox" name="data.trauma.list" value="cold">
<span class="checkmark">{{localize "BITD.TraumaCold"}}</span>
</label>
<label>
<input type="checkbox" name="data.traumas" value="haunted">
<input type="checkbox" name="data.trauma.list" value="haunted">
<span class="checkmark">{{localize "BITD.TraumaHaunted"}}</span>
</label>
<label>
<input type="checkbox" name="data.traumas" value="obsessed">
<input type="checkbox" name="data.trauma.list" value="obsessed">
<span class="checkmark">{{localize "BITD.TraumaObsessed"}}</span>
</label>
<label>
<input type="checkbox" name="data.traumas" value="paranoid">
<input type="checkbox" name="data.trauma.list" value="paranoid">
<span class="checkmark">{{localize "BITD.TraumaParanoid"}}</span>
</label>
<label>
<input type="checkbox" name="data.traumas" value="reckless">
<input type="checkbox" name="data.trauma.list" value="reckless">
<span class="checkmark">{{localize "BITD.TraumaReckless"}}</span>
</label>
<label>
<input type="checkbox" name="data.traumas" value="soft">
<input type="checkbox" name="data.trauma.list" value="soft">
<span class="checkmark">{{localize "BITD.TraumaSoft"}}</span>
</label>
<label>
<input type="checkbox" name="data.traumas" value="unstable">
<input type="checkbox" name="data.trauma.list" value="unstable">
<span class="checkmark">{{localize "BITD.TraumaUnstable"}}</span>
</label>
<label>
<input type="checkbox" name="data.traumas" value="vicious">
<input type="checkbox" name="data.trauma.list" value="vicious">
<span class="checkmark">{{localize "BITD.TraumaVicious"}}</span>
</label>
{{/multiboxes}}

View File

@ -6,7 +6,6 @@
<div id="attributes-{{attribute_name}}-title" class="attributes-exp">
<div class="stripe">
<label class="attribute-label roll-die-attribute rollable-text" data-roll-attribute="{{attribute_name}}" for="{{attribute_name}}-exp-0">{{localize attribute.label}}</label>
<a class="roll-die-attribute" data-roll-attribute="{{attribute_name}}" title="Roll"><i class="fas fa-dice"></i></a>
</div>
<div class="stripe-tooth-body">
{{#multiboxes attribute.exp}}