jkomoros / boardgame

An in-progress framework in golang to easily build boardgame Progressive Web Apps
Apache License 2.0
31 stars 4 forks source link

Allow a game to associate a color with a player in the client #749

Open jkomoros opened 4 years ago

jkomoros commented 4 years ago

Related to #748 .

It should be possible for a game client to use the color associated with a given player in its tempaltes, for example via a CSS var like --player-0-color.

Those colors are currently assigned randomly for players based on a hash of their name. But in some cases there's a very literal color, e.g. the color of the token.

In those cases, the game logic should be able to tell the game what the color is to show in the avatar, and it should show up more proactively, e.g. with a 2px outline border of that color around the picture.

Those colors unfortunately might not be known until some point slightly later in the game, because some games might not assign tokens and colors until after some first phases have been done and tokens have been assigned.

Maybe have a GameDelegate.PlayerColors() which returns an array of colors for each player in order. The engine can call that to see who is which color. (Should we stop calling it once all players have a color, which implies that colors can be set once and never unset, or keep on calling?)

The behaviors.ColorBehavior should automatically interact with that system correctly.

What form should the color be in? It probably makes sense for it to be emitted as a CSS-interpretable string, which would allow colors like 'red', 'green', #FF30AF etc. Should we have a typical color enum that lists common colors that people can choose? But then they'd want a subset of those colors in their actual enum based on which colors are actually legal in their game. Should there be a color table that matches constant name to actual CSS color to allow indirection and more nuanced color pallettes or should it just be literal CSS colors?

jkomoros commented 4 years ago

Note: #752 proposes a much richer model where the color is semantic to the game and tied to group membership. The solution here should be compatible with that.