From 9674738abc8984d15b55418e52718ac28669cc7d Mon Sep 17 00:00:00 2001 From: Daniel Francis Date: Fri, 21 Dec 2012 14:18:54 +0000 Subject: Activity completely ported to sugargame with no regressions Signed-off-by: Daniel Francis --- diff --git a/activity.py b/activity.py index 764470b..3a97890 100644 --- a/activity.py +++ b/activity.py @@ -37,8 +37,6 @@ except ImportError: # <= 0.84 toolbars pass -import olpcgamesutil - class PhysicsActivity(activity.Activity): def __init__(self, handle): @@ -60,18 +58,10 @@ class PhysicsActivity(activity.Activity): self._canvas.run_pygame(self.game.run) def read_file(self, file_path): - event = pygame.event.Event(pygame.USEREVENT) - event.code = olpcgamesutil.FILE_READ_REQUEST - event.filename = file_path - event.metadata = self.metadata - self._canvas.translator._post(event) + self.game.read_file(file_path) def write_file(self, file_path): - event = pygame.event.Event(pygame.USEREVENT, - code = olpcgamesutil.FILE_WRITE_REQUEST, - filename = file_path, - metadata = self.metadata) - self.canvas.translator._post(event) + self.game.write_file(file_path) def get_preview(self): """Custom preview code to get image from pygame. diff --git a/olpcgamesutil.py b/olpcgamesutil.py deleted file mode 100644 index 54f9526..0000000 --- a/olpcgamesutil.py +++ /dev/null @@ -1,3 +0,0 @@ -# This is part of olpcgames - -(FILE_READ_REQUEST, FILE_WRITE_REQUEST) = range(2**16, 2**16+2) diff --git a/physics.py b/physics.py index 18aa7eb..5f80527 100644 --- a/physics.py +++ b/physics.py @@ -55,6 +55,7 @@ class PhysicsGame: self.currentTool = self.toolList[tools.allTools[0].name] # Set up the world (instance of Elements) self.box2d = box2d + self.opening_queue = None def switch_off_fake_pygame_cursor_cb(self, panel, event): self.show_fake_cursor = False @@ -62,6 +63,15 @@ class PhysicsGame: def switch_on_fake_pygame_cursor_cb(self, panel, event): self.show_fake_cursor = True + def write_file(self, path): + #Saving to journal + self.world.add.remove_mouseJoint() + self.world.json_save(path) + + def read_file(self, path): + #Loading from journal + self.opening_queue = path + def run(self): self.screen = pygame.display.get_surface() pygame.display.init() @@ -88,6 +98,9 @@ class PhysicsGame: while gtk.events_pending(): gtk.main_iteration() + if self.opening_queue: + self.world.json_load(self.opening_queue) + for event in pygame.event.get(): self.currentTool.handleEvents(event) if event.type == MOUSEBUTTONUP: diff --git a/tools.py b/tools.py index adb08ff..358e1fe 100644 --- a/tools.py +++ b/tools.py @@ -23,7 +23,6 @@ #================================================================== import pygame import sugargame -import olpcgamesutil from pygame.locals import * from helpers import * from inspect import getmro @@ -56,14 +55,6 @@ class Tool(object): self.game.in_focus = False elif self.game.toolList.has_key(event.action): self.game.setTool(event.action) - elif hasattr(event, "code"): - if event.code == olpcgamesutil.FILE_WRITE_REQUEST: - #Saving to journal - self.game.world.add.remove_mouseJoint() - self.game.world.json_save(event.filename) - elif event.code == olpcgamesutil.FILE_READ_REQUEST: - #Loading from journal - self.game.world.json_load(event.filename) elif event.type == MOUSEBUTTONDOWN and event.button == 1: self.game.canvas.grab_focus() handled = False -- cgit v0.9.1