Hit dice now explicitly set their size

This commit is contained in:
Thaum Rystra
2020-04-28 17:12:22 +02:00
parent eae35062d0
commit 966fcc449d
5 changed files with 142 additions and 100 deletions

View File

@@ -32,6 +32,12 @@ let AttributeSchema = new SimpleSchema({
],
defaultValue: 'stat',
index: 1,
},
// For type hitDice, the size needs to be stored separately
hitDiceSize: {
type: String,
allowedValues: ['d4', 'd6', 'd8', 'd10', 'd12', 'd20'],
optional: true,
},
// The starting value, before effects
baseValueCalculation: {

View File

@@ -73,7 +73,7 @@
/>
<hit-dice-list-tile
:key="hitDie._id"
v-bind="hitDie"
:model="hitDie"
:data-id="hitDie._id"
@click="clickProperty({_id: hitDie._id})"
@change="e => incrementChange(hitDie._id, e)"
@@ -252,32 +252,7 @@
return getNonZeroAttributeOfType(this.creatureId, 'spellSlot');
},
hitDice(){
return CreatureProperties.find({
'ancestors.id': this.creatureId,
type: 'attribute',
attributeType: 'hitDice',
value: {$ne: 0},
}, {
sort: {order: 1},
}).map(hd => {
let diceMatch = hd.variableName.match(/d(\d+)/);
let dice = diceMatch && +diceMatch[1];
let con = CreatureProperties.findOne({
'ancestors.id': this.creatureId,
type: 'attribute',
variableName: 'constitution',
removed: {$ne: true},
});
let conMod = con && con.mod;
return {
_id: hd._id,
dice,
conMod,
key: hd._id,
maxValue: hd.value,
value: hd.value - (hd.damage || 0),
}
});
return getNonZeroAttributeOfType(this.creatureId, 'hitDice');
},
checks(){
return CreatureProperties.find({

View File

@@ -1,58 +1,89 @@
<template lang="html">
<v-list-tile class="hit-dice-list-tile" :class="{hover}">
<v-list-tile
class="hit-dice-list-tile"
:class="{hover}"
>
<v-list-tile-action class="mr-4">
<v-layout
row
align-center
class="left"
>
<v-layout
column
class="buttons"
justify-center
>
<v-btn
icon
small
:disabled="currentValue >= model.value"
@click="increment(1)"
>
<v-icon>arrow_drop_up</v-icon>
</v-btn>
<v-btn
icon
small
:disabled="currentValue <= 0"
@click="increment(-1)"
>
<v-icon>arrow_drop_down</v-icon>
</v-btn>
</v-layout>
<v-list-tile-action class="mr-4">
<v-layout
row
align-end
>
<div class="display-1">
{{ currentValue }}
</div>
<div class="title max-value ml-2">
/{{ model.value }}
</div>
</v-layout>
</v-layout>
</v-list-tile-action>
<v-layout row align-center class="left">
<v-layout column class="buttons" justify-center>
<v-btn icon small :disabled="value >= maxValue" @click="increment(1)">
<v-icon>arrow_drop_up</v-icon>
</v-btn>
<v-btn icon small :disabled="value <= 0" @click="increment(-1)">
<v-icon>arrow_drop_down</v-icon>
</v-btn>
</v-layout>
<v-layout row align-end>
<div class="display-1">
{{value}}
</div>
<div class="title max-value ml-2">
/{{maxValue}}
</div>
</v-layout>
</v-layout>
</v-list-tile-action>
<v-list-tile-content
class="content"
@click="click"
@mouseover="hover = true"
@mouseleave="hover = false"
>
<v-list-tile-title>
d{{dice}} {{signed(conMod)}}
</v-list-tile-title>
</v-list-tile-content>
</v-list-tile>
<v-list-tile-content
class="content"
@click="click"
@mouseover="hover = true"
@mouseleave="hover = false"
>
<v-list-tile-title>
{{ model.hitDiceSize }} <computed
class="d-inline"
signed
value="constitution.modifier"
/>
</v-list-tile-title>
</v-list-tile-content>
</v-list-tile>
</template>
<script>
import numberToSignedString from '/imports/ui/utility/numberToSignedString.js';
import ComputedForCreature from '/imports/ui/components/computation/ComputedForCreature.vue';
export default {
components: {
Computed: ComputedForCreature,
},
props: {
model: {
type: Object,
required: true,
}
},
data(){ return{
hover: false,
}},
props: {
dice: Number,
value: Number,
maxValue: Number,
conMod: Number,
},
computed: {
currentValue(){
return this.model.value - (this.model.damage || 0);
}
},
methods: {
signed: numberToSignedString,
click(e){
this.$emit('click', e);
},

View File

@@ -39,6 +39,16 @@
:debounce-time="debounceTime"
@change="(value, ack) => $emit('change', {path: ['attributeType'], value, ack})"
/>
<smart-select
v-if="model.attributeType === 'hitDice'"
label="Hit Dice Size"
:items="['d4', 'd6', 'd8', 'd10', 'd12', 'd20']"
:value="model.hitDiceSize"
:error-messages="errors.hitDiceSize"
:menu-props="{auto: true, lazy: true}"
:debounce-time="debounceTime"
@change="(value, ack) => $emit('change', {path: ['hitDiceSize'], value, ack})"
/>
<text-area
label="Description"
:value="model.description"
@@ -52,6 +62,7 @@
>
<div class="layout column align-center">
<v-switch
v-if="model.attributeType !== 'hitDice'"
label="Allow decimal values"
class="no-flex"
:input-value="model.decimal"
@@ -77,6 +88,7 @@
</div>
<div class="layout row wrap">
<smart-select
v-if="model.attributeType !== 'hitDice'"
label="Reset"
clearable
style="flex-basis: 300px;"
@@ -163,6 +175,15 @@
});
return data;
},
watch: {
'model.attributeType': function(newVal, oldVal){
if (newVal === 'hitDice' && !this.model.hitDiceSize){
this.$emit('change', {path: ['hitDiceSize'], value: 'd8'});
} else if (oldVal === 'hitDice'){
this.$emit('change', {path: ['hitDiceSize'], value: undefined});
}
},
},
};
</script>

View File

@@ -1,29 +1,37 @@
<template lang="html">
<div class="attribute-viewer">
<div v-if="model.value !== undefined">
<div class="display-3" v-if="model.damage !== undefined">
{{model.value - model.damage}} / {{model.value}}
</div>
<div v-else>
{{model.value}}
</div>
</div>
<div v-if="model.mod !== undefined">
{{numberToSignedString(model.mod)}}
</div>
<property-name :value="model.name"/>
<property-variable-name :value="model.variableName"/>
<p v-if="reset">
{{reset}}
</p>
<effect-viewer
:model="{
result: model.baseValue,
operation: 'base'
}"
/>
<property-description :value="model.description"/>
</div>
<div class="attribute-viewer">
<div v-if="model.value !== undefined">
<div
v-if="model.damage !== undefined"
class="display-3"
>
{{ model.value - model.damage }} / {{ model.value }}
</div>
<div v-else>
{{ model.value }}
</div>
</div>
<div v-if="model.mod !== undefined">
{{ numberToSignedString(model.mod) }}
</div>
<property-name :value="model.name" />
<property-variable-name :value="model.variableName" />
<property-field
v-if="model.attributeType === 'hitDice' && model.hitDiceSize"
name="Hit dice size"
:value="model.hitDiceSize"
/>
<p v-if="reset && model.attributeType !== 'hitDice'">
{{ reset }}
</p>
<effect-viewer
:model="{
result: model.baseValue,
operation: 'base'
}"
/>
<property-description :value="model.description" />
</div>
</template>
<script>
@@ -32,13 +40,10 @@
import EffectViewer from '/imports/ui/properties/viewers/EffectViewer.vue';
export default {
mixins: [propertyViewerMixin],
components: {
EffectViewer,
},
methods: {
numberToSignedString,
},
mixins: [propertyViewerMixin],
computed: {
reset(){
let reset = this.model.reset
@@ -51,7 +56,11 @@
this.model.resetMultiplier && ' x' + this.model.resetMultiplier
} on a long rest`;
}
return undefined;
}
},
methods: {
numberToSignedString,
}
}
</script>