Skip to content

Commit

Permalink
fix: jersey should not be displayed in 2P mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliboy50 committed Sep 15, 2024
1 parent c638d97 commit 7f45674
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
14 changes: 7 additions & 7 deletions velonimo.game.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ protected function getAllDatas() {

// Rounds
$result['currentRound'] = (int) self::getGameStateValue(self::GAME_STATE_CURRENT_ROUND);
$result['jerseyIsNotPlayable'] = $this->isJerseyNotPlayable();
$result['jerseyIsNotPlayable'] = $this->isJerseyNotPlayable($players);
$result['howManyRounds'] = $this->getHowManyRounds();

// Players
Expand Down Expand Up @@ -398,15 +398,12 @@ function playCards(
$currentPlayer = $this->getPlayerById($currentPlayerId, $players);
$currentPlayerIsWearingJersey = $currentPlayer->isWearingJersey();
if ($cardsPlayedWithJersey) {
if ($this->isJerseyNotPlayable()) {
if ($this->isJerseyNotPlayable($players)) {
$this->throwPlayedCardNotPlayable();
}
if (!$currentPlayerIsWearingJersey) {
$this->throwPlayedCardNotInPlayerHand();
}
if ($this->is2PlayersMode($players)) {
$this->throwPlayedCardNotInPlayerHand();
}
}
if ($cardsPlayedWithLegendsBroomWagon) {
if ($this->isLegendsBroomWagonNotPlayable()) {
Expand Down Expand Up @@ -1890,8 +1887,11 @@ private function fromSpecialCardIdToIsNotPlayableGameStateKey(int $cardId): stri
}
}

private function isJerseyNotPlayable(): bool {
return 1 === (int) self::getGameStateValue(self::GAME_STATE_JERSEY_IS_NOT_PLAYABLE);
/**
* @param VelonimoPlayer[] $players
*/
private function isJerseyNotPlayable(array $players = null): bool {
return $this->is2PlayersMode($players) || 1 === (int) self::getGameStateValue(self::GAME_STATE_JERSEY_IS_NOT_PLAYABLE);
}

private function isLegendsBroomWagonNotPlayable(): bool {
Expand Down
21 changes: 12 additions & 9 deletions velonimo.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ const DOM_CLASS_VELONIMO_CARD = 'velonimo-card';
const DOM_CLASS_CARD_FRONT_SIDE = 'front-side';
const DOM_CLASS_CARD_BACK_SIDE = 'back-side';
const DOM_CLASS_MOVING_CARD = 'moving-card';
const DOM_CLASS_MOVING_SPECIAL_CARD = 'moving-special-card';

// Player hand sorting modes
const PLAYER_HAND_SORT_BY_COLOR = 'color';
Expand Down Expand Up @@ -396,13 +395,15 @@ function (dojo, declare) {
this.moveLegendsBroomWagonToLastLoser();
}

// setup jersey
if (gamedatas.jerseyIsNotPlayable) {
this.useSpecialCardForCurrentRound(CARD_ID_JERSEY_PLUS_TEN);
} else {
this.restoreSpecialCardForCurrentRound(CARD_ID_JERSEY_PLUS_TEN);
// setup jersey (if not 2P mode)
if (!this.is2PlayersMode()) {
if (this.jerseyIsNotPlayable) {
this.useSpecialCardForCurrentRound(CARD_ID_JERSEY_PLUS_TEN);
} else {
this.restoreSpecialCardForCurrentRound(CARD_ID_JERSEY_PLUS_TEN);
}
this.moveJerseyToCurrentWinner();
}
this.moveJerseyToCurrentWinner();

// show 2P mode items
if (this.is2PlayersMode()) {
Expand Down Expand Up @@ -1956,7 +1957,7 @@ function (dojo, declare) {
*/
getSpecialPlayerCardIds: function () {
return [
[CARD_ID_JERSEY_PLUS_TEN, () => this.currentPlayerHasJersey && !this.jerseyIsNotPlayable && !this.is2PlayersMode()],
[CARD_ID_JERSEY_PLUS_TEN, () => this.currentPlayerHasJersey && !this.jerseyIsNotPlayable],
[CARD_ID_LEGENDS_BROOM_WAGON_PLUS_FIVE, () => this.currentPlayerHasLegendsBroomWagon && !this.legendsBroomWagonIsNotPlayable],
[CARD_ID_LEGENDS_EAGLE_ADD_ONE_OTHER_NUMBER, () => this.currentPlayerHasLegendsEagle && !this.legendsEagleIsNotPlayable && !this.currentPlayerHasJersey],
[CARD_ID_LEGENDS_PANDA_ADD_ONE_OTHER_COLOR, () => this.currentPlayerHasLegendsPanda && !this.legendsPandaIsNotPlayable && !this.currentPlayerHasJersey],
Expand Down Expand Up @@ -3409,7 +3410,9 @@ function (dojo, declare) {
data.args.specialCardIdsToRestore.forEach((cardId) => {
this.restoreSpecialCardForCurrentRound(cardId);
});
this.moveJerseyToCurrentWinner();
if (!this.is2PlayersMode()) {
this.moveJerseyToCurrentWinner();
}
this.moveLegendsBroomWagonToLastLoser();

this.setupPlayersScore();
Expand Down

0 comments on commit 7f45674

Please sign in to comment.