Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly generate hands for each of the 3/4 player routes #1439

Merged
merged 1 commit into from
Dec 19, 2020
Merged
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 client/web/pinochle/app/components/hand/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{stack this.toggle}}
{{resize this.adjust}}
>
{{#each this.cards as |card|}}
{{#each @cards as |card|}}
<PlayingCard
id={{card.id}}
@suit={{card.suit}}
Expand Down
19 changes: 4 additions & 15 deletions client/web/pinochle/app/components/hand/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@ import { cached } from '@glimmer/tracking';
import { getOwner } from '@ember/application';
import { action } from '@ember/object';

import { newDeck, sortHand, splitDeck } from 'pinochle/utils/deck';
import { Meld } from 'pinochle/utils/game/meld';

import { HandAnimation } from './-animation/hand';

import type { Card, Hand } from 'pinochle/utils/deck';
import type { Card } from 'pinochle/utils/deck';

type Args = {
hand: Hand;
cards: Card[];
};

export default class HandComponent extends Component<Args> {
@cached
get hand() {
return new HandAnimation(getOwner(this), this.cards);
return new HandAnimation(getOwner(this), this.args.cards);
}

/**
* Given the current cards, what are all the meld combinations and score?
*/
@cached
get meld() {
return new Meld([...(this.cards as Card[])]);
return new Meld([...(this.args.cards as Card[])]);
}

@action
Expand All @@ -42,14 +41,4 @@ export default class HandComponent extends Component<Args> {
adjust() {
this.hand.send('ADJUST');
}

@cached
get cards() {
let deck = newDeck();
let dealt = splitDeck(deck, 4);
let hand = dealt.hands[0];
let sorted = sortHand(hand);

return sorted;
}
}
Empty file.
3 changes: 0 additions & 3 deletions client/web/pinochle/app/routes/four-player.js

This file was deleted.

19 changes: 19 additions & 0 deletions client/web/pinochle/app/routes/four-player.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Route from '@ember/routing/route';

import { newDeck, sortHand, splitDeck } from 'pinochle/utils/deck';

const NUM_PLAYERS = 4;

export default class FourPlayerRoute extends Route {
async model() {
let deck = newDeck();
let dealt = splitDeck(deck, NUM_PLAYERS);
let unsorted = dealt.hands[0];
let hand = sortHand(unsorted);

return {
numPlayers: NUM_PLAYERS,
hand,
};
}
}
3 changes: 0 additions & 3 deletions client/web/pinochle/app/routes/three-player.js

This file was deleted.

19 changes: 19 additions & 0 deletions client/web/pinochle/app/routes/three-player.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Route from '@ember/routing/route';

import { newDeck, sortHand, splitDeck } from 'pinochle/utils/deck';

const NUM_PLAYERS = 3;

export default class ThreePlayerRoute extends Route {
async model() {
let deck = newDeck();
let dealt = splitDeck(deck, NUM_PLAYERS);
let unsorted = dealt.hands[0];
let hand = sortHand(unsorted);

return {
numPlayers: NUM_PLAYERS,
hand,
};
}
}
4 changes: 3 additions & 1 deletion client/web/pinochle/app/templates/four-player.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{{outlet}}
<div class='perspective'>
<Hand @cards={{@model.hand}} />
</div>
2 changes: 1 addition & 1 deletion client/web/pinochle/app/templates/three-player.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class='perspective'>
<Hand />
<Hand @cards={{@model.hand}} />
</div>