Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2011-03-14 21:28:48 (GMT)
committer Walter Bender <walter.bender@gmail.com>2011-03-14 21:28:48 (GMT)
commit86389dec8d09e2e3fd228a735411d377b0aa5f9d (patch)
tree779ae0fc13c2f473d2ae371a410f00b17017ff41
parent36f997b9b587448f1439a89a9f4f5dfd218a42f9 (diff)
sync positions of turtles when joining a share.
-rw-r--r--TurtleArt/tacollaboration.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/TurtleArt/tacollaboration.py b/TurtleArt/tacollaboration.py
index fb97ba7..a48cea6 100644
--- a/TurtleArt/tacollaboration.py
+++ b/TurtleArt/tacollaboration.py
@@ -227,10 +227,12 @@ class Collaboration():
self._get_colors()
event_payload = data_to_string(self._tw.remote_turtle_dictionary)
self.send_event('T|' + event_payload)
+ self._send_my_xy() # And the sender should report her xy position.
def _receive_turtle_dict(self, payload):
''' Any time there is a new joiner, an updated turtle dictionary is
- circulated. '''
+ circulated. Everyone must report their turtle positions so that we
+ are in sync. '''
if self.waiting_for_turtles:
if len(payload) > 0:
# Grab the new remote turtles dictionary.
@@ -253,6 +255,22 @@ class Collaboration():
debug_output('%s already in remote turtle dictionary' \
% (nick), self._tw.running_sugar)
self.waiting_for_turtles = False
+ self._send_my_xy()
+
+ def _send_my_xy(self):
+ ''' Set xy location so joiner can sync turtle positions. '''
+ self._tw.canvas.set_turtle(self._get_nick())
+ if self._tw.canvas.pendown:
+ self.send_event('p|%s' % (data_to_string([self._get_nick(),
+ False])))
+ put_pen_back_down = True
+ else:
+ put_pen_back_down = False
+ self.send_event('x|%s' % (data_to_string([self._get_nick(),
+ [int(self._tw.canvas.xcor), int(self._tw.canvas.ycor)]])))
+ if put_pen_back_down:
+ self.send_event('p|%s' % (data_to_string([self._get_nick(),
+ True])))
def _draw_pixbuf(self, payload):
if len(payload) > 0: