Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/player.py
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2012-04-17 03:24:01 (GMT)
committer Rafael Ortiz <rafael@activitycentral.com>2012-04-20 16:10:58 (GMT)
commit3c8e86e8ed4445457be91f2ebaca49ee0dc4f07b (patch)
tree3da5e04e3ef4b0f8dd8a289de9d1be1dfd8bc4fd /player.py
parentd4ab2f7d2db24319de36b29e455f7d30c3f8a90c (diff)
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 <humitos@gmail.com> Signed-off-by: Rafael Ortiz <rafael@activitycentral.com>
Diffstat (limited to 'player.py')
-rw-r--r--player.py24
1 files changed, 14 insertions, 10 deletions
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 <http://www.gnu.org/licenses/>.
-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