Display avatar "in game"

Game development with Board Game Arena Studio
Post Reply
User avatar
Draasill
Posts: 197
Joined: 26 April 2020, 00:00

Display avatar "in game"

Post 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);
User avatar
Lymon Flowers
Posts: 196
Joined: 01 April 2020, 21:14

Re: Display avatar "in game"

Post 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).
User avatar
Draasill
Posts: 197
Joined: 26 April 2020, 00:00

Re: Display avatar "in game"

Post 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.
User avatar
Draasill
Posts: 197
Joined: 26 April 2020, 00:00

Re: Display avatar "in game"

Post by Draasill »

Well I hope it's OK, the result is very cool, having player avatars around a card game :)
User avatar
Draasill
Posts: 197
Joined: 26 April 2020, 00:00

Re: Display avatar "in game"

Post 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;
	}
User avatar
docthib
Posts: 73
Joined: 10 August 2015, 14:05

Re: Display avatar "in game"

Post 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
User avatar
Draasill
Posts: 197
Joined: 26 April 2020, 00:00

Re: Display avatar "in game"

Post 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 !
User avatar
docthib
Posts: 73
Joined: 10 August 2015, 14:05

Re: Display avatar "in game"

Post by docthib »

Yeah I understand, that's a workaround, but as there are no "stable" way to do it :)
Post Reply

Return to “Developers”