Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/olpcgames/__init__.py
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2012-03-27 13:15:10 (GMT)
committer Rafael Ortiz <rafael@activitycentral.com>2012-03-28 18:05:22 (GMT)
commit335ad73456ba3ec8f56811abddcaca4650199db1 (patch)
treedb788baba57c7656c9bdb73eb9003a70dc87d59a /olpcgames/__init__.py
parent6deeb3f569e6c9a1c02a32a011b7a96a58fa8443 (diff)
Save and restore state of the game
Ability to 'save' (when the user closes the Activity) and 'restore' (when the user launch it from the Journal or the Home without holding Alt) the state of the game. For this ability I had to upgrade 'olpcgames' to 1.6 because 'olpcgames.FILE_READ_REQUEST' and 'olpcgames.FILE_WRITE_REQUEST' events are added in that version and those events are needed for this. The data is saved (as JSON, with json module) in the 'event.metadata["state"]' and the timestamp state is saved in 'event.filename'. This commit solves ticket #2393: * http://bugs.sugarlabs.org/ticket/2393 Signed-off-by: Manuel Kaufmann <humitos@gmail.com> Signed-off-by: Rafael Ortiz <rafael@activitycentral.com>
Diffstat (limited to 'olpcgames/__init__.py')
-rw-r--r--olpcgames/__init__.py96
1 files changed, 78 insertions, 18 deletions
diff --git a/olpcgames/__init__.py b/olpcgames/__init__.py
index 5fd28b7..504388c 100644
--- a/olpcgames/__init__.py
+++ b/olpcgames/__init__.py
@@ -1,6 +1,6 @@
-"""Wrapper/adaptation system for writing/porting PyGame games to OLPC/Sugar
+"""Wrapper/adaptation system for writing/porting Pygame games to OLPC/Sugar
-The wrapper system attempts to substitute various pieces of the PyGame
+The wrapper system attempts to substitute various pieces of the Pygame
implementation in order to make code written without knowledge of the
OLPC/Sugar environment run "naturally" under the GTK environment of
Sugar. It also provides some convenience mechanisms for dealing with
@@ -8,9 +8,9 @@ e.g. the Camera and Mesh Network system.
Considerations for Developers:
-PyGame programs running under OLPCGames will generally not have
+Pygame programs running under OLPCGames will generally not have
"hardware" surfaces, and will not be able to have a reduced-resolution
-full-screen view to optimise rendering. The PyGame code will run in
+full-screen view to optimise rendering. The Pygame code will run in
a secondary thread, with the main GTK UI running in the primary thread.
A third "mainloop" thread will occasionally be created to handle the
GStreamer interface to the camera.
@@ -22,21 +22,81 @@ Attributes of Note:
WIDGET -- PygameCanvas instance, a GTK widget with an embedded
socket object which is a proxy for the SDL window Pygame to which
pygame renders.
+
+ Constants: All event constants used by the package are defined at this
+ level. Note that eventually we will need to switch to using UserEvent
+ and making these values sub-types rather than top-level types.
+
+
+Pygame events at the Activity Level:
+
+ pygame.USEREVENT
+ code == olpcgames.FILE_READ_REQUEST
+ filename (unicode/string) -- filename from which to read
+ metadata (dictionary-like) -- mapping from key to string values
+
+ Note: due to a limitation in the Sugar API, the GTK event loop
+ will be *frozen* during this operation, as a result you cannot
+ make any DBUS or GTK calls, nor can you use GUI during the
+ call to provide input. That is, you have to process this event
+ synchronously.
+
+ code == olpcgames.FILE_WRITE_REQUEST
+ filename (unicode/string) -- file name to which to write
+ metadata (dictionary-like) -- mapping from key: value where all
+ values must (currently) be strings
+
+ Note: due to a limitation in the Sugar API, the GTK event loop
+ will be *frozen* during this operation, as a result you cannot
+ make any DBUS or GTK calls, nor can you use GUI during the
+ call to provide input. That is, you have to process this event
+ synchronously.
+
+see also the mesh and camera modules for more events.
+
+Deprecated:
+
+ This module includes the activity.PyGameActivity class currently,
+ this is a deprecated mechanism for accessing the activity class,
+ and uses the deprecated spelling (case) of the name. Use:
+
+ from olpcgames import activity
+
+ class MyActivity( activity.PygameActivity ):
+ ...
+
+ to define your PygameActivity subclass (note the case of the
+ spelling, which now matches Pygame's own spelling).
"""
-# XXX handle configurations that are not running under Sugar and
-# report proper errors to describe the problem, rather than letting the
-# particular errors propagate outward.
-# XXX allow use of a particular feature within the library without needing
-# to be running under sugar. e.g. allow importing mesh or camera without
-# needing to import the activity machinery.
-from olpcgames.canvas import *
+from olpcgames._version import __version__
+ACTIVITY = None
+widget = WIDGET = None
+
+# XXX problem here, we're filling up the entirety of the Pygame
+# event-set with just this small bit of functionality, obviously
+# Pygame is not intending for this kind of usage!
+(
+ CAMERA_LOAD, CAMERA_LOAD_FAIL,
+
+ CONNECT,PARTICIPANT_ADD,
+ PARTICIPANT_REMOVE,
+ MESSAGE_UNI,MESSAGE_MULTI,
+) = range( 25, 32 )
+
+# These events use UserEvent.code, eventually *all* events should be
+# delivered as UserEvent with code set to the values defined here...
+
+(
+ #NET_CONNECT, NET_PARTICIPANT_ADD,NET_PARTICIPANT_REMOVE,
+ #NET_MESSAGE_UNICAST, NET_MESSAGE_MULTICAST,
+ #CAMERA_LOAD, CAMERA_LOAD_FAIL,
+ FILE_READ_REQUEST, FILE_WRITE_REQUEST,
+) = range(
+ 2**16, 2**16+2,
+)
+
try:
- from olpcgames.activity import *
+ from olpcgames.activity import PygameActivity as PyGameActivity
except ImportError, err:
- PyGameActivity = None
-from olpcgames import camera
-from olpcgames import pangofont
-from olpcgames import mesh
+ PyGameActivity = None
-ACTIVITY = None
-widget = WIDGET = None