Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion convex/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@1.11.2.
* Generated by convex@1.12.1.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand Down
2 changes: 1 addition & 1 deletion convex/_generated/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@1.11.2.
* Generated by convex@1.12.1.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand Down
2 changes: 1 addition & 1 deletion convex/_generated/dataModel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@1.11.2.
* Generated by convex@1.12.1.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand Down
2 changes: 1 addition & 1 deletion convex/_generated/server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@1.11.2.
* Generated by convex@1.12.1.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand Down
2 changes: 1 addition & 1 deletion convex/_generated/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@1.11.2.
* Generated by convex@1.12.1.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand Down
24 changes: 18 additions & 6 deletions convex/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { internalMutationWithEnt, mutationWithGame } from './lib/functions'

export const startSelectSet = mutationWithGame({
args: {},
returns: v.union(
v.null(),
v.object({
reason: v.string(),
selectedBy: v.id('Players'),
})
),
handler: async (ctx) => {
const { game, player } = ctx

Expand All @@ -17,13 +24,15 @@ export const select = mutationWithGame({
args: {
cardId: v.id('PlayingCards'),
},
returns: v.null(),
handler: async (ctx, { cardId }) => {
return Cards.select(ctx, { cardId })
},
})

export const reveal = mutationWithGame({
args: {},
returns: v.null(),
handler: async (ctx) => {
return Cards.reveal(ctx)
},
Expand All @@ -34,22 +43,23 @@ export const discardRevealedProset = internalMutationWithEnt({
gameId: v.id('Games'),
cardIds: v.array(v.id('PlayingCards')),
},
returns: v.null(),
handler: async (ctx, args) => {
const player = await Player.getSystemPlayer(ctx, args.gameId)

const game = await ctx.table("Games").getX(args.gameId)
const game = await ctx.table('Games').getX(args.gameId)

const prosetId = await ctx.table('Prosets').insert({
PlayingCards: args.cardIds,
PlayerId: player._id
PlayerId: player._id,
})
await game.patch({
selectingPlayer: null,
selectionStartTime: null,
})
await Promise.all(
args.cardIds.map((cardId) => {
return ctx.table("PlayingCards").getX(cardId).patch({
return ctx.table('PlayingCards').getX(cardId).patch({
proset: prosetId,
})
})
Expand All @@ -63,9 +73,10 @@ export const claimSet = internalMutationWithEnt({
gameId: v.id('Games'),
playerId: v.id('Players'),
},
returns: v.null(),
handler: async (ctx, { gameId, playerId }) => {
const game = await ctx.table("Games").getX(gameId)
const player = await ctx.table("Players").getX(playerId)
const game = await ctx.table('Games').getX(gameId)
const player = await ctx.table('Players').getX(playerId)
await Cards.claimSet(ctx, {
game: game,
player: player,
Expand All @@ -77,8 +88,9 @@ export const maybeClearSelectSet = internalMutationWithEnt({
args: {
gameId: v.id('Games'),
},
returns: v.null(),
handler: async (ctx, { gameId }) => {
const game = await ctx.table("Games").getX(gameId)
const game = await ctx.table('Games').getX(gameId)
await Cards.maybeClearSelectSet(ctx, game)
},
})
53 changes: 43 additions & 10 deletions convex/dealCards.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
import { PaginationOptions, PaginationResult } from 'convex/server'
import { Doc, Id } from './_generated/dataModel'
import { query } from './_generated/server';
import { QueryCtx, queryWithEnt } from './lib/functions';
import { PaginationResult, paginationOptsValidator } from 'convex/server'
import { v } from 'convex/values'
import { Doc } from './_generated/dataModel'
import { queryWithEnt } from './lib/functions'

export default queryWithEnt(
async (
export default queryWithEnt({
args: { gameId: v.id('Games'), paginationOpts: paginationOptsValidator },
returns: v.object({
page: v.array(
v.object({
GameId: v.id('Games'),
blue: v.boolean(),
green: v.boolean(),
orange: v.boolean(),
proset: v.union(v.null(), v.id('Prosets')),
purple: v.boolean(),
rank: v.float64(),
red: v.boolean(),
selectedBy: v.union(v.null(), v.id('Players')),
yellow: v.boolean(),
_id: v.id('PlayingCards'),
_creationTime: v.number(),
})
),
isDone: v.boolean(),
continueCursor: v.string(),
splitCursor: v.optional(v.union(v.string(), v.null())),
pageStatus: v.optional(
v.union(
v.literal('SplitRecommended'),
v.literal('SplitRequired'),
v.null()
)
),
}),
handler: async (
ctx,
args: { gameId: Id<'Games'>; paginationOpts: PaginationOptions }
args
): Promise<PaginationResult<Doc<'PlayingCards'>>> => {
return ctx.table("PlayingCards", "ByGameAndProsetAndRank", q => q.eq("GameId", args.gameId).eq("proset", null)).paginate(args.paginationOpts)
}
)
return ctx
.table('PlayingCards', 'ByGameAndProsetAndRank', (q) =>
q.eq('GameId', args.gameId).eq('proset', null)
)
.paginate(args.paginationOpts)
},
})
63 changes: 61 additions & 2 deletions convex/games.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { v } from 'convex/values'
import { internalMutationWithEnt, mutationWithEnt, mutationWithGame, queryWithGame } from './lib/functions'
import {
internalMutationWithEnt,
mutationWithEnt,
mutationWithGame,
queryWithGame,
} from './lib/functions'
import * as Games from './model/game'
import * as Players from './model/player'
import * as User from './model/user'
Expand Down Expand Up @@ -34,8 +39,62 @@ export const end = mutationWithGame({
},
})

/*
export interface GameInfo {
game: Doc<'Games'>
currentPlayer: Doc<'Players'> & { showOnboarding: boolean; isGuest: boolean }
otherPlayers: Doc<'Players'>[]
playerToProsets: Record<string, Doc<'PlayingCards'>[][]>
}


*/

const playerFields = {
// from schema
name: v.string(),
score: v.number(),
color: v.union(
v.literal('red'),
v.literal('orange'),
v.literal('yellow'),
v.literal('green'),
v.literal('blue'),
v.literal('purple'),
v.literal('grey')
),
isSystemPlayer: v.boolean(),
// system fields
_id: v.id('Players'),
_creationTime: v.number(),
// fields added by ents
GameId: v.id('Games'),
UserId: v.id('Users'),
}

export const getInfo = queryWithGame({
args: {},
returns: v.object({
game: v.object({
name: v.string(),
selectingPlayer: v.union(v.null(), v.id('Players')),
selectionStartTime: v.union(v.null(), v.number()),
inProgress: v.boolean(),
isPublic: v.optional(v.boolean()),
// system fields
_id: v.id('Games'),
_creationTime: v.number(),
// fields added by ents
}),
currentPlayer: v.object({
...playerFields,
isGuest: v.boolean(),
showOnboarding: v.boolean(),
}),
otherPlayers: v.array(v.object(playerFields)),
// record
playerToProsets: v.any(),
}),
handler: async (ctx) => {
return await Games.getInfo(ctx, {
currentPlayer: ctx.player,
Expand All @@ -47,7 +106,7 @@ export const getInfo = queryWithGame({

export const cleanup = internalMutationWithEnt({
args: { gameId: v.id('Games') },
handler: (ctx, args) => {} // Games.cleanup(ctx, args),
handler: (ctx, args) => {}, // Games.cleanup(ctx, args),
})

export const setup = internalMutationWithEnt({
Expand Down
23 changes: 18 additions & 5 deletions convex/message.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { v } from 'convex/values'
import { Doc } from './_generated/dataModel'
import { internalMutation } from './_generated/server'
import { mutationWithGame, queryWithGame, } from './lib/functions'
import { mutationWithGame, queryWithGame } from './lib/functions'
import * as Message from './model/message'
import { Doc } from './_generated/dataModel'

export const send = mutationWithGame({
args: {
Expand All @@ -28,8 +28,21 @@ export const remove = internalMutation({

export const list = queryWithGame({
args: {},
handler: async (ctx): Promise<Array<Doc<"Messages">>> => {
const messages = await ctx.game.edge("Messages")
return messages.filter(m => m._creationTime >= Date.now() - 10 * 1000 && (m.player === null || m.player === ctx.player._id))
returns: v.array(
v.object({
content: v.string(),
player: v.union(v.null(), v.string()),
GameId: v.id('Games'),
_id: v.id('Messages'),
_creationTime: v.number(),
})
),
handler: async (ctx): Promise<Array<Doc<'Messages'>>> => {
const messages = await ctx.game.edge('Messages')
return messages.filter(
(m) =>
m._creationTime >= Date.now() - 10 * 1000 &&
(m.player === null || m.player === ctx.player._id)
)
},
})
Loading