diff --git a/api/games/games.ts b/api/games/games.ts index a967dc798eb71dabe51627af8d1f8fad031401da..1b1c1a7db31adc90836f80efb2d809fc6cd78e5e 100644 --- a/api/games/games.ts +++ b/api/games/games.ts @@ -89,26 +89,12 @@ export const joinGame = new ValidatedMethod<{ _id: string }, void>({ } }) -export const nextCards = new ValidatedMethod<{}, void>({ - name: 'Game.nextCards', - mixins: [schemaMixin, loggedInMixin, inGameMixin], - validate: new SimpleSchema({}), - run () { - callSystem(this, this.game.sys.nextCards) - } -}) +export const nextCards = newGameMethod('nextCards') -export const giveCards = new ValidatedMethod<{ cards: Card[] }, void>({ - name: 'Game.giveCards', - mixins: [schemaMixin, loggedInMixin, inGameMixin], - validate: new SimpleSchema({ - cards: {type: Array, minCount: 3, maxCount: 3}, - 'cards.$': Card - }), - run ({cards}) { - callSystem(this, this.game.sys.giveCards, cards) - } -}) +export const giveCards = newGameMethod('giveCards', new SimpleSchema({ + cards: {type: Array, minCount: 3, maxCount: 3}, + 'cards.$': Card +}), 'cards') export const playCards = new ValidatedMethod({ name: 'Game.playCards', @@ -135,38 +121,17 @@ export const playCards = new ValidatedMethod({ } }) -export const skipTurn = new ValidatedMethod<{}, void>({ - name: 'Game.skipTurn', - mixins: [schemaMixin, loggedInMixin, inGameMixin], - validate: new SimpleSchema({}), - run () { - callSystem(this, this.game.sys.skipTurn) - } -}) +export const skipTurn = newGameMethod('skipTurn') -export const giveDragon = new ValidatedMethod<{ to: number }, void>({ - name: 'game.giveDragon', - mixins: [schemaMixin, loggedInMixin, inGameMixin], - validate: new SimpleSchema({ - to: {type: Number, allowedValues: [0, 1]} - }), - run ({to}) { - callSystem(this, this.game.sys.giveDragon, to) - } -}) +export const giveDragon = newGameMethod('giveDragon', new SimpleSchema({ + to: {type: Number, allowedValues: [0, 1]} +}), 'to') -export const makeCall = new ValidatedMethod<{ bet: number }, void>({ - name: 'Game.makeCall', - mixins: [schemaMixin, loggedInMixin, inGameMixin], - validate: new SimpleSchema({ - bet: {type: Number, allowedValues: [Bet.TICHU, Bet.GRAND]} - }), - run ({bet}) { - callSystem(this, this.game.sys.makeCall, bet) - } -}) +export const makeCall = newGameMethod('makeCall', new SimpleSchema({ + bet: {type: Number, allowedValues: [Bet.TICHU, Bet.GRAND]} +}), 'bet') -function newGameMethod (name: string, schema: SimpleSchema, argName?: string): ValidatedMethod<any, void> { +function newGameMethod (name: string, schema: SimpleSchema = new SimpleSchema({}), argName?: string): ValidatedMethod<any, void> { return new ValidatedMethod<any, void>({ name: 'Game.' + name, mixins: [schemaMixin, loggedInMixin, inGameMixin],