Added calculation errors to attributes and toggles
This commit is contained in:
@@ -2,13 +2,12 @@ import evaluateCalculation from '/imports/api/creature/computation/evaluateCalcu
|
||||
|
||||
export default class EffectAggregator{
|
||||
constructor(stat, memo){
|
||||
delete this.baseValueErrors;
|
||||
if (stat.baseValueCalculation){
|
||||
let {value, errors} = evaluateCalculation(stat.baseValueCalculation, memo);
|
||||
this.statBaseValue = value;
|
||||
if (errors.length){
|
||||
this.baseValueErrors = errors;
|
||||
} else {
|
||||
delete this.baseValueErrors;
|
||||
}
|
||||
this.base = this.statBaseValue;
|
||||
} else {
|
||||
|
||||
@@ -31,6 +31,7 @@ function getAggregatorResult(stat, aggregator){
|
||||
function combineAttribute(stat, aggregator){
|
||||
stat.value = getAggregatorResult(stat, aggregator);
|
||||
stat.baseValue = aggregator.statBaseValue;
|
||||
stat.baseValueErrors = aggregator.baseValueErrors;
|
||||
if (stat.attributeType === 'ability') {
|
||||
stat.modifier = Math.floor((stat.value - 10) / 2);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ export default function computeToggle(toggle, memo){
|
||||
toggle.computationDetails.busyComputing = true;
|
||||
|
||||
// Do work
|
||||
delete toggle.errors;
|
||||
if (toggle.enabled){
|
||||
toggle.toggleResult = true;
|
||||
} else if (toggle.disabled){
|
||||
@@ -29,8 +30,6 @@ export default function computeToggle(toggle, memo){
|
||||
toggle.toggleResult = value;
|
||||
if (errors.length){
|
||||
toggle.errors = errors;
|
||||
} else {
|
||||
delete toggle.errors;
|
||||
}
|
||||
}
|
||||
toggle.computationDetails.computed = true;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js';
|
||||
|
||||
/*
|
||||
@@ -73,6 +74,13 @@ let ComputedOnlyAttributeSchema = new SimpleSchema({
|
||||
baseValue: {
|
||||
type: SimpleSchema.oneOf(Number, String, Boolean),
|
||||
optional: true,
|
||||
},
|
||||
baseValueErrors: {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'baseValueErrors.$': {
|
||||
type: ErrorSchema,
|
||||
},
|
||||
// The computed value of the attribute
|
||||
value: {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||
|
||||
const ToggleSchema = new SimpleSchema({
|
||||
name: {
|
||||
@@ -32,8 +33,8 @@ const ComputedOnlyToggleSchema = new SimpleSchema({
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'errors.$':{
|
||||
type: String,
|
||||
'errors.$': {
|
||||
type: ErrorSchema,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user