Skip to content

Commit

Permalink
feat: color all player names
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliboy50 committed Jun 18, 2022
1 parent a9f5a64 commit 1e827d3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
16 changes: 8 additions & 8 deletions states.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
// The first player of a round must play cards
ST_FIRST_PLAYER_TURN => [
'name' => 'firstPlayerTurn',
'description' => clienttranslate('${actplayer} must play one or more cards'),
'descriptionmyturn' => clienttranslate('${you} must play one or more cards'),
'description' => clienttranslate('${actplayer} must play card(s)'),
'descriptionmyturn' => clienttranslate('${you} must play card(s)'),
'type' => 'activeplayer',
'args' => 'argFirstPlayerTurn',
'possibleactions' => ['playCards'],
Expand All @@ -89,8 +89,8 @@
// The next player must choose to play cards or pass
ST_PLAYER_TURN => [
'name' => 'playerTurn',
'description' => clienttranslate('${actplayer} must play cards to beat ${playedCardsValue} or pass'),
'descriptionmyturn' => clienttranslate('${you} must play cards to beat ${playedCardsValue} or pass'),
'description' => clienttranslate('${actplayer} must play card(s) to beat ${playedCardsValue} or pass'),
'descriptionmyturn' => clienttranslate('${you} must play card(s) to beat ${playedCardsValue} or pass'),
'type' => 'activeplayer',
'args' => 'argPlayerTurn',
'possibleactions' => ['playCards', 'passTurn'],
Expand Down Expand Up @@ -135,8 +135,8 @@
// this player has to pick one or more cards from another player of its choice
ST_PLAYER_PICK_CARDS_FROM_PLAYER => [
'name' => 'playerSelectPlayerToPickCards',
'description' => clienttranslate('${actplayer} must randomly pick ${numberOfCards} cards from another player\'s hand'),
'descriptionmyturn' => clienttranslate('${you} must randomly pick ${numberOfCards} cards from another player\'s hand'),
'description' => clienttranslate('${actplayer} must pick ${numberOfCards} card(s) from another player\'s hand'),
'descriptionmyturn' => clienttranslate('${you} must pick ${numberOfCards} card(s) from another player\'s hand'),
'type' => 'activeplayer',
'args' => 'argPlayerSelectPlayerToPickCards',
'possibleactions' => ['selectPlayerToPickCards'],
Expand All @@ -147,8 +147,8 @@
// the player who picked cards must give back the same number of cards of its choice
ST_PLAYER_GIVE_CARDS_BACK_TO_PLAYER_AFTER_PICKING => [
'name' => 'playerGiveCardsBackAfterPicking',
'description' => clienttranslate('${actplayer} must choose ${numberOfCards} cards for ${selectedPlayerName}'),
'descriptionmyturn' => clienttranslate('${you} must choose ${numberOfCards} cards for ${selectedPlayerName}'),
'description' => clienttranslate('${actplayer} must choose ${numberOfCards} card(s) for ${otherplayer}'),
'descriptionmyturn' => clienttranslate('${you} must choose ${numberOfCards} card(s) for ${otherplayer}'),
'type' => 'activeplayer',
'args' => 'argPlayerGiveCardsBackAfterPicking',
'possibleactions' => ['selectCardsToGiveBack'],
Expand Down
57 changes: 28 additions & 29 deletions velonimo.game.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ protected function getAllDatas() {

// Players
$result['players'] = $this->formatPlayersForClient($this->getPlayersFromDatabase());
// @TODO: support spectator
$result['currentPlayerId'] = $currentPlayerId;
$result['currentPlayerCards'] = $this->formatCardsForClient(
$this->fromBgaCardsToVelonimoCards($this->deck->getCardsInLocation(self::CARD_LOCATION_PLAYER_HAND, $currentPlayerId))
Expand Down Expand Up @@ -340,10 +339,10 @@ function playCards(array $playedCardIds, bool $cardsPlayedWithJersey) {
self::setGameStateValue(self::GAME_STATE_LAST_PLAYED_CARDS_PLAYER_ID, $currentPlayerId);
self::setGameStateValue(self::GAME_STATE_PREVIOUS_PLAYED_CARDS_VALUE, $lastPlayedCardsValue);
self::setGameStateValue(self::GAME_STATE_LAST_PLAYED_CARDS_VALUE, $playedCardsValue);
self::notifyAllPlayers('cardsPlayed', clienttranslate('${playerName} plays ${playedCardsValue}'), [
self::notifyAllPlayers('cardsPlayed', clienttranslate('${player_name} plays ${playedCardsValue}'), [
'playedCardsPlayerId' => $currentPlayerId,
'playedCards' => $this->formatCardsForClient($playedCards),
'playerName' => self::getCurrentPlayerName(),
'player_name' => self::getCurrentPlayerName(),
'playedCardsValue' => $playedCardsValue,
'withJersey' => $cardsPlayedWithJersey,
]);
Expand Down Expand Up @@ -407,8 +406,8 @@ function playCards(array $playedCardIds, bool $cardsPlayedWithJersey) {
function passTurn() {
self::checkAction('passTurn');

self::notifyAllPlayers('turnPassed', clienttranslate('${playerName} passes'), [
'playerName' => self::getCurrentPlayerName(),
self::notifyAllPlayers('turnPassed', clienttranslate('${player_name} passes'), [
'player_name' => self::getCurrentPlayerName(),
]);

$this->gamestate->nextState('nextPlayer');
Expand All @@ -434,9 +433,9 @@ function selectNextPlayer(int $selectedPlayerId) {
$players = $this->getPlayersFromDatabase();
$currentPlayer = $this->getPlayerById($currentPlayerId, $players);
$selectedPlayer = $this->getPlayerById($selectedPlayerId, $players);
self::notifyAllPlayers('nextPlayerSelected', clienttranslate('${playerName} chooses ${selectedPlayerName} as next player'), [
'playerName' => $currentPlayer->getName(),
'selectedPlayerName' => $selectedPlayer->getName(),
self::notifyAllPlayers('nextPlayerSelected', clienttranslate('${player_name} chooses ${player_name2} as next player'), [
'player_name' => $currentPlayer->getName(),
'player_name2' => $selectedPlayer->getName(),
]);

// in order to change the active player during an "activeplayer" type state,
Expand Down Expand Up @@ -491,31 +490,31 @@ function selectPlayerToPickCards(int $selectedPlayerId) {

// notify players
$formattedPickedCards = $this->formatCardsForClient($pickedCards);
$translatedMessage = clienttranslate('${receiverPlayerName} picks ${numberOfCards} cards from ${senderPlayerName} hand');
$translatedMessage = clienttranslate('${player_name} picks ${numberOfCards} card(s) from ${player_name2} hand');
foreach ($players as $player) {
if ($player->getId() === $currentPlayer->getId()) {
self::notifyPlayer($currentPlayer->getId(), 'cardsReceivedFromAnotherPlayer', $translatedMessage, [
'cards' => $formattedPickedCards,
'senderPlayerId' => $selectedPlayer->getId(),
'numberOfCards' => $numberOfCardsToPick,
'receiverPlayerName' => $currentPlayer->getName(),
'senderPlayerName' => $selectedPlayer->getName(),
'player_name' => $currentPlayer->getName(),
'player_name2' => $selectedPlayer->getName(),
]);
} elseif ($player->getId() === $selectedPlayer->getId()) {
self::notifyPlayer($selectedPlayer->getId(), 'cardsSentToAnotherPlayer', $translatedMessage, [
'cards' => $formattedPickedCards,
'receiverPlayerId' => $currentPlayer->getId(),
'numberOfCards' => $numberOfCardsToPick,
'receiverPlayerName' => $currentPlayer->getName(),
'senderPlayerName' => $selectedPlayer->getName(),
'player_name' => $currentPlayer->getName(),
'player_name2' => $selectedPlayer->getName(),
]);
} else {
self::notifyPlayer($player->getId(), 'cardsMovedBetweenTwoOtherPlayers', $translatedMessage, [
'receiverPlayerId' => $currentPlayer->getId(),
'senderPlayerId' => $selectedPlayer->getId(),
'numberOfCards' => $numberOfCardsToPick,
'receiverPlayerName' => $currentPlayer->getName(),
'senderPlayerName' => $selectedPlayer->getName(),
'player_name' => $currentPlayer->getName(),
'player_name2' => $selectedPlayer->getName(),
]);
}
}
Expand Down Expand Up @@ -576,31 +575,31 @@ function selectCardsToGiveBack(array $selectedCardIds) {

// notify players
$formattedSelectedCards = $this->formatCardsForClient($selectedCards);
$translatedMessage = clienttranslate('${senderPlayerName} gives back ${numberOfCards} cards to ${receiverPlayerName}');
$translatedMessage = clienttranslate('${player_name} gives back ${numberOfCards} card(s) to ${player_name2}');
foreach ($players as $player) {
if ($player->getId() === $currentPlayer->getId()) {
self::notifyPlayer($currentPlayer->getId(), 'cardsSentToAnotherPlayer', $translatedMessage, [
'cards' => $formattedSelectedCards,
'receiverPlayerId' => $receiverPlayer->getId(),
'numberOfCards' => $numberOfCardsToGiveBack,
'receiverPlayerName' => $receiverPlayer->getName(),
'senderPlayerName' => $currentPlayer->getName(),
'player_name2' => $receiverPlayer->getName(),
'player_name' => $currentPlayer->getName(),
]);
} elseif ($player->getId() === $receiverPlayer->getId()) {
self::notifyPlayer($receiverPlayer->getId(), 'cardsReceivedFromAnotherPlayer', $translatedMessage, [
'cards' => $formattedSelectedCards,
'senderPlayerId' => $currentPlayer->getId(),
'numberOfCards' => $numberOfCardsToGiveBack,
'receiverPlayerName' => $receiverPlayer->getName(),
'senderPlayerName' => $currentPlayer->getName(),
'player_name2' => $receiverPlayer->getName(),
'player_name' => $currentPlayer->getName(),
]);
} else {
self::notifyPlayer($player->getId(), 'cardsMovedBetweenTwoOtherPlayers', $translatedMessage, [
'receiverPlayerId' => $receiverPlayer->getId(),
'senderPlayerId' => $currentPlayer->getId(),
'numberOfCards' => $numberOfCardsToGiveBack,
'receiverPlayerName' => $receiverPlayer->getName(),
'senderPlayerName' => $currentPlayer->getName(),
'player_name2' => $receiverPlayer->getName(),
'player_name' => $currentPlayer->getName(),
]);
}
}
Expand Down Expand Up @@ -672,7 +671,8 @@ function argPlayerGiveCardsBackAfterPicking() {
return [
'activePlayerId' => (int) self::getActivePlayerId(),
'numberOfCards' => (int) self::getGameStateValue(self::GAME_STATE_LAST_NUMBER_OF_CARDS_TO_GIVE_BACK),
'selectedPlayerName' => $playerToGiveCardsBack->getName(),
'otherplayer' => $playerToGiveCardsBack->getName(),
'otherplayer_id' => $playerToGiveCardsBack->getId(),
];
}

Expand Down Expand Up @@ -802,19 +802,19 @@ function stEndRound() {
// re-allow the jersey to be used
self::setGameStateValue(self::GAME_STATE_JERSEY_HAS_BEEN_USED_IN_THE_CURRENT_ROUND, 0);

self::notifyAllPlayers('roundEnded', 'Round #${currentRound} has been won by ${playerName}', [
self::notifyAllPlayers('roundEnded', 'Round #${currentRound} has been won by ${player_name}', [
'currentRound' => $currentRound,
'playerName' => $winnerOfCurrentRound ? $winnerOfCurrentRound->getName() : 'N/A',
'player_name' => $winnerOfCurrentRound ? $winnerOfCurrentRound->getName() : 'N/A',
'players' => $this->formatPlayersForClient($players),
]);

// notify points earned by each player
foreach ($players as $player) {
$translatedMessage = ($numberOfPointsForRoundByPlayerId[$player->getId()] > 0)
? clienttranslate('${playerName} wins ${points} points')
: clienttranslate('${playerName} does not get any point');
? clienttranslate('${player_name} wins ${points} point(s)')
: clienttranslate('${player_name} does not get any point');
self::notifyAllPlayers('pointsWon', $translatedMessage, [
'playerName' => $player->getName(),
'player_name' => $player->getName(),
'points' => $numberOfPointsForRoundByPlayerId[$player->getId()],
]);
}
Expand Down Expand Up @@ -905,7 +905,6 @@ function stEndRound() {
*/

function zombieTurn($state, $activePlayer) {
// @TODO: zombie
$statename = $state['name'];

if ($state['type'] === 'activeplayer') {
Expand Down
7 changes: 4 additions & 3 deletions velonimo.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@ const PLAYERS_PLACES_BY_NUMBER_OF_PLAYERS = {
},
};

// @TODO: the cards picked/gave for the impacted players should be picked/gave consecutively (dojo.queue?)
// @TODO: show cards in logs (especially the cards picked/gave for the impacted players)
// @TODO: color player names (logs, action messages)
// @TODO: support 2 players game
// @TODO: support "spectators"
// @TODO: support "zombie mode"
// @TODO: ? game rounds topology instead of choosing number of rounds
// @TODO: ? be able to move cards individually in your hand
define([
'dojo','dojo/_base/declare',
'ebg/core/gamegui',
Expand Down Expand Up @@ -643,7 +644,7 @@ function (dojo, declare) {
if (!$(DOM_ID_ACTION_BUTTON_GIVE_CARDS)) {
this.addActionButton(DOM_ID_ACTION_BUTTON_GIVE_CARDS, _('Give selected cards'), () => this.onSelectCardsToGiveBack());
}
dojo.toggleClass(DOM_ID_ACTION_BUTTON_GIVE_CARDS, DOM_CLASS_DISABLED_ACTION_BUTTON, selectedCards.length !== this.howManyCardsToGiveBack);
dojo.toggleClass(DOM_ID_ACTION_BUTTON_GIVE_CARDS, DOM_CLASS_DISABLED_ACTION_BUTTON, (selectedCards.length === 0) || (selectedCards.length !== this.howManyCardsToGiveBack));
},
/**
* @param {function (number, number)} fn such as (color, value) => {...}
Expand Down

0 comments on commit 1e827d3

Please sign in to comment.