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

Add Players enum class with special values #1370

Open
micahstairs opened this issue Oct 1, 2023 · 0 comments
Open

Add Players enum class with special values #1370

micahstairs opened this issue Oct 1, 2023 · 0 comments
Labels
backend .php or .sql tech debt Something that doesn't necessarily need to be done now, but it may make future changes harder to do.

Comments

@micahstairs
Copy link
Owner

I'd love a Players class with constants like ALL, OPPONENTS, OTHERS, etc.

It would allow us to simplify code like:

$cards = [];
foreach (self::getPlayerIds() as $playerId) {
  $cards = array_merge($cards, self::getCards(Locations::SCORE, $playerId));
}

to

$cards = self::getCards(Locations::SCORE, Players::ALL);

It would also help us clean up code like:

if ($owner == -2) { // any player
            $owner_condition = "owner != 0 AND";
        } else if ($owner == -3) { // any opponent
            $opponent_ids = self::getActiveOpponentIds(self::getActivePlayerId());
            $owner_condition = self::format("owner IN ({owners}) AND", array('owners' => join(',', $opponent_ids)));
        } else if ($owner == -4) { // any other player
            $owner_condition = self::format("owner != 0 AND owner != {player_id} AND", array('player_id' => self::getActivePlayerId()));
        } else {
            $owner_condition = self::format("owner = {owner} AND", array('owner' => $owner));
        }
@micahstairs micahstairs added tech debt Something that doesn't necessarily need to be done now, but it may make future changes harder to do. backend .php or .sql labels Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend .php or .sql tech debt Something that doesn't necessarily need to be done now, but it may make future changes harder to do.
Projects
None yet
Development

No branches or pull requests

1 participant