Started work on tabletop view

This commit is contained in:
Stefan Zermatten
2020-07-17 23:31:12 +02:00
parent 47345b3694
commit 95d8d2cb9a
24 changed files with 749 additions and 94 deletions

View File

@@ -1,5 +1,5 @@
import Creatures from '/imports/api/creature/Creatures.js';
import Parties from '/imports/api/campaign/Parties.js';
import Parties from '/imports/api/creature/Parties.js';
Meteor.publish('characterList', function(){
this.autorun(function (){

View File

@@ -5,3 +5,4 @@ import '/imports/server/publications/singleCharacter.js';
import '/imports/server/publications/experiences.js';
import '/imports/server/publications/users.js';
import '/imports/server/publications/icons.js';
import '/imports/server/publications/tabletops.js';

View File

@@ -0,0 +1,51 @@
import Tabletops from '/imports/api/tabletop/Tabletops.js';
import Creatures from '/imports/api/creature/Creatures.js';
Meteor.publish('tabletops', function(){
var userId = this.userId;
if (!userId) {
return this.ready();
}
return Tabletops.find({
$or: [
{players: userId},
{gameMaster: userId},
],
});
});
Meteor.publish('tabletop', function(tabletopId){
var userId = this.userId;
if (!userId) {
return this.ready();
}
this.autorun(function (){
let tabletopCursor = Tabletops.find({
_id: tabletopId,
$or: [
{players: userId},
{gameMaster: userId},
]
});
let tabletop = tabletopCursor.fetch()[0];
if (!tabletop){
return this.ready();
}
// Warning, this leaks data to users of the same tabletop who may not have
// read permission of this specific creature, so publish as few fields as
// possible
let creatureSummaries = Creatures.find({
tabletop: tabletopId,
}, {
fields: {
name: 1,
picture: 1,
avatarPicture: 1,
variables: 1,
tabletop: 1,
initiativeRoll: 1,
},
});
return [ tabletopCursor, creatureSummaries]
})
});