From 36c23e1eb5d366eeb8c62c117430abaaa2116323 Mon Sep 17 00:00:00 2001 From: Thaum Rystra Date: Thu, 28 May 2020 21:06:40 +0200 Subject: [PATCH] Made hiding stats that aren't targeted by effects or proficiencies an option --- app/imports/api/creature/Creatures.js | 5 ++ .../creature/computation/EffectAggregator.js | 6 ++- .../api/creature/computation/combineStat.js | 14 ++++- app/imports/api/properties/Attributes.js | 5 ++ app/imports/api/properties/Skills.js | 5 ++ app/imports/ui/creature/CreatureForm.vue | 19 ++++--- .../character/characterSheetTabs/StatsTab.vue | 51 +++++++++++-------- 7 files changed, 75 insertions(+), 30 deletions(-) diff --git a/app/imports/api/creature/Creatures.js b/app/imports/api/creature/Creatures.js index 27ce6859..d65aae6f 100644 --- a/app/imports/api/creature/Creatures.js +++ b/app/imports/api/creature/Creatures.js @@ -27,6 +27,11 @@ let CreatureSettingsSchema = new SimpleSchema({ type: Boolean, optional: true, }, + // Hide all the unused stats + hideUnusedStats: { + type: Boolean, + optional: true, + } }); let CreatureSchema = new SimpleSchema({ diff --git a/app/imports/api/creature/computation/EffectAggregator.js b/app/imports/api/creature/computation/EffectAggregator.js index 03207239..f9c2c364 100644 --- a/app/imports/api/creature/computation/EffectAggregator.js +++ b/app/imports/api/creature/computation/EffectAggregator.js @@ -24,15 +24,19 @@ export default class EffectAggregator{ this.set = undefined; this.conditional = []; this.rollBonus = []; + this.hasNoEffects = true; } addEffect(effect){ let result = effect.result; + if (this.hasNoEffects) this.hasNoEffects = false; switch(effect.operation){ case 'base': // Take the largest base value this.base = result > this.base ? result : this.base; if (effect.statBase){ - this.statBaseValue = result > this.statBaseValue ? result : this.statBaseValue; + if (this.statBaseValue === undefined || result > this.statBaseValue){ + this.statBaseValue = result; + } } break; case 'add': diff --git a/app/imports/api/creature/computation/combineStat.js b/app/imports/api/creature/computation/combineStat.js index 5f3292d3..be1ed6a0 100644 --- a/app/imports/api/creature/computation/combineStat.js +++ b/app/imports/api/creature/computation/combineStat.js @@ -36,6 +36,9 @@ function combineAttribute(stat, aggregator){ stat.modifier = Math.floor((stat.value - 10) / 2); } stat.currentValue = stat.value - (stat.damage || 0); + stat.hide = aggregator.hasNoEffects && + stat.baseValue === undefined || + undefined } function combineSkill(stat, aggregator, memo){ @@ -73,7 +76,12 @@ function combineSkill(stat, aggregator, memo){ let result = (stat.abilityMod + profBonus + aggregator.add) * aggregator.mul; if (result < aggregator.min) result = aggregator.min; if (result > aggregator.max) result = aggregator.max; - result = Math.floor(result); + if (aggregator.set !== undefined) { + result = aggregator.set; + } + if (Number.isFinite(result)){ + result = Math.floor(result); + } stat.value = result; // Advantage/disadvantage if (aggregator.advantage && !aggregator.disadvantage){ @@ -93,6 +101,10 @@ function combineSkill(stat, aggregator, memo){ stat.fail = aggregator.fail; // Rollbonus stat.rollBonuses = aggregator.rollBonus; + // Hide + stat.hide = aggregator.hasNoEffects && + stat.proficiency == 0 || + undefined; } function combineDamageMultiplier(stat){ diff --git a/app/imports/api/properties/Attributes.js b/app/imports/api/properties/Attributes.js index 0b5fcfea..1eb63ab9 100644 --- a/app/imports/api/properties/Attributes.js +++ b/app/imports/api/properties/Attributes.js @@ -93,6 +93,11 @@ let ComputedOnlyAttributeSchema = new SimpleSchema({ type: SimpleSchema.Integer, optional: true, }, + // Should this attribute hide + hide: { + type: Boolean, + optional: true, + }, }); const ComputedAttributeSchema = new SimpleSchema() diff --git a/app/imports/api/properties/Skills.js b/app/imports/api/properties/Skills.js index eb871161..a4310d55 100644 --- a/app/imports/api/properties/Skills.js +++ b/app/imports/api/properties/Skills.js @@ -101,6 +101,11 @@ let ComputedOnlySkillSchema = new SimpleSchema({ type: SimpleSchema.Integer, optional: true, }, + // Should this attribute hide + hide: { + type: Boolean, + optional: true, + }, }) const ComputedSkillSchema = new SimpleSchema() diff --git a/app/imports/ui/creature/CreatureForm.vue b/app/imports/ui/creature/CreatureForm.vue index 67908e28..ddec2f8d 100644 --- a/app/imports/ui/creature/CreatureForm.vue +++ b/app/imports/ui/creature/CreatureForm.vue @@ -42,9 +42,16 @@ :disabled="disabled" @change="(value, ack) => $emit('change', {path: ['avatarPicture'], value, ack})" /> - + --> + + diff --git a/app/imports/ui/creature/character/characterSheetTabs/StatsTab.vue b/app/imports/ui/creature/character/characterSheetTabs/StatsTab.vue index fe552fa8..8f658db5 100644 --- a/app/imports/ui/creature/character/characterSheetTabs/StatsTab.vue +++ b/app/imports/ui/creature/character/characterSheetTabs/StatsTab.vue @@ -1,5 +1,8 @@