Added point buy form

This commit is contained in:
Stefan Zermatten
2022-08-17 13:42:47 +02:00
parent f2a1861279
commit 9b652fc133
8 changed files with 192 additions and 3 deletions

View File

@@ -27,10 +27,18 @@ let PointBuySchema = createPropertySchema({
'values': {
type: Array,
defaultValue: [],
maxCount: STORAGE_LIMITS.pointBuyRowsCount,
},
'values.$': {
type: Object,
},
'values.$._id': {
type: String,
regEx: SimpleSchema.RegEx.Id,
autoValue(){
if (!this.isSet) return Random.id();
}
},
'values.$.name': {
type: String,
optional: true,
@@ -47,6 +55,18 @@ let PointBuySchema = createPropertySchema({
type: Number,
optional: true,
},
'values.$.min': {
type: 'fieldToCompute',
optional: true,
},
'values.$.max': {
type: 'fieldToCompute',
optional: true,
},
'values.$.cost': {
type: 'fieldToCompute',
optional: true,
},
min: {
type: 'fieldToCompute',
optional: true,
@@ -74,11 +94,31 @@ const ComputedOnlyPointBuySchema = createPropertySchema({
type: 'computedOnlyField',
optional: true,
},
total: {
cost: {
type: 'computedOnlyField',
optional: true,
},
cost: {
'values': {
type: Array,
defaultValue: [],
maxCount: STORAGE_LIMITS.pointBuyRowsCount,
},
'values.$': {
type: Object,
},
'values.$.min': {
type: 'computedOnlyField',
optional: true,
},
'values.$.max': {
type: 'computedOnlyField',
optional: true,
},
'values.$.cost': {
type: 'computedOnlyField',
optional: true,
},
total: {
type: 'computedOnlyField',
optional: true,
},
@@ -87,6 +127,11 @@ const ComputedOnlyPointBuySchema = createPropertySchema({
optional: true,
removeBeforeCompute: true,
},
error: {
type: String,
optional: true,
removeBeforeCompute: true,
},
});
const ComputedPointBuySchema = new SimpleSchema()

View File

@@ -15,6 +15,7 @@ import { ComputedOnlyFeatureSchema } from '/imports/api/properties/Features.js';
import { ComputedOnlyFolderSchema } from '/imports/api/properties/Folders.js';
import { ComputedOnlyItemSchema } from '/imports/api/properties/Items.js';
import { ComputedOnlyNoteSchema } from '/imports/api/properties/Notes.js';
import { ComputedOnlyPointBuySchema } from '/imports/api/properties/PointBuys.js';
import { ComputedOnlyProficiencySchema } from '/imports/api/properties/Proficiencies.js';
import { ComputedOnlyReferenceSchema } from '/imports/api/properties/References.js';
import { ComputedOnlyRollSchema } from '/imports/api/properties/Rolls.js';
@@ -44,6 +45,7 @@ const propertySchemasIndex = {
folder: ComputedOnlyFolderSchema,
item: ComputedOnlyItemSchema,
note: ComputedOnlyNoteSchema,
pointBuy: ComputedOnlyPointBuySchema,
proficiency: ComputedOnlyProficiencySchema,
propertySlot: ComputedOnlySlotSchema,
reference: ComputedOnlyReferenceSchema,

View File

@@ -15,6 +15,7 @@ import { ComputedFeatureSchema } from '/imports/api/properties/Features.js';
import { FolderSchema } from '/imports/api/properties/Folders.js';
import { ComputedItemSchema } from '/imports/api/properties/Items.js';
import { ComputedNoteSchema } from '/imports/api/properties/Notes.js';
import { ComputedPointBuySchema } from '/imports/api/properties/PointBuys.js';
import { ProficiencySchema } from '/imports/api/properties/Proficiencies.js';
import { ReferenceSchema } from '/imports/api/properties/References.js';
import { ComputedRollSchema } from '/imports/api/properties/Rolls.js';
@@ -42,6 +43,7 @@ const propertySchemasIndex = {
feature: ComputedFeatureSchema,
folder: FolderSchema,
note: ComputedNoteSchema,
pointBuy: ComputedPointBuySchema,
proficiency: ProficiencySchema,
propertySlot: ComputedSlotSchema,
reference: ReferenceSchema,

View File

@@ -13,6 +13,7 @@ import { EffectSchema } from '/imports/api/properties/Effects.js';
import { FeatureSchema } from '/imports/api/properties/Features.js';
import { FolderSchema } from '/imports/api/properties/Folders.js';
import { NoteSchema } from '/imports/api/properties/Notes.js';
import { PointBuySchema } from '/imports/api/properties/PointBuys.js';
import { ProficiencySchema } from '/imports/api/properties/Proficiencies.js';
import { ReferenceSchema } from '/imports/api/properties/References.js';
import { RollSchema } from '/imports/api/properties/Rolls.js';
@@ -42,6 +43,7 @@ const propertySchemasIndex = {
feature: FeatureSchema,
folder: FolderSchema,
note: NoteSchema,
pointBuy: PointBuySchema,
proficiency: ProficiencySchema,
propertySlot: SlotSchema,
reference: ReferenceSchema,

View File

@@ -96,7 +96,13 @@ const PROPERTIES = Object.freeze({
icon: 'mdi-note-outline',
name: 'Note',
helpText: 'Notes about your character and their adventures',
suggestedParents: ['folder'],
suggestedParents: ['note', 'folder'],
},
pointBuy: {
icon: 'mdi-table',
name: 'Point Buy',
helpText: 'A point buy table that allows the user to select an array of values that match a given cost',
suggestedParents: [],
},
proficiency: {
icon: 'mdi-brightness-1',

View File

@@ -32,6 +32,7 @@ const STORAGE_LIMITS = Object.freeze({
tagCount: 64,
writersCount: 20,
libraryCollectionCount: 32,
pointBuyRowsCount: 32,
});
export default STORAGE_LIMITS;

View File

@@ -0,0 +1,129 @@
<template lang="html">
<div class="point-buy-form">
<v-row dense>
<text-field
ref="focusFirst"
label="Name"
:value="model.name"
:error-messages="errors.name"
@change="change('name', ...arguments)"
/>
<text-field
label="Variable name"
:value="model.variableName"
hint="Use this name in calculations to reference this point buy table"
:error-messages="errors.variableName"
@change="change('variableName', ...arguments)"
/>
<computed-field
label="Min"
hint="The minimum value for each row"
:model="model.min"
:error-messages="errors.min"
@change="change('min', ...arguments)"
/>
<computed-field
label="Max"
hint="The maximum value for each row"
:model="model.max"
:error-messages="errors.max"
@change="change('max', ...arguments)"
/>
<computed-field
label="Cost"
hint="A function of `value` that determines the cost of each row"
:model="model.cost"
:error-messages="errors.cost"
@change="change('cost', ...arguments)"
/>
<computed-field
label="Total"
hint="The total allowed cost of all rows"
:model="model.total"
:error-messages="errors.total"
@change="change('total', ...arguments)"
/>
</v-row>
<v-row
v-for="(row, i) in model.values"
:key="row._id"
dense
>
<text-field
ref="focusFirst"
label="Name"
:value="model.name"
:error-messages="errors.name"
@change="change(['values', i, 'name'], ...arguments)"
/>
<text-field
label="Variable name"
:value="model.variableName"
hint="Use this name to reference this row of the table: tableVariableName.thisVariableName"
:error-messages="errors.variableName"
@change="change(['values', i, 'variableName'], ...arguments)"
/>
<v-btn
icon
@click="$emit('pull', {path: ['values', i]})"
>
<v-icon>mdi-delete</v-icon>
</v-btn>
</v-row>
<v-btn
icon
outlined
:loading="addRowLoading"
:disabled="rowsFull"
@click="addRow"
>
<v-icon>
mdi-plus
</v-icon>
</v-btn>
<form-section
v-if="$slots.children"
name="Children"
standalone
>
<slot name="children" />
</form-section>
</div>
</template>
<script lang="js">
import attributeListMixin from '/imports/ui/properties/forms/shared/lists/attributeListMixin.js';
import propertyFormMixin from '/imports/ui/properties/forms/shared/propertyFormMixin.js';
import { PointBuySchema } from '/imports/api/properties/PointBuys.js';
export default {
mixins: [propertyFormMixin, attributeListMixin],
data() {
return {
addRowLoading: false,
};
},
computed: {
rowsFull(){
if (!this.model.values) return false;
let maxCount = PointBuySchema.get('values', 'maxCount');
return this.model.values.length >= maxCount;
},
},
methods: {
acknowledgeAddResult(){
this.addRowLoading = false;
},
addRow(){
this.addRowLoading = true;
this.$emit('push', {
path: ['values'],
value: {
_id: Random.id(),
},
ack: this.acknowledgeAddResult,
});
},
},
}
</script>

View File

@@ -14,6 +14,7 @@ const FeatureForm = () => import('/imports/ui/properties/forms/FeatureForm.vue')
const FolderForm = () => import('/imports/ui/properties/forms/FolderForm.vue');
const ItemForm = () => import('/imports/ui/properties/forms/ItemForm.vue');
const NoteForm = () => import('/imports/ui/properties/forms/NoteForm.vue');
const PointBuyForm = () => import('/imports/ui/properties/forms/PointBuyForm.vue');
const ProficiencyForm = () => import('/imports/ui/properties/forms/ProficiencyForm.vue');
const ReferenceForm = () => import('/imports/ui/properties/forms/ReferenceForm.vue');
const RollForm = () => import('/imports/ui/properties/forms/RollForm.vue');
@@ -43,6 +44,7 @@ export default {
folder: FolderForm,
item: ItemForm,
note: NoteForm,
pointBuy: PointBuyForm,
proficiency: ProficiencyForm,
propertySlot: SlotForm,
reference: ReferenceForm,