From 3c8e86e8ed4445457be91f2ebaca49ee0dc4f07b Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Tue, 17 Apr 2012 03:24:01 +0000 Subject: Collaboration: allow multiple users in the same XO This is a workaround to the problem with the real nick on a jabber server[1]. Now, we are using the unique identifier (mesh.my_handle or event.handle) for each player in the game plus a "-%d" at the end of the uid. This value (Player.uid) is added only when the Activity is shared otherwise this field is None. This new workaround allow to distinguish between many users (up to 3) for each XO laptop -using the gamepad keys. [1] http://dev.laptop.org/ticket/10750 Signed-off-by: Manuel Kaufmann Signed-off-by: Rafael Ortiz --- (limited to 'player.py') diff --git a/player.py b/player.py index f02e03a..f9a3452 100644 --- a/player.py +++ b/player.py @@ -22,15 +22,12 @@ # You should have received a copy of the GNU General Public License # along with Maze.activity. If not, see . -from olpcgames.util import get_bundle_path -bundlepath = get_bundle_path() -from sugar.graphics.icon import Icon -from sugar.graphics.xocolor import XoColor import pygame -import re -import os import unicodedata +from olpcgames.util import get_bundle_path +bundlepath = get_bundle_path() + class Player: def __init__(self, buddy, shape='circle'): @@ -39,6 +36,11 @@ class Player: self.nick = unicodedata.normalize('NFC', name) colors = buddy.props.color.split(",") + # this field is None when the activity is not shared and when + # the user shared it this field will become to + # "olpcgames.mesh.my_handle()" + self.uid = None + def string2Color(str): return (int(str[1:3], 16), int(str[3:5], 16), int(str[5:7], 16)) self.colors = map(string2Color, colors) @@ -123,17 +125,19 @@ class Player: self.bonusplayers.append(Player(self.buddy, 'square')) self.bonusplayers.append(Player(self.buddy, 'triangle')) - count = 2 + count = 1 for player in self.bonusplayers: player.nick = self.nick + "-%d" % count + if self.uid is not None: + player.uid = self.uid + "-%d" % count player.hidden = True count += 1 return self.bonusplayers - def bonusPlayer(self, nick): - if nick == self.nick: + def bonusPlayer(self, uid): + if uid == self.uid: return self for bonusplayer in self.bonusPlayers(): - if bonusplayer.nick == nick: + if bonusplayer.uid == uid: return bonusplayer -- cgit v0.9.1