Added roll form

This commit is contained in:
Stefan Zermatten
2019-07-23 12:02:19 +02:00
parent 1bfb48c672
commit 812a6679d5
4 changed files with 183 additions and 18 deletions

View File

@@ -51,10 +51,10 @@ let RollChildrenSchema = new SimpleSchema({
* child rolls are applied
*/
let RollSchema = new SimpleSchema({
// Apply this only if the parent roll missed
// i.e. roll failed or target suceeded on their save
onMiss: {
type: Boolean,
// The roll made against the target value. A calculation that resolves to a
// number or a roll. If it is a number, it will be added to a d20 roll
roll: {
type: String,
optional: true,
},
// The target number to meet or exceed
@@ -62,13 +62,20 @@ let RollSchema = new SimpleSchema({
type: String,
optional: true,
},
// Swap who wins ties
invertTies: {
// Is this roll a saving throw
rollType: {
type: String,
defaultValue: 'roll',
allowedValues: ['roll', 'savingThrow'],
},
// Apply this only if the parent roll missed
// i.e. roll failed or target suceeded on their save
onMiss: {
type: Boolean,
optional: true,
},
// Is this roll a saving throw
isSavingThrow: {
// Swap who wins ties
invertTies: {
type: Boolean,
optional: true,
},
@@ -81,15 +88,15 @@ let RollSchema = new SimpleSchema({
'tags.$': {
type: String,
},
// The roll made against the target value. A calculation that resolves to a
// number or a roll. If it is a number, it will be added to a d20 roll
roll: {
type: String,
optional: true,
},
// The buffs and adjustments to apply based on the outcome of the roll
hit: RollChildrenSchema,
miss: RollChildrenSchema,
hit: {
type: RollChildrenSchema,
defaultValue: {},
},
miss: {
type: RollChildrenSchema,
defaultValue: {},
},
});
Rolls.attachSchema(RollSchema);

View File

@@ -47,7 +47,7 @@
class="no-flex"
:value="model.decimal"
:error-messages="errors.decimal"
@change="e => $emit('change', $emit('change', {path: ['decimal'], value: !!e, ack}))"
@change="e => $emit('change', {path: ['decimal'], value: !!e})"
/>
<div class="layout row justify-center" style="align-self: stretch;">
<text-field
@@ -58,7 +58,7 @@
hint="The attribute's final value is reduced by this amount"
:value="model.damage"
@change="(value, ack) => $emit('change', {path: ['damage'], value, ack})"
:error-messages="errors.adjustment"
:error-messages="errors.damage"
:debounce-time="debounceTime"
/>
</div>

View File

@@ -0,0 +1,156 @@
<template lang="html">
<div class="roll-form">
<text-field
label="Roll"
hint="The roll will be calculated using the rolling character's stats"
:value="model.roll"
@change="(value, ack) => $emit('change', {path: ['roll'], value, ack})"
:error-messages="errors.roll"
:debounce-time="debounceTime"
/>
<text-field
label="Target number"
hint="The target number or stat to meet or exceed, calculated from the target's stats"
:value="model.targetNumber"
@change="(value, ack) => $emit('change', {path: ['targetNumber'], value, ack})"
:error-messages="errors.targetNumber"
:debounce-time="debounceTime"
/>
<smart-select
label="Type"
:items="rollTypes"
:value="model.rollType"
:error-messages="errors.rollType"
:menu-props="{auto: true, lazy: true}"
@change="(value, ack) => $emit('change', {path: ['rollType'], value, ack})"
:debounce-time="debounceTime"
/>
<v-combobox
label="Tags"
multiple
chips
deletable-chips
box
:value="model.tags"
@change="(value) => $emit('change', {path: ['tags'], value})"
/>
<form-sections>
<form-section name="Advanced">
<v-switch
label="Only roll if the parent roll misses"
:value="model.onMiss"
:error-messages="errors.onMiss"
@change="e => $emit('change', {path: ['onMiss'], value: !!e})"
/>
<v-switch
label="Swap who wins ties"
:value="model.invertTies"
:error-messages="errors.invertTies"
@change="e => $emit('change', {path: ['invertTies'], value: !!e})"
/>
</form-section>
<form-section name="Damage and Adjustments on Hit">
<div class="caption">
Adjustments can be used to automatically spend resources or deal
damage when taking an roll.
These apply when a roll suceeds.
</div>
<adjustment-list-form
:model="model.hit.adjustments"
@change="({path, value, ack}) => $emit('change', {path: ['hit', 'adjustments', ...path], value, ack})"
@push="({path, value, ack}) => $emit('push', {path: ['hit', 'adjustments', ...path], value, ack})"
@pull="({path, ack}) => $emit('pull', {path: ['hit', 'adjustments', ...path], ack})"
/>
</form-section>
<form-section name="Buffs on Hit">
<div class="caption">
Buffs apply temporary effects to characters when the roll succeeds.
</div>
<buff-list-form
:model="model.hit.buffs"
:stored="stored"
@change="({path, value, ack}) => $emit('change', {path: ['hit', 'buffs', ...path], value, ack})"
@push="({path, value, ack}) => $emit('push', {path: ['hit', 'buffs', ...path], value, ack})"
@pull="({path, ack}) => $emit('pull', {path: ['hit', 'buffs', ...path], ack})"
/>
</form-section>
<form-section name="Damage and Adjustments on Miss">
<div class="caption">
Adjustments can be used to automatically spend resources or deal
damage when taking an roll.
These apply when a roll fails.
</div>
<adjustment-list-form
:model="model.miss.adjustments"
@change="({path, value, ack}) => $emit('change', {path: ['miss', 'adjustments', ...path], value, ack})"
@push="({path, value, ack}) => $emit('push', {path: ['miss', 'adjustments', ...path], value, ack})"
@pull="({path, ack}) => $emit('pull', {path: ['miss', 'adjustments', ...path], ack})"
/>
</form-section>
<form-section name="Buffs on Miss">
<div class="caption">
Buffs apply temporary effects to characters when the roll fails.
</div>
<buff-list-form
:model="model.miss.buffs"
:stored="stored"
@change="({path, value, ack}) => $emit('change', {path: ['miss', 'buffs', ...path], value, ack})"
@push="({path, value, ack}) => $emit('push', {path: ['miss', 'buffs', ...path], value, ack})"
@pull="({path, ack}) => $emit('pull', {path: ['miss', 'buffs', ...path], ack})"
/>
</form-section>
</form-sections>
</div>
</template>
<script>
import FormSection, {FormSections} from '/imports/ui/forms/components/FormSection.vue';
import AdjustmentListForm from '/imports/ui/forms/AdjustmentListForm.vue';
import BuffListForm from '/imports/ui/forms/BuffListForm.vue';
export default {
components: {
FormSection,
FormSections,
AdjustmentListForm,
BuffListForm,
},
props: {
stored: {
type: Boolean,
},
model: {
type: Object,
default: () => ({}),
},
errors: {
type: Object,
default: () => ({}),
},
debounceTime: Number,
},
data(){return {
rollTypes: [
{
text: 'Roll',
value: 'roll',
}, {
text: 'Saving Throw',
value: 'savingThrow',
},
],
};},
};
</script>
<style lang="css" scoped>
.no-flex {
flex: initial;
}
.layout.row.wrap {
margin-right: -8px;
}
.layout.row.wrap > *{
margin-right: 8px;
}
</style>

View File

@@ -9,6 +9,7 @@ import FeatureForm from '/imports/ui/forms/FeatureForm.vue';
import FolderForm from '/imports/ui/forms/FolderForm.vue';
import NoteForm from '/imports/ui/forms/NoteForm.vue';
import ProficiencyForm from '/imports/ui/forms/ProficiencyForm.vue';
import RollForm from '/imports/ui/forms/RollForm.vue';
export default {
action: ActionForm,
@@ -22,4 +23,5 @@ export default {
folder: FolderForm,
note: NoteForm,
proficiency: ProficiencyForm,
roll: RollForm,
};