Added UI backend that can do computations with context

This commit is contained in:
Thaum Rystra
2020-04-23 14:26:05 +02:00
parent 7416101a34
commit 95bfcd79c9
16 changed files with 294 additions and 40 deletions

View File

@@ -0,0 +1,35 @@
<template lang="html">
<div v-html="computedValue" class="computed" :class="expectNumber && 'symbols-are-errors'"/>
</template>
<script>
import evaluateString from '/imports/api/creature/computation/afterComputation/evaluateString.js';
export default {
props: {
value: {
type: String,
},
scope: {
type: Object,
},
expectNumber: {
type: Boolean,
default: true,
}
},
computed: {
computedValue(){
if (!this.value) return;
let {result, errors} = evaluateString(this.value, this.scope);
return result;
}
}
}
</script>
<style lang="css">
.computed.symbols-are-errors .math-symbol {
color: red;
}
</style>

View File

@@ -0,0 +1,29 @@
<template lang="html">
<computed :value="value" :scope="scope"/>
</template>
<script>
import Computed from '/imports/ui/components/computation/Computed.vue';
export default {
inject: ['computationContext'],
components: {
Computed,
},
props: {
value: {
type: String,
},
},
meteor: {
creature(){
return Creatures.findOne(this.creatureId);
},
},
computed: {
scope(){
return this.computationContext.creature && this.computationContext.creature.variables;
}
}
}
</script>