Added edit tab to base dialogs, added edit screen to attribute dialog

This commit is contained in:
Stefan Zermatten
2019-02-18 13:41:21 +02:00
parent 5d45788521
commit d30ee06e33
7 changed files with 57 additions and 30 deletions

View File

@@ -18,12 +18,12 @@ const getRacialBonusEffect = function(charId, attribute, bonus){
name: "Race Bonus", name: "Race Bonus",
stat: attribute, stat: attribute,
operation: "add", operation: "add",
calculation: bonus, calculation: bonus.toString(),
enabled: true, enabled: true,
parent: { parent: {
collection: "Creatures", collection: "Creatures",
id: charId, id: charId,
group: "racial", group: "race",
}, },
charId: charId, charId: charId,
}; };

View File

@@ -91,6 +91,7 @@ let updateAttributeSchema = pickKeysAsOptional(attributeSchema, [
'type', 'type',
'baseValue', 'baseValue',
'decimal', 'decimal',
'adjustment',
'reset', 'reset',
'resetMultiplier', 'resetMultiplier',
'color', 'color',
@@ -109,13 +110,18 @@ const updateAttribute = new ValidatedMethod({
}).validator(), }).validator(),
run({_id, update}) { run({_id, update}) {
let currentAttribute = Attributes.findOne(_id); let currentAttribute = Attributes.findOne(_id, {fields: {value: 1, charId: 1}});
if (!currentAttribute){ if (!currentAttribute){
throw new Meteor.Error("Attributes.methods.update.denied", throw new Meteor.Error("Attributes.methods.update.denied",
`No attributes exist with the id: ${_id}`); `No attributes exist with the id: ${_id}`);
} }
let charId = currentAttribute.charId; let charId = currentAttribute.charId;
if (canEditCreature(charId, this.userId)){ if (canEditCreature(charId, this.userId)){
if (typeof update.adjustment === 'number'){
let val = currentAttribute.value;
if (update.adjustment < -val) update.adjustment = -val;
if (update.adjustment > 0) update.adjustment = 0;
}
Attributes.update(_id, {$set: update}); Attributes.update(_id, {$set: update});
recomputeCreatureById(charId); recomputeCreatureById(charId);
} }

View File

@@ -62,7 +62,7 @@
}, },
data(){return { data(){return {
theme, theme,
tab: 1, tab: 0,
}}, }},
methods: { methods: {
...mapMutations([ ...mapMutations([

View File

@@ -31,7 +31,7 @@
/> />
</div> </div>
<div v-for="modifier in modifiers" class="modifier"> <div v-for="modifier in modifiers" class="modifier" :key="modifier._id">
<attribute-card modifier <attribute-card modifier
v-bind="modifier" v-bind="modifier"
:id="`${_uid}-${modifier._id}`" :id="`${_uid}-${modifier._id}`"
@@ -44,11 +44,11 @@
<v-list> <v-list>
<v-subheader>Hit Dice</v-subheader> <v-subheader>Hit Dice</v-subheader>
<template v-for="(hitDie, index) in hitDice"> <template v-for="(hitDie, index) in hitDice">
<v-divider v-if="index !== 0"/> <v-divider v-if="index !== 0" :key="hitDice._id + 'divider'"/>
<hit-dice-list-tile <hit-dice-list-tile
v-bind="hitDie" v-bind="hitDie"
:key="hitDie._id"
:id="`${_uid}-${hitDie._id}`" :id="`${_uid}-${hitDie._id}`"
:key="hitDice._id"
@click="clickAttribute({elementId: `${_uid}-${hitDie._id}`, _id: hitDie._id})" @click="clickAttribute({elementId: `${_uid}-${hitDie._id}`, _id: hitDie._id})"
@change="e => hitDiceChange(hitDie._id, e)" @change="e => hitDiceChange(hitDie._id, e)"
/> />

View File

@@ -3,27 +3,32 @@
<div slot="toolbar"> <div slot="toolbar">
{{name}} {{name}}
</div> </div>
<v-layout align-center column v-if="type === 'ability'"> <div>
<div class="display-3 mod"> <v-layout align-center column v-if="type === 'ability'">
{{numberToSignedString(mod)}} <div class="display-3 mod">
{{numberToSignedString(mod)}}
</div>
<div class="display-1 ability-value">
{{value}}
</div>
</v-layout>
<div class="display-3 attribute-value" v-else-if="type === 'healthBar'">
{{value+adjustment}} / {{value}}
</div> </div>
<div class="display-1 ability-value"> <div class="display-3 attribute-value" v-else-if="type === 'modifier'">
{{numberToSignedString(value)}}
</div>
<div class="display-3 attribute-value" v-else>
{{value}} {{value}}
</div> </div>
</v-layout> <attribute-effect-list v-if="attribueBaseEffect" :effects="[attribueBaseEffect]"/>
<div class="display-3 attribute-value" v-else-if="type === 'healthBar'"> <div v-if="effects && effects.length">
{{value+adjustment}} / {{value}} <h6 class="title">Effects</h6>
<attribute-effect-list :effects="effects" @click="clickedEffect"/>
</div>
</div> </div>
<div class="display-3 attribute-value" v-else-if="type === 'modifier'"> <div slot="edit">
{{numberToSignedString(value)}} <attribute-edit :attribute="$props" @change="(update, ack) => $emit('change', update, ack)"/>
</div>
<div class="display-3 attribute-value" v-else>
{{value}}
</div>
<attribute-effect-list v-if="attribueBaseEffect" :effects="[attribueBaseEffect]"/>
<div v-if="effects && effects.length">
<h6 class="title">Effects</h6>
<attribute-effect-list :effects="effects" @click="clickedEffect"/>
</div> </div>
</dialog-base> </dialog-base>
</template> </template>
@@ -32,15 +37,24 @@
import store from "/imports/ui/vuexStore.js"; import store from "/imports/ui/vuexStore.js";
import DialogBase from "/imports/ui/dialogStack/DialogBase.vue"; import DialogBase from "/imports/ui/dialogStack/DialogBase.vue";
import AttributeEffectList from '/imports/ui/components/AttributeEffectList.vue'; import AttributeEffectList from '/imports/ui/components/AttributeEffectList.vue';
import AttributeEdit from '/imports/ui/components/AttributeEdit.vue';
import numberToSignedString from '/imports/ui/utility/numberToSignedString.js'; import numberToSignedString from '/imports/ui/utility/numberToSignedString.js';
export default { export default {
props: { props: {
charId: String,
name: String, name: String,
variableName: String,
order: Number,
type: String, type: String,
baseValue: Number,
value: Number, value: Number,
mod: Number, mod: Number,
baseValue: Number, adjustment: Number,
decimal: Boolean,
reset: String,
resetMultiplier: Number,
color: String,
adjustment: {type: Number, default: 0}, adjustment: {type: Number, default: 0},
effects: {type: Array, default: () => []}, effects: {type: Array, default: () => []},
}, },
@@ -66,6 +80,7 @@
components: { components: {
DialogBase, DialogBase,
AttributeEffectList, AttributeEffectList,
AttributeEdit,
}, },
}; };
</script> </script>

View File

@@ -2,13 +2,14 @@
<attribute-dialog <attribute-dialog
v-bind="attribute" v-bind="attribute"
:effects="effects" :effects="effects"
v-on="{clickedEffect}" v-on="{clickedEffect, change}"
/> />
</template> </template>
<script> <script>
import AttributeDialog from '/imports/ui/components/AttributeDialog.vue'; import AttributeDialog from '/imports/ui/components/AttributeDialog.vue';
import Attributes from '/imports/api/creature/properties/Attributes.js'; import Attributes from '/imports/api/creature/properties/Attributes.js';
import { updateAttribute, adjustAttribute } from '/imports/api/creature/properties/Attributes.js';
export default { export default {
components: { components: {
AttributeDialog, AttributeDialog,
@@ -36,7 +37,12 @@
methods: { methods: {
clickedEffect(e){ clickedEffect(e){
console.log(e); console.log(e);
} },
change(update, ack){
updateAttribute.call({_id: this._id, update}, error => {
ack(error);
});
},
} }
}; };
</script> </script>

View File

@@ -15,7 +15,7 @@
label="Base Value" label="Base Value"
type="number" type="number"
:value="attribute.baseValue" :value="attribute.baseValue"
@change="(baseValue, ack) => $emit('change', {baseValue}, ack)" @change="(baseValue, ack) => $emit('change', {baseValue: +baseValue}, ack)"
hint="This is the value of the attribute before effects are applied" hint="This is the value of the attribute before effects are applied"
/> />
<text-field <text-field
@@ -34,7 +34,7 @@
<v-switch <v-switch
label="Allow decimal values" label="Allow decimal values"
:value="attribute.decimal" :value="attribute.decimal"
@change="e => $emit('change', {decimal: e})" @change="e => $emit('change', {decimal: !!e})"
/> />
<smart-select <smart-select
label="Reset" label="Reset"
@@ -49,7 +49,7 @@
label="Reset Multiplier" label="Reset Multiplier"
type="number" type="number"
:value="attribute.resetMultiplier" :value="attribute.resetMultiplier"
@change="(resetMultiplier, ack) => $emit('change', {resetMultiplier}, ack)" @change="(resetMultiplier, ack) => $emit('change', {resetMultiplier: +resetMultiplier}, ack)"
hint="Some attributes, like hit dice, only reset by half their total on a long rest" hint="Some attributes, like hit dice, only reset by half their total on a long rest"
/> />
</div> </div>