Fixed some errors with character insertion/deletion

This commit is contained in:
Stefan Zermatten
2022-07-09 12:53:44 +02:00
parent b8a03245ea
commit 59ef7527b7
7 changed files with 33 additions and 14 deletions

View File

@@ -3,11 +3,13 @@ import { ValidatedMethod } from 'meteor/mdg:validated-method';
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
import { assertOwnership } from '/imports/api/creature/creatures/creaturePermissions.js';
import Creatures from '/imports/api/creature/creatures/Creatures.js';
import CreatureVariables from '/imports/api/creature/creatures/CreatureVariables.js';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
import CreatureLogs from '/imports/api/creature/log/CreatureLogs.js';
import Experiences from '/imports/api/creature/experience/Experiences.js';
function removeRelatedDocuments(creatureId){
CreatureVariables.remove({_creatureId: creatureId});
CreatureProperties.remove({'ancestors.id': creatureId});
CreatureLogs.remove({creatureId});
Experiences.remove({creatureId});

View File

@@ -1,9 +1,9 @@
import CreatureVariables from '/imports/api/creature/creatures/CreatureVariables.js';
import Creatures from '/imports/api/creature/creatures/Creatures.js';
import { EJSON } from 'meteor/ejson';
import { omitBy } from 'lodash';
export default function writeScope(creatureId, computation) {
if (!creatureId) throw 'creatureId is required';
const scope = computation.scope;
const variables = computation.variables || {};
delete variables._id;
@@ -50,7 +50,7 @@ export default function writeScope(creatureId, computation) {
if ($unset) update.$unset = $unset;
CreatureVariables.upsert({_creatureId: creatureId}, update);
}
if (computation.creature.dirty) {
if (computation.creature?.dirty) {
Creatures.update({_creatureId: creatureId}, {$unset: { dirty: 1 }});
}
}

View File

@@ -129,6 +129,16 @@ if<template>
},
mounted(){
this.$store.commit('setPageTitle', this.creature && this.creature.name || 'Character Sheet');
this.nameObserver = Creatures.find({
creatureId: this.creatureId,
}, {
fields: {name: 1},
}).observe({
added: ({name}) =>
this.$store.commit('setPageTitle', name || 'Character Sheet'),
changed: ({ name }) =>
this.$store.commit('setPageTitle', name || 'Character Sheet'),
});
let that = this;
this.logObserver = CreatureLogs.find({
creatureId: this.creatureId,
@@ -141,6 +151,7 @@ if<template>
});
},
beforeDestroy(){
this.nameObserver.stop();
this.logObserver.stop();
},
meteor: {

View File

@@ -143,12 +143,6 @@ export default {
return highestLevelsList;
},
},
mounted(){
if (this.$store.state.showDetailsDialog){
this.$store.commit('setShowDetailsDialog', false);
this.showCharacterForm();
}
},
meteor: {
creature(){
return Creatures.findOne(this.creatureId);

View File

@@ -454,9 +454,10 @@
return getAttributeOfType(this.creature, 'spellSlot');
},
hasSpells(){
return getProperties(this.creature, {
const cursor = getProperties(this.creature, {
type: 'spell',
}).count();
})
return cursor && cursor.count();
},
hitDice(){
return getAttributeOfType(this.creature, 'hitDice');

View File

@@ -1,5 +1,6 @@
const AddCreaturePropertyDialog = () => import('/imports/ui/creature/creatureProperties/AddCreaturePropertyDialog.vue');
const ArchiveDialog = () => import('/imports/ui/creature/archive/ArchiveDialog.vue');
const CharacterCreationDialog = () => import('/imports/ui/creature/character/CharacterCreationDialog.vue');
const CastSpellWithSlotDialog = () => import('/imports/ui/properties/components/spells/CastSpellWithSlotDialog.vue');
const CreatureFormDialog = () => import('/imports/ui/creature/CreatureFormDialog.vue');
const CreaturePropertyCreationDialog = () => import('/imports/ui/creature/creatureProperties/CreaturePropertyCreationDialog.vue');
@@ -28,6 +29,7 @@ export default {
AddCreaturePropertyDialog,
ArchiveDialog,
CastSpellWithSlotDialog,
CharacterCreationDialog,
CreatureFormDialog,
CreaturePropertyCreationDialog,
CreaturePropertyDialog,

View File

@@ -74,6 +74,7 @@
</template>
<script lang="js">
import { defer } from 'lodash';
import Creatures from '/imports/api/creature/creatures/Creatures.js';
import insertCreature from '/imports/api/creature/creatures/methods/insertCreature.js';
import CreatureFolders from '/imports/api/creature/creatureFolders/CreatureFolders.js';
@@ -159,7 +160,7 @@
},
methods: {
insertCharacter(){
insertCreature.call((error, result) => {
insertCreature.call((error, creatureId) => {
if (error){
console.error(error);
snackbar({
@@ -168,10 +169,18 @@
} else {
this.$store.commit(
'setTabForCharacterSheet',
{id: result, tab: 4}
{id: creatureId, tab: 4}
);
this.$store.commit('setShowDetailsDialog', true);
this.$router.push({ path: `/character/${result}`});
defer(() => {
this.$store.commit('pushDialogStack', {
component: 'character-creation-dialog',
elementId: 'new-character-button',
data: {
creatureId,
},
});
})
this.$router.push({ path: `/character/${creatureId}` });
}
});
},