Prevented new characters being added if you are at your character limit
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import '/imports/api/creature/creatures/methods/insertCreature.js';
|
||||
import '/imports/api/creature/creatures/methods/removeCreature.js';
|
||||
import '/imports/api/creature/creatures/methods/restCreature.js';
|
||||
import '/imports/api/creature/creatures/methods/transferCreatureOwnership.js';
|
||||
import '/imports/api/creature/creatures/methods/updateCreature.js';
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||
import { assertUserHasPaidBenefits } from '/imports/api/users/patreon/tiers.js';
|
||||
import { getUserTier } from '/imports/api/users/patreon/tiers.js';
|
||||
import defaultCharacterProperties from '/imports/api/creature/creatures/defaultCharacterProperties.js';
|
||||
import insertPropertyFromLibraryNode from '/imports/api/creature/creatureProperties/methods/insertPropertyFromLibraryNode.js';
|
||||
|
||||
@@ -23,7 +23,21 @@ const insertCreature = new ValidatedMethod({
|
||||
throw new Meteor.Error('Creatures.methods.insert.denied',
|
||||
'You need to be logged in to insert a creature');
|
||||
}
|
||||
assertUserHasPaidBenefits(this.userId);
|
||||
let tier = getUserTier(this.userId);
|
||||
|
||||
let currentCharacterCount = Creatures.find({
|
||||
owner: this.userId,
|
||||
}, {
|
||||
fields: {_id: 1},
|
||||
}).count();
|
||||
|
||||
if (
|
||||
tier.characterSlots !== -1 &&
|
||||
currentCharacterCount >= tier.characterSlots
|
||||
){
|
||||
throw new Meteor.Error('Creatures.methods.insert.denied',
|
||||
`You are already at your limit of ${tier.characterSlots} characters`)
|
||||
}
|
||||
|
||||
// Create the creature document
|
||||
let creatureId = Creatures.insert({
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<template lang="html">
|
||||
<div>
|
||||
{{ creatureCount }} /
|
||||
<v-icon v-if="characterSlots === -1">
|
||||
mdi-infinity
|
||||
</v-icon>
|
||||
<template v-else>
|
||||
{{ characterSlots }}
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="js">
|
||||
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||
import { getUserTier } from '/imports/api/users/patreon/tiers.js';
|
||||
|
||||
export default {
|
||||
meteor: {
|
||||
creatureCount(){
|
||||
return Creatures.find({owner: Meteor.userId()}).count();
|
||||
},
|
||||
characterSlots(){
|
||||
return getUserTier(Meteor.userId()).characterSlots;
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="css">
|
||||
</style>
|
||||
@@ -3,6 +3,13 @@
|
||||
class="card-background pa-4"
|
||||
style="height: 100%"
|
||||
>
|
||||
<v-alert
|
||||
v-if="exceededCharacterSpace"
|
||||
type="error"
|
||||
>
|
||||
You have exceeded your maximum number of character slots, archive or delete
|
||||
some characters.
|
||||
</v-alert>
|
||||
<v-card :class="{'mb-4': folders && folders.length}">
|
||||
<creature-list :creatures="CreaturesWithNoParty" />
|
||||
</v-card>
|
||||
@@ -76,6 +83,7 @@
|
||||
bottom
|
||||
right
|
||||
data-id="new-character-button"
|
||||
:disabled="!hasCharacterSpace"
|
||||
@click="insertCharacter"
|
||||
>
|
||||
<v-icon>mdi-plus</v-icon>
|
||||
@@ -143,6 +151,28 @@
|
||||
{sort: {name: 1}}
|
||||
).map(characterTransform);
|
||||
},
|
||||
creatureCount(){
|
||||
let userId = Meteor.userId();
|
||||
return Creatures.find({
|
||||
owner: userId,
|
||||
}, {
|
||||
fields: {_id: 1},
|
||||
}).count();
|
||||
},
|
||||
tier(){
|
||||
let userId = Meteor.userId();
|
||||
return getUserTier(userId);
|
||||
},
|
||||
hasCharacterSpace(){
|
||||
let tier = this.tier;
|
||||
let currentCharacterCount = this.creatureCount;
|
||||
return tier.characterSlots === -1 || currentCharacterCount < tier.characterSlots
|
||||
},
|
||||
exceededCharacterSpace(){
|
||||
let tier = this.tier;
|
||||
let currentCharacterCount = this.creatureCount;
|
||||
return tier.characterSlots !== -1 && currentCharacterCount > tier.characterSlots
|
||||
}
|
||||
},
|
||||
watch:{
|
||||
renamingFolder(newId){
|
||||
@@ -156,26 +186,21 @@
|
||||
},
|
||||
methods: {
|
||||
insertCharacter(){
|
||||
let tier = getUserTier(Meteor.userId());
|
||||
if (tier.paidBenefits){
|
||||
insertCreature.call((error, result) => {
|
||||
if (error){
|
||||
console.error(error);
|
||||
} else {
|
||||
this.$store.commit(
|
||||
'setTabForCharacterSheet',
|
||||
{id: result, tab: 4}
|
||||
);
|
||||
this.$store.commit('setShowDetailsDialog', true);
|
||||
this.$router.push({ path: `/character/${result}`});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.$store.commit('pushDialogStack', {
|
||||
component: 'tier-too-low-dialog',
|
||||
elementId: 'new-character-button',
|
||||
});
|
||||
}
|
||||
insertCreature.call((error, result) => {
|
||||
if (error){
|
||||
console.error(error);
|
||||
snackbar({
|
||||
text: error.reason,
|
||||
});
|
||||
} else {
|
||||
this.$store.commit(
|
||||
'setTabForCharacterSheet',
|
||||
{id: result, tab: 4}
|
||||
);
|
||||
this.$store.commit('setShowDetailsDialog', true);
|
||||
this.$router.push({ path: `/character/${result}`});
|
||||
}
|
||||
});
|
||||
},
|
||||
insertFolder(){
|
||||
this.loadingInsertFolder = true;
|
||||
|
||||
@@ -5,6 +5,7 @@ import { acceptInviteToken } from '/imports/api/users/Invites.js';
|
||||
import Home from '/imports/ui/pages/Home.vue';
|
||||
import About from '/imports/ui/pages/About.vue';
|
||||
import CharacterList from '/imports/ui/pages/CharacterList.vue';
|
||||
import CharacterListToolbarItems from '/imports/ui/creature/creatureList/CharacterListToolbarItems.vue';
|
||||
import Library from '/imports/ui/pages/Library.vue';
|
||||
import SingleLibraryToolbar from '/imports/ui/library/SingleLibraryToolbar.vue';
|
||||
import CharacterSheetPage from '/imports/ui/pages/CharacterSheetPage.vue';
|
||||
@@ -104,6 +105,7 @@ RouterFactory.configure(factory => {
|
||||
path: '/characterList',
|
||||
components: {
|
||||
default: CharacterList,
|
||||
toolbarItems: CharacterListToolbarItems,
|
||||
},
|
||||
meta: {
|
||||
title: 'Character List',
|
||||
|
||||
Reference in New Issue
Block a user