Fixed computations throwing errors when not provided with context
This commit is contained in:
@@ -51,7 +51,6 @@ function substituteAccessors(scope){
|
|||||||
try {
|
try {
|
||||||
return evaluateAccessor(node, scope);
|
return evaluateAccessor(node, scope);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(typeof e);
|
|
||||||
return replaceAccessorWithSymbol(node);
|
return replaceAccessorWithSymbol(node);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,23 +1,27 @@
|
|||||||
<template lang="html">
|
<template lang="html">
|
||||||
<div
|
<div
|
||||||
v-html="computedValue"
|
|
||||||
class="computed"
|
class="computed"
|
||||||
:class="expectNumber && 'symbols-are-errors'"
|
:class="{
|
||||||
|
'symbols-are-errors': expectNumber && scope,
|
||||||
|
'code': errors.length,
|
||||||
|
}"
|
||||||
|
v-html="computedValue"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import evaluateString from '/imports/api/creature/computation/afterComputation/evaluateString.js';
|
import evaluateString from '/imports/api/creature/computation/afterComputation/evaluateString.js';
|
||||||
import numberToSignedString from '/imports/ui/utility/numberToSignedString.js';
|
import numberToSignedString from '/imports/ui/utility/numberToSignedString.js';
|
||||||
import { isFinite } from 'lodash';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
value: {
|
value: {
|
||||||
type: String,
|
type: String,
|
||||||
|
default: '',
|
||||||
},
|
},
|
||||||
scope: {
|
scope: {
|
||||||
type: Object,
|
type: Object,
|
||||||
|
default: undefined,
|
||||||
},
|
},
|
||||||
expectNumber: {
|
expectNumber: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@@ -27,14 +31,30 @@ export default {
|
|||||||
type: Boolean
|
type: Boolean
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
data(){return {
|
||||||
computedValue(){
|
errors: false,
|
||||||
|
computedValue: '',
|
||||||
|
}},
|
||||||
|
watch: {
|
||||||
|
value(){
|
||||||
|
this.recalculate();
|
||||||
|
},
|
||||||
|
scope(){
|
||||||
|
this.recalculate();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
mounted(){
|
||||||
|
this.recalculate();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
recalculate(){
|
||||||
if (!this.value) return;
|
if (!this.value) return;
|
||||||
let {result, errors} = evaluateString(this.value, this.scope);
|
let {result, errors} = evaluateString(this.value, this.scope);
|
||||||
if (this.signed){
|
if (this.signed){
|
||||||
result = numberToSignedString(result);
|
result = numberToSignedString(result);
|
||||||
}
|
}
|
||||||
return result;
|
this.computedValue = result;
|
||||||
|
this.errors = errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,4 +64,10 @@ export default {
|
|||||||
.computed.symbols-are-errors .math-symbol {
|
.computed.symbols-are-errors .math-symbol {
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
|
.computed.code {
|
||||||
|
font-family: monospace,monospace;
|
||||||
|
}
|
||||||
|
.computed .math-binary-operator {
|
||||||
|
margin: 0 6px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -8,10 +8,11 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Computed from '/imports/ui/components/computation/Computed.vue';
|
import Computed from '/imports/ui/components/computation/Computed.vue';
|
||||||
import Creatures from '/imports/api/creature/Creatures.js';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
inject: ['computationContext'],
|
inject: {
|
||||||
|
computationContext: { default: {} }
|
||||||
|
},
|
||||||
components: {
|
components: {
|
||||||
Computed,
|
Computed,
|
||||||
},
|
},
|
||||||
@@ -21,14 +22,10 @@ export default {
|
|||||||
default: undefined,
|
default: undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
meteor: {
|
|
||||||
creature(){
|
|
||||||
return Creatures.findOne(this.creatureId);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
scope(){
|
scope(){
|
||||||
return this.computationContext.creature && this.computationContext.creature.variables;
|
return this.computationContext.creature &&
|
||||||
|
this.computationContext.creature.variables;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
{{ model.value }}
|
{{ model.value }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="model.mod !== undefined">
|
<div v-if="model.modifier !== undefined">
|
||||||
{{ numberToSignedString(model.mod) }}
|
{{ numberToSignedString(model.modifier) }}
|
||||||
</div>
|
</div>
|
||||||
<property-name :value="model.name" />
|
<property-name :value="model.name" />
|
||||||
<property-variable-name :value="model.variableName" />
|
<property-variable-name :value="model.variableName" />
|
||||||
@@ -24,13 +24,21 @@
|
|||||||
<p v-if="reset && model.attributeType !== 'hitDice'">
|
<p v-if="reset && model.attributeType !== 'hitDice'">
|
||||||
{{ reset }}
|
{{ reset }}
|
||||||
</p>
|
</p>
|
||||||
|
<property-description :value="model.description" />
|
||||||
|
|
||||||
<effect-viewer
|
<effect-viewer
|
||||||
|
v-if="computationContext.creature"
|
||||||
:model="{
|
:model="{
|
||||||
|
name: 'Attribute base value',
|
||||||
result: model.baseValue,
|
result: model.baseValue,
|
||||||
operation: 'base'
|
operation: 'base'
|
||||||
}"
|
}"
|
||||||
/>
|
/>
|
||||||
<property-description :value="model.description" />
|
<effect-viewer
|
||||||
|
v-for="effect in effects"
|
||||||
|
:key="effect._id"
|
||||||
|
:model="effect"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -38,8 +46,12 @@
|
|||||||
import propertyViewerMixin from '/imports/ui/properties/viewers/shared/propertyViewerMixin.js'
|
import propertyViewerMixin from '/imports/ui/properties/viewers/shared/propertyViewerMixin.js'
|
||||||
import numberToSignedString from '/imports/ui/utility/numberToSignedString.js';
|
import numberToSignedString from '/imports/ui/utility/numberToSignedString.js';
|
||||||
import EffectViewer from '/imports/ui/properties/viewers/EffectViewer.vue';
|
import EffectViewer from '/imports/ui/properties/viewers/EffectViewer.vue';
|
||||||
|
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
inject: {
|
||||||
|
computationContext: { default: {} }
|
||||||
|
},
|
||||||
components: {
|
components: {
|
||||||
EffectViewer,
|
EffectViewer,
|
||||||
},
|
},
|
||||||
@@ -61,7 +73,21 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
numberToSignedString,
|
numberToSignedString,
|
||||||
}
|
},
|
||||||
|
meteor: {
|
||||||
|
effects(){
|
||||||
|
if (this.computationContext.creature){
|
||||||
|
let creatureId = this.computationContext.creature._id;
|
||||||
|
return CreatureProperties.find({
|
||||||
|
'ancestors.id': creatureId,
|
||||||
|
'stats': this.model.variableName,
|
||||||
|
removed: {$ne: true},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<template lang="html">
|
<template lang="html">
|
||||||
<div class="effect-viewer">
|
<div class="effect-viewer">
|
||||||
<property-name
|
|
||||||
v-if="model.name"
|
|
||||||
:value="model.name"
|
|
||||||
/>
|
|
||||||
<div class="layout row align-center wrap">
|
<div class="layout row align-center wrap">
|
||||||
|
<property-name
|
||||||
|
v-if="model.name"
|
||||||
|
:value="model.name"
|
||||||
|
/>
|
||||||
<div class="headline">
|
<div class="headline">
|
||||||
<code
|
<code
|
||||||
v-for="stat in model.stats"
|
v-for="stat in model.stats"
|
||||||
|
|||||||
Reference in New Issue
Block a user