From 4f0083f24f608bf4627fdf0fd8629833116691db Mon Sep 17 00:00:00 2001 From: Alex Levenson Date: Wed, 16 Jul 2008 19:50:38 +0000 Subject: Improved toolbar automation --- diff --git a/physics.py b/physics.py index 5f3c9d6..769de46 100644 --- a/physics.py +++ b/physics.py @@ -22,7 +22,7 @@ from pygame.color import * import olpcgames import elements from elements import Elements -from tools import * +import tools from helpers import * class PhysicsGame: @@ -33,18 +33,11 @@ class PhysicsGame: self.font = pygame.font.Font(None, 24) # font object self.canvas = olpcgames.ACTIVITY.canvas - # setup tools - self.tools = { - "triangle": TriangleTool(self), - "box": BoxTool(self), - "circle": CircleTool(self), - "polygon": PolygonTool(self), - "magicpen": MagicPenTool(self), - "joint": JointTool(self), - "grab": GrabTool(self), - "destroy": DestroyTool(self) - } - self.currentTool = self.tools["triangle"] + # create the name --> instance map for components + self.toolList = {} + for c in tools.allTools: + self.toolList[c.name] = c(self) + self.currentTool = self.toolList[tools.allTools[0].name] # set up the world (instance of Elements) self.world = elements.Elements(self.screen.get_size()) @@ -81,7 +74,7 @@ class PhysicsGame: def setTool(self,tool): self.currentTool.cancel() - self.currentTool = self.tools[tool] + self.currentTool = self.toolList[tool] def main(): toolbarheight = 75 diff --git a/tools.py b/tools.py index 38b3cd6..01f3d83 100644 --- a/tools.py +++ b/tools.py @@ -45,7 +45,7 @@ class Tool(object): # self.game.setTool("gear") elif event.type == USEREVENT: if hasattr(event,"action"): - if self.game.tools.has_key(event.action): self.game.setTool(event.action) + if self.game.toolList.has_key(event.action): self.game.setTool(event.action) elif event.type == MOUSEBUTTONDOWN and event.button == 1: self.game.canvas.grab_focus() handled = False @@ -371,7 +371,7 @@ class JoystickTool(Tool): self.game = gameInstance self.name = "Joystick" self.vertices = None - self.joystickobject + #self.joystickobject def handleEvents(self,event): #look for default events, and if none are handled then try the custom events if not super(JoystickTool,self).handleEvents(event): -- cgit v0.9.1