Page 1 of 1

Display avatar "in game"

Posted: 12 May 2020, 13:59
by Draasill
Hi,

on the game I'm working on (coinche) I suppose it would be nice to display the avatars on the game table itself.

Is it OK ? I found nothing about this in the BGA game design page.

Is it feasible in a correct way (data taken from the players array) ?

----

Edit: using "get_avatar_filename" is the correct way now :

Code: Select all

// With $size being 32,50, 92 or 184
$avatar_url = get_avatar_filename($player_id, $player_avatar, $size);

Re: Display avatar "in game"

Posted: 12 May 2020, 17:06
by Lymon Flowers
I would say, use :

https://x.boardgamearena.net/data/avata ... FGH_XY.jpg

Where ABCDEFGH is the player ID and XY the size you need (at least 184 and 50 are available).

Re: Display avatar "in game"

Posted: 12 May 2020, 18:05
by Draasill
Thank you !

I did see that (32 is available too) but I've not seen any game using them, so I hope it doesn't go against the rules/design guidelines.

Re: Display avatar "in game"

Posted: 18 May 2020, 11:40
by Draasill
Well I hope it's OK, the result is very cool, having player avatars around a card game :)

Re: Display avatar "in game"

Posted: 10 June 2020, 13:11
by Draasill
Edit: using "get_avatar_filename" is the correct way now :

Code: Select all

// With $size being 32,50, 92 or 184
$avatar_url = get_avatar_filename($player_id, $player_avatar, $size);
----

Ok, there seems to be some differences when the user id is 'older' (depending on the number of digits).

I'd love to have an admin confirmation, but here is the method i'll use now :

Code: Select all

	private function getPlayerAvatar($player, $size) {
		$avatarPlayerId = (string) $player['player_id'];

		// Zero means "0", otherwise, length of the string from the start
		$lengthMap = [
			8 => [0, 2, 5],
			7 => [0, 1, 4],
			6 => [0, 0, 3],
			5 => [0, 0, 1], // ? no case found
			4 => [0, 0, 1],
			3 => [0, 0, 0],
			2 => [0, 0, 0],
			1 => [0, 0, 0],
		];

		$length = strlen($avatarPlayerId);
		if (!isset($lengthMap[$length])) {
			return null;
		}
		$len0 = $lengthMap[$length][0];
		$len1 = $lengthMap[$length][1];
		$len2 = $lengthMap[$length][2];

		$avatarUrl = sprintf(
			'https://x.boardgamearena.net/data/avatar/%s/%s/%s/%s_%s.jpg?h=%s',
			$len0 === 0 ? '0' : substr($avatarPlayerId, 0, $len0),
			$len1 === 0 ? '0' : substr($avatarPlayerId, 0, $len1),
			$len2 === 0 ? '0' : substr($avatarPlayerId, 0, $len2),
			$avatarPlayerId,
			$size,
			$player['player_avatar']
		);

		return $avatarUrl;
	}

Re: Display avatar "in game"

Posted: 11 June 2020, 09:02
by docthib
Why not simply copy the avatar from player panel in JS?

Code: Select all

for (let playerId in gamedatas.players) {
    // (assuming the 'new_game_avatar_x' is an <img> tag)
    document.getElementById('new_game_avatar_' + playerId).src = document.getElementById('avatar_' + playerId).src;
}
Works pretty well

Re: Display avatar "in game"

Posted: 11 June 2020, 10:41
by Draasill
That's a good idea indeed, although I don't like depending on the UI, which can theoretically change any time.

I already do this to observe preferences changes, no choice here but I don't like it at all !

Re: Display avatar "in game"

Posted: 11 June 2020, 11:46
by docthib
Yeah I understand, that's a workaround, but as there are no "stable" way to do it :)