Added UI backend that can do computations with context
This commit is contained in:
35
app/imports/ui/components/computation/Computed.vue
Normal file
35
app/imports/ui/components/computation/Computed.vue
Normal 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>
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user