Moved tabletop characters to left side of the screen

This commit is contained in:
Thaum Rystra
2024-04-12 17:05:20 +02:00
parent 4793b34a55
commit 08640f2bf2
27 changed files with 496 additions and 1370 deletions

View File

@@ -1,25 +0,0 @@
import Tabletops from '../../Tabletops';
export function assertUserInTabletop(tabletopId, userId) {
let tabletop = Tabletops.findOne(tabletopId);
if (!tabletop) {
throw new Meteor.Error('Tabletop does not exist',
'No tabletop could be found for the given tabletop id');
}
if (tabletop.gameMaster !== userId && !tabletop.players.includes(userId)) {
throw new Meteor.Error('Not in tabletop',
'The user is not the gamemaster or a player in the given tabletop');
}
}
export function assertUserIsTabletopOwner(tabletopId, userId) {
let tabletop = Tabletops.findOne(tabletopId);
if (!tabletop) {
throw new Meteor.Error('Tabletop does not exist',
'No tabletop could be found for the given tabletop id');
}
if (tabletop.gameMaster !== userId) {
throw new Meteor.Error('Not the owner',
'The user is not the owner of the given tabletop');
}
}

View File

@@ -0,0 +1,41 @@
import Tabletops, { Tabletop } from '/imports/api/tabletop/Tabletops';
function assertTabletopExists(tabletop: Tabletop | undefined): asserts tabletop is Tabletop {
if (!tabletop) {
throw new Meteor.Error('Tabletop does not exist',
'No tabletop could be found for the given tabletop id');
}
}
export function assertUserInTabletop(tabletopId, userId) {
const tabletop = Tabletops.findOne(tabletopId, {
fields: { gameMasters: 1, players: 1 }
});
assertTabletopExists(tabletop);
if (tabletop.gameMasters.includes(userId) && !tabletop.players.includes(userId)) {
throw new Meteor.Error('Not in tabletop',
'The user is not the gamemaster or a player in the given tabletop');
}
}
export function assertUserGameMasterOfTabletop(tabletopId, userId) {
const tabletop = Tabletops.findOne(tabletopId, {
fields: { gameMasters: 1 },
});
assertTabletopExists(tabletop);
if (tabletop.gameMasters.includes(userId)) {
throw new Meteor.Error('not-game-master',
'The user is not a game master in the given tabletop');
}
}
export function assertUserIsTabletopOwner(tabletopId, userId) {
const tabletop = Tabletops.findOne(tabletopId, {
fields: { owner: 1 },
});
assertTabletopExists(tabletop);
if (tabletop.owner === userId) {
throw new Meteor.Error('not-owner',
'The user is not the owner of the given tabletop');
}
}