Page 1 of 1

Playername color on background

Posted: 22 October 2020, 21:37
by Volker78
I have a gamestate turn description like this:
${you} must guess: Which of the four words does ${player_name} have?
Unfortunately ${player_name} is not colorized automatically, so I do it manually:

Code: Select all

function argGuess() {
		$players = $this->getPlayers();
		$p = $players[$this->getActivePlayerId()];
		return [
			"active_player_id" => $p["id"],
			"player_name" => '<span style="color:#' . $p["color"] . ';">' . $p["name"] . '</span>',
		];
	}
But this makes problems for example with white color on white backgrounds. BGA already solved this, but is there an API function for this? To compute an optional background color, if needed? That would be nice!

Re: Playername color on background

Posted: 24 October 2020, 05:40
by Victoria_La

Code: Select all

	if (this.gamedatas.players[this.player_id] && this.gamedatas.players[this.player_id].color_back) {
				color_bg = "background-color:#" + this.gamedatas.players[this.player_id].color_back + ";";

			}
(replace this.player_id with player var)

Re: Playername color on background

Posted: 24 October 2020, 14:44
by Volker78
I don't understand. In this gamestate the ${player_name} is NOT the active player (multiplayer gamestate)

Re: Playername color on background

Posted: 24 October 2020, 22:13
by PirateKitten
Try using otherplayer in your description and setting otherplayer (as their name) and otherplayer_id in the args, these will also get picked up and coloured automatically.

Re: Playername color on background

Posted: 25 October 2020, 20:05
by Volker78
I now found that in the studio-js sources, too, this is not documented, right? There I also found an undocumented player-property "color_back", sadly only on client-side.

Re: Playername color on background

Posted: 26 October 2020, 12:32
by PirateKitten
Yes I don't believe it's documented, I found it in the JS source too when looking up how to add a non-active name into the log and have it formatted correctly.