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{
|
export default class EffectAggregator{
|
||||||
constructor(stat, memo){
|
constructor(stat, memo){
|
||||||
|
delete this.baseValueErrors;
|
||||||
if (stat.baseValueCalculation){
|
if (stat.baseValueCalculation){
|
||||||
let {value, errors} = evaluateCalculation(stat.baseValueCalculation, memo);
|
let {value, errors} = evaluateCalculation(stat.baseValueCalculation, memo);
|
||||||
this.statBaseValue = value;
|
this.statBaseValue = value;
|
||||||
if (errors.length){
|
if (errors.length){
|
||||||
this.baseValueErrors = errors;
|
this.baseValueErrors = errors;
|
||||||
} else {
|
|
||||||
delete this.baseValueErrors;
|
|
||||||
}
|
}
|
||||||
this.base = this.statBaseValue;
|
this.base = this.statBaseValue;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ function getAggregatorResult(stat, aggregator){
|
|||||||
function combineAttribute(stat, aggregator){
|
function combineAttribute(stat, aggregator){
|
||||||
stat.value = getAggregatorResult(stat, aggregator);
|
stat.value = getAggregatorResult(stat, aggregator);
|
||||||
stat.baseValue = aggregator.statBaseValue;
|
stat.baseValue = aggregator.statBaseValue;
|
||||||
|
stat.baseValueErrors = aggregator.baseValueErrors;
|
||||||
if (stat.attributeType === 'ability') {
|
if (stat.attributeType === 'ability') {
|
||||||
stat.modifier = Math.floor((stat.value - 10) / 2);
|
stat.modifier = Math.floor((stat.value - 10) / 2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export default function computeToggle(toggle, memo){
|
|||||||
toggle.computationDetails.busyComputing = true;
|
toggle.computationDetails.busyComputing = true;
|
||||||
|
|
||||||
// Do work
|
// Do work
|
||||||
|
delete toggle.errors;
|
||||||
if (toggle.enabled){
|
if (toggle.enabled){
|
||||||
toggle.toggleResult = true;
|
toggle.toggleResult = true;
|
||||||
} else if (toggle.disabled){
|
} else if (toggle.disabled){
|
||||||
@@ -29,8 +30,6 @@ export default function computeToggle(toggle, memo){
|
|||||||
toggle.toggleResult = value;
|
toggle.toggleResult = value;
|
||||||
if (errors.length){
|
if (errors.length){
|
||||||
toggle.errors = errors;
|
toggle.errors = errors;
|
||||||
} else {
|
|
||||||
delete toggle.errors;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toggle.computationDetails.computed = true;
|
toggle.computationDetails.computed = true;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
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';
|
import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -73,6 +74,13 @@ let ComputedOnlyAttributeSchema = new SimpleSchema({
|
|||||||
baseValue: {
|
baseValue: {
|
||||||
type: SimpleSchema.oneOf(Number, String, Boolean),
|
type: SimpleSchema.oneOf(Number, String, Boolean),
|
||||||
optional: true,
|
optional: true,
|
||||||
|
},
|
||||||
|
baseValueErrors: {
|
||||||
|
type: Array,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
'baseValueErrors.$': {
|
||||||
|
type: ErrorSchema,
|
||||||
},
|
},
|
||||||
// The computed value of the attribute
|
// The computed value of the attribute
|
||||||
value: {
|
value: {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||||
|
|
||||||
const ToggleSchema = new SimpleSchema({
|
const ToggleSchema = new SimpleSchema({
|
||||||
name: {
|
name: {
|
||||||
@@ -32,8 +33,8 @@ const ComputedOnlyToggleSchema = new SimpleSchema({
|
|||||||
type: Array,
|
type: Array,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
'errors.$':{
|
'errors.$': {
|
||||||
type: String,
|
type: ErrorSchema,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
@change="change('baseValueCalculation', ...arguments)"
|
@change="change('baseValueCalculation', ...arguments)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<calculation-error-list :errors="model.baseValueErrors" />
|
||||||
<div class="layout row wrap">
|
<div class="layout row wrap">
|
||||||
<text-field
|
<text-field
|
||||||
label="Name"
|
label="Name"
|
||||||
@@ -100,10 +101,12 @@
|
|||||||
<script>
|
<script>
|
||||||
import FormSection from '/imports/ui/properties/forms/shared/FormSection.vue';
|
import FormSection from '/imports/ui/properties/forms/shared/FormSection.vue';
|
||||||
import propertyFormMixin from '/imports/ui/properties/forms/shared/propertyFormMixin.js';
|
import propertyFormMixin from '/imports/ui/properties/forms/shared/propertyFormMixin.js';
|
||||||
|
import CalculationErrorList from '/imports/ui/properties/forms/shared/CalculationErrorList.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
FormSection,
|
FormSection,
|
||||||
|
CalculationErrorList,
|
||||||
},
|
},
|
||||||
mixins: [propertyFormMixin],
|
mixins: [propertyFormMixin],
|
||||||
data(){
|
data(){
|
||||||
|
|||||||
@@ -56,26 +56,7 @@
|
|||||||
:hint="!isFinite(model.calculation) && model.result ? model.result + '' : '' "
|
:hint="!isFinite(model.calculation) && model.result ? model.result + '' : '' "
|
||||||
@change="change('calculation', ...arguments)"
|
@change="change('calculation', ...arguments)"
|
||||||
/>
|
/>
|
||||||
<div
|
<calculation-error-list :errors="model.errors" />
|
||||||
v-if="model.errors && model.errors.length"
|
|
||||||
two-line
|
|
||||||
>
|
|
||||||
<v-slide-x-transition
|
|
||||||
group
|
|
||||||
leave-absolute
|
|
||||||
>
|
|
||||||
<v-alert
|
|
||||||
v-for="error in model.errors"
|
|
||||||
:key="error.message"
|
|
||||||
:value="true"
|
|
||||||
:icon="errorIcon(error.type)"
|
|
||||||
:color="errorColor(error.type)"
|
|
||||||
outline
|
|
||||||
>
|
|
||||||
{{ error.message }}
|
|
||||||
</v-alert>
|
|
||||||
</v-slide-x-transition>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -83,9 +64,13 @@
|
|||||||
import getEffectIcon from '/imports/ui/utility/getEffectIcon.js';
|
import getEffectIcon from '/imports/ui/utility/getEffectIcon.js';
|
||||||
import propertyFormMixin from '/imports/ui/properties/forms/shared/propertyFormMixin.js';
|
import propertyFormMixin from '/imports/ui/properties/forms/shared/propertyFormMixin.js';
|
||||||
import attributeListMixin from '/imports/ui/properties/forms/shared/lists/attributeListMixin.js';
|
import attributeListMixin from '/imports/ui/properties/forms/shared/lists/attributeListMixin.js';
|
||||||
|
import CalculationErrorList from '/imports/ui/properties/forms/shared/CalculationErrorList.vue';
|
||||||
|
|
||||||
const ICON_SPIN_DURATION = 300;
|
const ICON_SPIN_DURATION = 300;
|
||||||
export default {
|
export default {
|
||||||
|
components: {
|
||||||
|
CalculationErrorList,
|
||||||
|
},
|
||||||
mixins: [propertyFormMixin, attributeListMixin],
|
mixins: [propertyFormMixin, attributeListMixin],
|
||||||
data(){ return {
|
data(){ return {
|
||||||
displayedIcon: 'add',
|
displayedIcon: 'add',
|
||||||
@@ -145,24 +130,6 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
errorIcon(type){
|
|
||||||
if (type === 'subsitution'){
|
|
||||||
return 'info';
|
|
||||||
} else if (type === 'evaluation'){
|
|
||||||
return 'warning';
|
|
||||||
} else {
|
|
||||||
return 'error'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
errorColor(type){
|
|
||||||
if (type === 'subsitution'){
|
|
||||||
return 'info';
|
|
||||||
} else if (type === 'evaluation'){
|
|
||||||
return 'warning';
|
|
||||||
} else {
|
|
||||||
return 'error'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
getEffectIcon,
|
getEffectIcon,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,13 +37,18 @@
|
|||||||
@change="change('condition', ...arguments)"
|
@change="change('condition', ...arguments)"
|
||||||
/>
|
/>
|
||||||
</v-fade-transition>
|
</v-fade-transition>
|
||||||
|
<calculation-error-list :errors="model.errors" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import propertyFormMixin from '/imports/ui/properties/forms/shared/propertyFormMixin.js';
|
import propertyFormMixin from '/imports/ui/properties/forms/shared/propertyFormMixin.js';
|
||||||
|
import CalculationErrorList from '/imports/ui/properties/forms/shared/CalculationErrorList.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
components: {
|
||||||
|
CalculationErrorList,
|
||||||
|
},
|
||||||
mixins: [propertyFormMixin],
|
mixins: [propertyFormMixin],
|
||||||
computed: {
|
computed: {
|
||||||
radioSelection(){
|
radioSelection(){
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<template lang="html">
|
||||||
|
<div
|
||||||
|
v-if="errors && errors.length"
|
||||||
|
class="error-list"
|
||||||
|
>
|
||||||
|
<v-slide-x-transition
|
||||||
|
group
|
||||||
|
hide-on-leave
|
||||||
|
>
|
||||||
|
<v-alert
|
||||||
|
v-for="error in errors"
|
||||||
|
:key="error.message"
|
||||||
|
:value="true"
|
||||||
|
:icon="errorIcon(error.type)"
|
||||||
|
:color="errorColor(error.type)"
|
||||||
|
outline
|
||||||
|
>
|
||||||
|
{{ error.message }}
|
||||||
|
</v-alert>
|
||||||
|
</v-slide-x-transition>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
errors: {
|
||||||
|
type: Array,
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
errorIcon(type){
|
||||||
|
if (type === 'subsitution'){
|
||||||
|
return 'info';
|
||||||
|
} else if (type === 'evaluation'){
|
||||||
|
return 'warning';
|
||||||
|
} else {
|
||||||
|
return 'error'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
errorColor(type){
|
||||||
|
if (type === 'subsitution'){
|
||||||
|
return 'info';
|
||||||
|
} else if (type === 'evaluation'){
|
||||||
|
return 'warning';
|
||||||
|
} else {
|
||||||
|
return 'error'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="css" scoped>
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user