Groundwork for default libraries and slots

This commit is contained in:
Stefan Zermatten
2019-11-13 11:54:27 +02:00
parent ae0b060f01
commit eabc0aa32e
12 changed files with 116 additions and 23 deletions

View File

@@ -18,6 +18,13 @@ let CreaturePropertySchema = new SimpleSchema({
type: String, type: String,
allowedValues: Object.keys(propertySchemasIndex), allowedValues: Object.keys(propertySchemasIndex),
}, },
tags: {
type: Array,
defaultValue: [],
},
'tags.$': {
type: String,
},
}); });
for (let key in propertySchemasIndex){ for (let key in propertySchemasIndex){

View File

@@ -21,7 +21,7 @@ const insertCreature = new ValidatedMethod({
validate: null, validate: null,
run(characterFormData) { run() {
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error("Creatures.methods.insert.denied", throw new Meteor.Error("Creatures.methods.insert.denied",
"You need to be logged in to insert a creature"); "You need to be logged in to insert a creature");
@@ -29,18 +29,9 @@ const insertCreature = new ValidatedMethod({
// Create the creature document // Create the creature document
let charId = Creatures.insert({ let charId = Creatures.insert({
name: characterFormData.name,
owner: this.userId, owner: this.userId,
alignment: characterFormData.alignment,
gender: characterFormData.gender,
race: characterFormData.race,
}); });
this.unblock(); this.unblock();
if (Meteor.isServer){
//Add all the required attributes to it
let docs = getDefaultCharacterDocs(charId, characterFormData);
addDefaultDocs(docs);
}
return charId; return charId;
}, },

View File

@@ -17,6 +17,10 @@ let LibrarySchema = new SimpleSchema({
name: { name: {
type: String, type: String,
}, },
isDefault: {
type: Boolean,
optional: true,
},
}); });
LibrarySchema.extend(SharingSchema); LibrarySchema.extend(SharingSchema);
@@ -30,11 +34,30 @@ const insertLibrary = new ValidatedMethod({
mixins: [ mixins: [
simpleSchemaMixin, simpleSchemaMixin,
], ],
schema: LibrarySchema.omit('owner'), schema: LibrarySchema.omit('owner', 'isDefault'),
run(library) { run(library) {
library.owner = this.userId; library.owner = this.userId;
return Libraries.insert(library); return Libraries.insert(library);
}, },
}); });
export { LibrarySchema, insertLibrary }; const setLibraryDefault = new ValidatedMethod({
name: 'Libraries.methods.makeLibraryDefault',
validate: new SimpleSchema({
_id: {
type: String,
regEx: SimpleSchema.RegEx.id
},
isDefault: {
type: Boolean,
},
}).validator(),
run({_id, isDefault}) {
if (!Meteor.users.isAdmin()){
throw new Meteor.Error('Permission denied', 'User must be admin to set libraries as default');
}
return Libraries.update(_id, {$set: {isDefault}});
},
});
export { LibrarySchema, insertLibrary, setLibraryDefault };

View File

@@ -13,6 +13,13 @@ let LibraryNodeSchema = new SimpleSchema({
type: String, type: String,
allowedValues: Object.keys(propertySchemasIndex), allowedValues: Object.keys(propertySchemasIndex),
}, },
tags: {
type: Array,
defaultValue: [],
},
'tags.$': {
type: String,
},
}); });
for (let key in propertySchemasIndex){ for (let key in propertySchemasIndex){

View File

@@ -107,7 +107,6 @@ export function setLineageOfDocs({docArray, oldParent, newAncestry}){
}); });
} }
/** /**
* Give documents new random ids and transform their references. * Give documents new random ids and transform their references.
* Transform collections of re-IDed docs according to the collection map * Transform collections of re-IDed docs according to the collection map

View File

@@ -21,6 +21,13 @@ let ClassLevelSchema = new SimpleSchema({
type: SimpleSchema.Integer, type: SimpleSchema.Integer,
defaultValue: 1, defaultValue: 1,
}, },
nextLevelTags: {
type: Array,
defaultValue: [],
},
'nextLevelTags.$': {
type: String,
},
}); });
export { ClassLevelSchema }; export { ClassLevelSchema };

View File

@@ -0,0 +1,13 @@
import SimpleSchema from 'simpl-schema';
let SlotSchema = new SimpleSchema({
slotTags: {
type: Array,
defaultValue: [],
},
'slotTags.$': {
type: String,
},
});
export { SlotSchema };

View File

@@ -12,8 +12,9 @@ import { FolderSchema } from '/imports/api/properties/Folders.js';
import { NoteSchema } from '/imports/api/properties/Notes.js'; import { NoteSchema } from '/imports/api/properties/Notes.js';
import { ProficiencySchema } from '/imports/api/properties/Proficiencies.js'; import { ProficiencySchema } from '/imports/api/properties/Proficiencies.js';
import { RollSchema } from '/imports/api/properties/Rolls.js'; import { RollSchema } from '/imports/api/properties/Rolls.js';
import { SkillSchema } from '/imports/api/properties/Skills.js';
import { SavingThrowSchema } from '/imports/api/properties/SavingThrows.js'; import { SavingThrowSchema } from '/imports/api/properties/SavingThrows.js';
import { SkillSchema } from '/imports/api/properties/Skills.js';
import { SlotSchema } from '/imports/api/properties/Slots.js';
import { SpellListSchema } from '/imports/api/properties/SpellLists.js'; import { SpellListSchema } from '/imports/api/properties/SpellLists.js';
import { SpellSchema } from '/imports/api/properties/Spells.js'; import { SpellSchema } from '/imports/api/properties/Spells.js';
import { ContainerSchema } from '/imports/api/properties/Containers.js'; import { ContainerSchema } from '/imports/api/properties/Containers.js';
@@ -35,6 +36,7 @@ const propertySchemasIndex = {
roll: RollSchema, roll: RollSchema,
savingThrow: SavingThrowSchema, savingThrow: SavingThrowSchema,
skill: SkillSchema, skill: SkillSchema,
slot: SlotSchema,
spellList: SpellListSchema, spellList: SpellListSchema,
spell: SpellSchema, spell: SpellSchema,
container: ContainerSchema, container: ContainerSchema,

View File

@@ -105,7 +105,7 @@ Meteor.users.sendVerificationEmail = new ValidatedMethod({
}).validator(), }).validator(),
run(userId, address){ run(userId, address){
userId = this.userId || userId; userId = this.userId || userId;
let user = Meteor.users.findOne(); let user = Meteor.users.findOne(userId);
if (!user) { if (!user) {
throw new Meteor.Error('User not found', throw new Meteor.Error('User not found',
'Can\'t send a validation email to a user that does not exist'); 'Can\'t send a validation email to a user that does not exist');
@@ -114,6 +114,12 @@ Meteor.users.sendVerificationEmail = new ValidatedMethod({
throw new Meteor.Error('Email address not found', throw new Meteor.Error('Email address not found',
'The specified email address wasn\'t found on this user account'); 'The specified email address wasn\'t found on this user account');
} }
Accounts.sendVerificationEmail(this.userId, address); Accounts.sendVerificationEmail(userId, address);
} }
}); });
Meteor.users.isAdmin = function(userId){
userId = this.userId || userId;
let user = Meteor.users.findOne(userId);
return user && user.roles.includes('admin');
}

View File

@@ -1,5 +1,5 @@
<template> <template>
<div class="character-sheet"> <div class="character-sheet layout column">
<v-toolbar app :color="character.color || 'secondary'" :dark="isDarkColor(character.color || theme.primary)"> <v-toolbar app :color="character.color || 'secondary'" :dark="isDarkColor(character.color || theme.primary)">
<v-btn v-if="showMenuButton" flat icon @click="toggleDrawer"> <v-btn v-if="showMenuButton" flat icon @click="toggleDrawer">
<v-icon>menu</v-icon> <v-icon>menu</v-icon>
@@ -14,12 +14,36 @@
centered centered
> >
<v-tab> <v-tab>
Stats
</v-tab>
<v-tab>
Features
</v-tab>
<v-tab>
Tree Tree
</v-tab> </v-tab>
</v-tabs> </v-tabs>
</v-toolbar> </v-toolbar>
<v-content v-if="$subReady.singleCharacter"> <v-content class="flex" v-if="$subReady.singleCharacter">
<v-tabs-items v-model="tab"> <v-tabs-items v-model="tab">
<v-tab-item>
<!--<stats-tab/>-->
<v-alert
:value="true"
type="info"
>
This tab is not available in this version of the alpha.
</v-alert>
</v-tab-item>
<v-tab-item>
<!--<features-tab/>-->
<v-alert
:value="true"
type="info"
>
This tab is not available in this version of the alpha.
</v-alert>
</v-tab-item>
<v-tab-item> <v-tab-item>
<tree-tab :creature-id="creatureId"/> <tree-tab :creature-id="creatureId"/>
</v-tab-item> </v-tab-item>
@@ -37,6 +61,8 @@
import { mapMutations } from "vuex"; import { mapMutations } from "vuex";
import { theme } from '/imports/ui/theme.js'; import { theme } from '/imports/ui/theme.js';
import TreeTab from '/imports/ui/creature/character/TreeTab.vue'; import TreeTab from '/imports/ui/creature/character/TreeTab.vue';
import StatsTab from '/imports/ui/creature/character/StatsTab.vue';
import FeaturesTab from '/imports/ui/creature/character/FeaturesTab.vue';
import { recomputeCreature } from '/imports/api/creature/creatureComputation.js' import { recomputeCreature } from '/imports/api/creature/creatureComputation.js'
export default { export default {
@@ -73,5 +99,14 @@
} }
</script> </script>
<style scoped> <style>
.v-tabs__bar {
background: none !important;
}
.v-window-item, .v-window, .v-window__container {
height: 100%;
}
.v-window-item {
padding: 0.1px;
}
</style> </style>

View File

@@ -68,7 +68,7 @@
<v-btn <v-btn
slot="activator" slot="activator"
color="primary" color="primary"
small fab small fab disabled
@click="insertCreatureProperty" @click="insertCreatureProperty"
> >
<v-icon>edit</v-icon> <v-icon>edit</v-icon>
@@ -127,12 +127,11 @@
component: 'creature-property-from-library-dialog', component: 'creature-property-from-library-dialog',
elementId: 'insert-creature-property-fab', elementId: 'insert-creature-property-fab',
callback(libraryNode){ callback(libraryNode){
console.log({libraryNode}); if (!libraryNode) return;
let propertyId = insertPropertyFromLibraryNode.call({ let propertyId = insertPropertyFromLibraryNode.call({
nodeId: libraryNode._id, nodeId: libraryNode._id,
parentRef: {collection: 'creatures', id: that.creatureId}, parentRef: {collection: 'creatures', id: that.creatureId},
}); });
console.log({propertyId});
return; return;
} }
}); });

View File

@@ -124,7 +124,10 @@
}, },
methods: { methods: {
insertCharacter(){ insertCharacter(){
store.commit("pushDialogStack", { insertCreature.call(result);
/*
store.commit("pushDialogStack", {
component: CharacterCreationDialog, component: CharacterCreationDialog,
data: {}, data: {},
element: undefined, element: undefined,
@@ -134,6 +137,7 @@
insertCreature.call(result); insertCreature.call(result);
}, },
}); });
*/
}, },
}, },
components: { components: {