Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2014-01-31 02:14:51 (GMT)
committer Walter Bender <walter@sugarlabs.org>2014-01-31 02:14:51 (GMT)
commit0a23008116995aab2c113b6540a528b43027abed (patch)
tree799e513f19d3b9758f3fbb67d007550bbeaf6e73
parent44a008996d1683ed09c165d56c760587e2930316 (diff)
add sharing to polygons and magic pen
-rw-r--r--NEWS4
-rw-r--r--activity.py20
-rwxr-xr-xactivity/activity.info2
-rw-r--r--elements/add_objects.py8
-rw-r--r--helpers.py9
-rw-r--r--po/es.po113
-rw-r--r--tools.py114
7 files changed, 146 insertions, 124 deletions
diff --git a/NEWS b/NEWS
index 88dd214..8c760c4 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+16
+
+* Clean up of some internals
+
15
ENHANCEMENT:
diff --git a/activity.py b/activity.py
index 77e071f..3238d52 100644
--- a/activity.py
+++ b/activity.py
@@ -523,6 +523,8 @@ class PhysicsActivity(activity.Activity):
dispatch_table = {'C': self._construct_shared_circle,
'B': self._construct_shared_box,
'T': self._construct_shared_triangle,
+ 'P': self._construct_shared_polygon,
+ 'M': self._construct_shared_magicpen,
'j': self._add_shared_joint,
'p': self._add_shared_pin,
'm': self._add_shared_motor,
@@ -562,6 +564,24 @@ class PhysicsActivity(activity.Activity):
self._constructors['Triangle'](pos1, pos2, density, restitution,
friction, share=False)
+ def _construct_shared_polygon(self, data):
+ polygon_data = json.loads(data)
+ verticies = polygon_data[0]
+ density = polygon_data[1]
+ restitution = polygon_data[2]
+ friction = polygon_data[3]
+ self._constructors['Polygon'](verticies, density, restitution,
+ friction, share=False)
+
+ def _construct_shared_magicpen(self, data):
+ magicpen_data = json.loads(data)
+ verticies = magicpen_data[0]
+ density = magicpen_data[1]
+ restitution = magicpen_data[2]
+ friction = magicpen_data[3]
+ self._constructors['Magicpen'](verticies, density, restitution,
+ friction, share=False)
+
def _add_shared_joint(self, data):
joint_data = json.loads(data)
pos1 = joint_data[0]
diff --git a/activity/activity.info b/activity/activity.info
index b9f346b..2946b51 100755
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -4,6 +4,6 @@ summary = Prove Sir Isaac Newton right! Create real life simulations using diffe
bundle_id = org.laptop.physics
exec = sugar-activity activity.PhysicsActivity
icon = activity-physics
-activity_version = 15
+activity_version = 16
show_launcher = yes
mime_types = application/x-physics-activity;
diff --git a/elements/add_objects.py b/elements/add_objects.py
index 1ed35e0..bfb7e0b 100644
--- a/elements/add_objects.py
+++ b/elements/add_objects.py
@@ -390,14 +390,14 @@ class Add:
if tools_poly.is_line(vertices):
# Lines shall be drawn by self.concavePoly(...)
- print "is line"
+ # print "is line"
is_convex = False
if is_convex:
- print "convex"
+ # print "convex"
return self.convexPoly(vertices, dynamic, density, restitution, friction), vertices
else:
- print "concave"
+ # print "concave"
return self.concavePoly(vertices, dynamic, density, restitution, friction), vertices
@@ -421,7 +421,7 @@ class Add:
tolerance += 1
v_new = tools_poly.reduce_poly(vertices, tolerance)
- print "convexPoly: Polygon reduced from %i to %i vertices | tolerance: %i" % (len(vertices), len(v_new), tolerance)
+ # print "convexPoly: Polygon reduced from %i to %i vertices | tolerance: %i" % (len(vertices), len(v_new), tolerance)
vertices = v_new
# So poly should be alright now
diff --git a/helpers.py b/helpers.py
index 65b07cd..2f4b6f1 100644
--- a/helpers.py
+++ b/helpers.py
@@ -163,3 +163,12 @@ def tuple_to_int(tuple_input):
"""Cast tuple values to ints to avoid gtk+ and pygame's dislike of floats.
"""
return [int(i) for i in tuple_input]
+
+
+def find_body(world, pos):
+ body = world.get_bodies_at_pos(tuple_to_int(pos))
+ if isinstance(body, list) and len(body) > 0:
+ return body[0]
+ else:
+ return None
+
diff --git a/po/es.po b/po/es.po
index 1d52926..bec982d 100644
--- a/po/es.po
+++ b/po/es.po
@@ -158,8 +158,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-12-12 00:31-0500\n"
-"PO-Revision-Date: 2013-12-13 04:41+0200\n"
+"POT-Creation-Date: 2014-01-13 00:31-0500\n"
+"PO-Revision-Date: 2014-01-20 00:43+0200\n"
"Last-Translator: AlanJAS <alanjas@hotmail.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: es\n"
@@ -176,152 +176,165 @@ msgstr "Física"
#. TRANS: "summary" option from activity.info file
#. TRANS: "description" option from activity.info file
msgid ""
-"Prove Sir Issac Newton right! Create real life simulations using different "
+"Prove Sir Isaac Newton right! Create real life simulations using different "
"shapes and see them come to life with forces!"
msgstr ""
"¡Comprueba que Isaac Newton tenía razón! Crea simulaciones de la vida real "
"usando las diferentes formas y viendo como cobran vida con las fuerzas."
-#: activity.py:123
+#: activity.py:124
msgid "Create"
msgstr "Crear"
-#: activity.py:151 activity.py:157
-#, fuzzy
+#: activity.py:135
+msgid "Clear Trace Marks"
+msgstr "Limpiar Marcas de Trazo"
+
+#: activity.py:136
+msgid "<ctrl>x"
+msgstr "<ctrl>x"
+
+#: activity.py:161 activity.py:167
msgid "Export tracked objects to journal"
msgstr "Exportar objetos al Diario"
-#: activity.py:175 activity.py:228
+#: activity.py:185 activity.py:293
msgid "Stop"
msgstr "Detener"
-#: activity.py:176
+#: activity.py:186
msgid "<ctrl>space"
msgstr "<ctrl>Espacio"
-#: activity.py:183
+#: activity.py:193
msgid "Erase All"
msgstr "Borrar todo"
-#: activity.py:184
+#: activity.py:194
msgid "<ctrl>a"
msgstr "<ctrl>a"
-#: activity.py:231
-msgid "Start"
-msgstr "Avanzar"
-
-#: activity.py:241
+#: activity.py:280 activity.py:307
msgid "Are You Sure?"
msgstr "¿Estás seguro?"
-#: activity.py:243
+#: activity.py:282
+msgid "All trace points will be erased. This cannot be undone!"
+msgstr "Todos los puntos trazados serán borrados. ¡Ésto no puede deshacerse!"
+
+#: activity.py:296
+msgid "Start"
+msgstr "Avanzar"
+
+#: activity.py:309
msgid "All your work will be discarded. This cannot be undone!"
msgstr "Todo tu trabajo será descartado. ¡Esto no se puede deshacer!"
-#: activity.py:267 activity.py:284
+#: activity.py:333 activity.py:350
msgid "Physics export"
msgstr "Exportar Física"
-#: tools.py:109
+#: tools.py:167
msgid "Circle"
msgstr "Círculo"
-#: tools.py:110
+#: tools.py:168
msgid "<ctrl>c"
msgstr "<ctrl>c"
-#: tools.py:150
+#: tools.py:215
msgid "Box"
msgstr "Bloque"
-#: tools.py:151
+#: tools.py:216
msgid "<ctrl>b"
msgstr "<ctrl>b"
-#: tools.py:203
+#: tools.py:274
msgid "Triangle"
msgstr "Triángulo"
-#: tools.py:204
+#: tools.py:275
msgid "<ctrl>t"
msgstr "<ctrl>t"
-#: tools.py:273
+#: tools.py:350
msgid "Polygon"
msgstr "Polígono"
-#: tools.py:274
+#: tools.py:351
msgid "<ctrl>p"
msgstr "<ctrl>p"
-#: tools.py:349
+#: tools.py:436
msgid "Draw"
msgstr "Dibujar"
-#: tools.py:350
+#: tools.py:437
msgid "<ctrl>d"
msgstr "<ctrl>d"
-#: tools.py:406
+#: tools.py:499
msgid "Grab"
msgstr "Agarrar"
-#: tools.py:407
+#: tools.py:500
msgid "<ctrl>g"
msgstr "<ctrl>g"
-#: tools.py:456
+#: tools.py:549
msgid "Joint"
msgstr "Unión"
-#: tools.py:504
+#: tools.py:597
msgid "Pin"
msgstr "Tachuela"
-#: tools.py:505
+#: tools.py:598
msgid "<ctrl>o"
msgstr "<ctrl>o"
-#: tools.py:529
+#: tools.py:622
msgid "Motor"
msgstr "Motor"
-#: tools.py:530
+#: tools.py:623
msgid "<ctrl>m"
msgstr "<ctrl>m"
-#: tools.py:555
+#: tools.py:667
msgid "Roll"
msgstr "Rodar"
-#: tools.py:556 tools.py:674
+#: tools.py:668 tools.py:751
msgid "<ctrl>r"
msgstr "<ctrl>r"
-#: tools.py:582
+#: tools.py:694
msgid "Erase"
msgstr "Borrar"
-#: tools.py:583
+#: tools.py:695
msgid "<ctrl>e"
msgstr "<ctrl>e"
-#: tools.py:624
-msgid "Erase all"
-msgstr "Borrar todo"
+#: tools.py:750
+msgid "Track Object"
+msgstr "Seguir Objeto"
-#: tools.py:637
-msgid "Delete all shapes?"
-msgstr "¿Borrar todas las formas?"
+#: tools.py:800
+msgid "Chain"
+msgstr "Cadena"
-#: tools.py:638
-msgid "This can't be undone!"
-msgstr "¡Esto no puede ser revertido!"
+#~ msgid "Erase all"
+#~ msgstr "Borrar todo"
-#: tools.py:673
-msgid "Track Object"
-msgstr "Seguir Objeto"
+#~ msgid "Delete all shapes?"
+#~ msgstr "¿Borrar todas las formas?"
+
+#, fuzzy
+#~ msgid "This cannot be undone!"
+#~ msgstr "¡Esto no puede ser revertido!"
#, python-format
#~ msgid "%s Source"
diff --git a/tools.py b/tools.py
index 8e6e76f..0ba305d 100644
--- a/tools.py
+++ b/tools.py
@@ -409,9 +409,8 @@ class PolygonTool(Tool):
self.vertices = [[i[0] - delta_x, i[1] - delta_y]
for i in self.previous_vertices]
self.safe = True
- self.game.world.add.complexPoly(
+ self.constructor(
self.vertices,
- dynamic=True,
density=self.palette_data['density'],
restitution=self.palette_data['restitution'],
friction=self.palette_data['friction'])
@@ -427,9 +426,8 @@ class PolygonTool(Tool):
if distance(tuple_to_int(event.pos), self.vertices[0]) < 15 \
and self.safe:
self.vertices.append(self.vertices[0]) # Connect polygon
- self.game.world.add.complexPoly(
+ self.constructor(
self.vertices,
- dynamic=True,
density=self.palette_data['density'],
restitution=self.palette_data['restitution'],
friction=self.palette_data['friction'])
@@ -443,6 +441,16 @@ class PolygonTool(Tool):
self.vertices[0]) > 54:
self.safe = True
+ def constructor(self, vertices, density, restitution, friction,
+ share=True):
+ self.game.world.add.complexPoly(vertices, dynamic=True,
+ density=density,
+ restitution=restitution,
+ friction=friction)
+ if share and self.game.activity.we_are_sharing:
+ data = json.dumps([vertices, density, restitution, friction])
+ self.game.activity.send_event('P:' + data)
+
def draw(self):
Tool.draw(self)
# Draw the poly being created
@@ -492,8 +500,8 @@ class MagicPenTool(Tool):
for i in self.previous_vertices]
self.safe = True
if self.vertices and self.safe:
- self.game.world.add.complexPoly(
- self.vertices, dynamic=True,
+ self.constructor(
+ self.vertices,
density=self.palette_data['density'],
restitution=self.palette_data['restitution'],
friction=self.palette_data['friction'])
@@ -505,6 +513,16 @@ class MagicPenTool(Tool):
len(self.vertices) > 3:
self.safe = True
+ def constructor(self, vertices, density, restitution, friction,
+ share=True):
+ self.game.world.add.complexPoly(vertices, dynamic=True,
+ density=density,
+ restitution=restitution,
+ friction=friction)
+ if share and self.game.activity.we_are_sharing:
+ data = json.dumps([vertices, density, restitution, friction])
+ self.game.activity.send_event('M:' + data)
+
def draw(self):
Tool.draw(self)
# Draw the poly being created
@@ -590,8 +608,7 @@ class JointTool(Tool):
if event.button >= 1:
# Grab the first body
self.jb1pos = tuple_to_int(event.pos)
- self.jb1 = self.game.world.get_bodies_at_pos(
- tuple_to_int(event.pos))
+ self.jb1 = find_body(self.game.world, event.pos)
self.jb2pos = None
elif event.type == MOUSEBUTTONUP:
if event.button == 1:
@@ -607,19 +624,8 @@ class JointTool(Tool):
self.jb1 = self.jb1pos = self.jb2pos = None
def constructor(self, pos1, pos2, share=True):
- current_bodies = self.game.world.get_bodies_at_pos(pos1)
- if current_bodies is not None and current_bodies and \
- len(current_bodies) > 0:
- body1 = current_bodies[0]
- else:
- body1 = None
- current_bodies = self.game.world.get_bodies_at_pos(pos2)
- if current_bodies is not None and current_bodies and \
- len(current_bodies) > 0:
- body2 = current_bodies[0]
- else:
- body2 = None
-
+ body1 = find_body(self.game.world, pos1)
+ body2 = find_body(self.game.world, pos2)
if body1 is None or body2 is None:
return
@@ -654,18 +660,13 @@ class PinTool(Tool):
Tool.handleToolEvent(self, event)
if event.type == MOUSEBUTTONDOWN:
self.jb1pos = tuple_to_int(event.pos)
- self.jb1 = self.game.world.get_bodies_at_pos(
- tuple_to_int(event.pos))
- if self.jb1:
+ self.jb1 = find_body(self.game.world, event.pos)
+ if self.jb1 is not None:
self.constructor(self.jb1pos)
self.jb1 = self.jb1pos = None
def constructor(self, pos, share=True):
- current_bodies = self.game.world.get_bodies_at_pos(pos)
- if current_bodies is None or not current_bodies or \
- len(current_bodies) == 0:
- return
- body = current_bodies[0]
+ body = find_body(self.game.world, pos)
self.game.world.add.joint(body, pos)
if share and self.game.activity.we_are_sharing:
@@ -709,18 +710,13 @@ class MotorTool(Tool):
if event.button >= 1:
# Grab the first body
self.jb1pos = tuple_to_int(event.pos)
- self.jb1 = self.game.world.get_bodies_at_pos(
- tuple_to_int(event.pos))
- if self.jb1:
+ self.jb1 = find_body(self.game.world, event.pos)
+ if self.jb1 is not None:
self.constructor(self.jb1pos, self.palette_data['speed'])
self.jb1 = self.jb1pos = None
def constructor(self, pos, speed, share=True):
- current_bodies = self.game.world.get_bodies_at_pos(pos)
- if current_bodies is None or not current_bodies or \
- len(current_bodies) == 0:
- return
- body = current_bodies[0]
+ body = find_body(self.game.world, pos)
self.game.world.add.motor(body, pos, speed=speed)
if share and self.game.activity.we_are_sharing:
@@ -746,8 +742,8 @@ class RollTool(Tool):
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
self.jb1pos = tuple_to_int(event.pos)
- self.jb1 = self.game.world.get_bodies_at_pos(self.jb1pos)
- if self.jb1 and isinstance(self.jb1[0].userData, dict):
+ self.jb1 = find_body(self.game.world, event.pos)
+ if self.jb1 is not None:
self.jb1[0].userData['rollMotor'] = {}
self.jb1[0].userData['rollMotor']['targetVelocity'] = -10
self.jb1[0].userData['rollMotor']['strength'] = 40
@@ -777,9 +773,8 @@ class DestroyTool(Tool):
if len(self.vertices) > 10:
self.vertices.pop(0)
- tokill = self.game.world.get_bodies_at_pos(tuple_to_int(event.pos))
-
- if tokill:
+ tokill = find_body(self.game.world, event.pos)
+ if tokill is not None:
tracklist = self.game.trackinfo.items()
destroyed_body = False
for key, info in tracklist:
@@ -829,10 +824,8 @@ class TrackTool(Tool):
Tool.handleToolEvent(self, event)
if pygame.mouse.get_pressed()[0]:
- current_body = self.game.world.get_bodies_at_pos(
- tuple_to_int(event.pos))
- if current_body:
- body = current_body[0]
+ body = find_body(self.game.world, event.pos)
+ if body is not None:
color = body.userData['color']
point_pos = tuple_to_int(event.pos)
self.constructor(point_pos, color)
@@ -844,11 +837,7 @@ class TrackTool(Tool):
self.added_badge = True
def constructor(self, pos, color, share=True):
- current_bodies = self.game.world.get_bodies_at_pos(pos)
- if current_bodies is None or not current_bodies or \
- len(current_bodies) == 0:
- return
- body = current_bodies[0]
+ body = find_body(self.game.world, pos)
track_circle = self.game.world.add.ball(
pos, self.radius, dynamic=True, density=0.001,
restitution=0.16, friction=0.1)
@@ -920,7 +909,7 @@ class ChainTool(Tool):
if event.button >= 1:
# Find body 1
self._pos_1 = tuple_to_int(event.pos)
- self._body_1 = self._find_body(event.pos)
+ self._body_1 = find_body(self.game.world, event.pos)
if self._body_1 is None:
self._clear()
return
@@ -936,17 +925,11 @@ class ChainTool(Tool):
self.constructor(self._pos_1, self._pos_2, link_length, radius)
def constructor(self, pos1, pos2, link_length, radius, share=True):
- current_bodies = self.game.world.get_bodies_at_pos(pos1)
- if current_bodies is not None and current_bodies and \
- len(current_bodies) > 0:
- body1 = current_bodies[0]
- else:
+ body1 = find_body(self.game.world, pos1)
+ if body1 is None:
return
- current_bodies = self.game.world.get_bodies_at_pos(pos2)
- if current_bodies is not None and current_bodies and \
- len(current_bodies) > 0:
- body2 = current_bodies[0]
- else:
+ body2 = find_body(self.game.world, pos2)
+ if body2 is None:
body2 = self.game.world.add.ball(
pos2, radius, dynamic=True, density=1.0, restitution=0.16,
friction=0.1)
@@ -1003,13 +986,6 @@ class ChainTool(Tool):
self._clear()
- def _find_body(self, pos):
- body = self.game.world.get_bodies_at_pos(tuple_to_int(pos))
- if isinstance(body, list) and len(body) > 0:
- return body[0]
- else:
- return None
-
def getAllTools():
return [MagicPenTool,