bunny game, data paths

14 views
Skip to first unread message

claudio canepa

unread,
Mar 6, 2011, 4:47:21 AM3/6/11
to Gummworld2
1. unpacking the bunny game and running produces a traceback with
Import error: no module paths

Looking at the examples, I added a gamepaths.py with

import os
import sys

progname = sys.argv[0]
progdir = os.path.dirname(progname)
print progdir
sys.path.insert(0, os.path.join(progdir,'gamelib'))

and changed the import paths to import gamepaths
That fixes the exception.

2. then got
File "D:\hg_externals\gummworld2\gamelib
\gummworld2\pygame_utils.py", line 404
, in load_image
raise pygame.error, message
pygame.error: Couldn't open D:\hg_externals\gummworld2\data\image
\grass.bmp

The problem is that the library gummworld2 loads data from a path
relative to ($gummworld2_dir)
So, to workaround this I copied gummworld2 (and pgu just in case)
under
($bunny game dir)\gamelib

That lets the game progress further, but then

3. hud_font = pygame.font.Font(data.filepath('font', 'Vera.ttf'),
10)
IOError: unable to read font filename

Here I copied the font directory that comes with the library under
($gamedir)\data
And that allowed the game to run.

Maybe you can flesh out in similar fashion and reupload the game, that
way potential users can see a working example for the files layout
that gummworld2 expects.

Long term, maybe you can consider to allow an explicit setting for the
data dir, something like:
(in gummworld2\data.py , replacing the implicit form)

path = None
def set_datapaths(data_dir):
global path
path = dict(
font = join_path(data_dir, 'font'),
image = join_path(data_dir, 'image'),
map = join_path(data_dir, 'map'),
plugins = join_path(data_dir, 'plugins'),
sound = join_path(data_dir, 'sound'),
text = join_path(data_dir, 'text'),
theme = join_path(data_dir, 'themes'),
)

and instructs the users to call this early. You can even provide the
recipe for getting the data_dir in the game starter script.

The benefits are:
1. explicit
2. the library placement is not tied to the data placement, you can
switch different library versions with a one line change in a .pth
file
3. keeping at minimum the code that runs at import time is good
practice, it eases unit testing at the very least.

-----

Kudos for the library; seems to pack a good chunk of functionality,
and the examples looks good.

cheers,

--
claudio

B W

unread,
Mar 6, 2011, 5:48:48 PM3/6/11
to gummw...@googlegroups.com
Hi, Claudio.

First of all, let me say thanks for struggling through all of that to make it work. I truly appreciate the challenges, and often frustrations, in trying to get something like a new library or module configured and working. Feedback like yours will help me make better documentation, and improve the library.

I planned to write some how-to's. It looks like you've identified just such an opportunity! :) It had already become obvious I need to add some readmes for the distros.

I thought I had documented installation instructions for the bunny game, but I see it's not included in the game's distro. The cleverly hidden =) "quick help" is on the download page, in the download's description: Unpack Gummworld2 0.1.0, then unpack this bundle into the gummworld2/ root directory. Afterward, you should have gummworld/save_the_bunnies.py and the mini game should simply work.

Please see my other comments mixed in below...

On Sun, Mar 6, 2011 at 1:47 AM, claudio canepa <ccan...@gmail.com> wrote:
1. unpacking the bunny game and running  produces a traceback with
Import error: no module paths

Looking at the examples, I added a gamepaths.py with

import os
import sys

progname = sys.argv[0]
progdir = os.path.dirname(progname)
print progdir
sys.path.insert(0, os.path.join(progdir,'gamelib'))

and changed the import paths to import gamepaths
That fixes the exception.

The directory layout is based on skellington (http://media.pyweek.org/static/skellington-1.9.zip). I wanted the library to lend itself to PyWeek and ease of packaging without any re-configuration. skellington is well organized and has the data.py module, which I've extended for Gummworld2. By design, each individual game should at least have its own program directory under which is data/, gamelib/gummworld2/; and gamelib/pgu/ if you're going to use world_editor.py or use pgu's GUI package in your game.

Along those lines, your start_game.py (or name of your choice) would rest in the program directory. And incidentally, that is where paths.py already is, so the library and data paths are ready to use.

In a nutshell:

  gummworld2/
    data/...
    docs/
    gamelib/gummworld2/
    gamelib/pgu/gui/
    gamelib/...all your game's modules and packages...
    paths.py
    My_Game.py

You may modify paths.py, and gamelib/gummworld2/data.py to suit your purpose.

The data/font/Vera.ttf font file is needed by the ui module, pgu.gui package and Gummworld2 examples.

That just explains the thought behind the organization. Hope it makes sense.
 
2. then got
 File "D:\hg_externals\gummworld2\gamelib
\gummworld2\pygame_utils.py", line 404
, in load_image
   raise pygame.error, message
pygame.error: Couldn't open D:\hg_externals\gummworld2\data\image
\grass.bmp

The problem is that the library gummworld2 loads data from a path
relative to ($gummworld2_dir)
So, to workaround this I copied gummworld2 (and pgu just in case)
under
($bunny game dir)\gamelib

I hadn't intended Gummworld2 to be installed in the system package location or other location. I have had bad experiences getting some games to work, thus I really like the idea of including the dependencies in the distro if they do not add much to the size. I acknowledge that's a personal preference.

Mine is not the only preference. :) As it happens, flexibility is a fundamental goal of Gummworld2. If people want to do this, then I can see the need support it in the API and with documentation.
 
That lets the game progress further, but then

3.     hud_font = pygame.font.Font(data.filepath('font', 'Vera.ttf'),
10)
IOError: unable to read font filename

Here I copied the font directory that comes with the library under
($gamedir)\data
And that allowed the game to run.

Yeah, more fallout from a missing install doc and a limiting design of resource management. I wanted to keep it simple so folks could easily comprehend and hack the data module. But looking ahead, I see you've offered a more elegant suggestion. Also, I like the way pyglet does resource management; I may copy that somewhat.
 
Maybe you can flesh out in similar fashion and reupload the game, that
way potential users can see a working example for the files layout
that gummworld2 expects.

If I understand correctly, you're suggesting to package bunny game and its dependencies. This is a good idea.
 
Long term, maybe you can consider to allow an explicit setting for the
data dir, something like:
(in gummworld2\data.py , replacing the implicit form)

path = None
def set_datapaths(data_dir):
   global path
   path = dict(
       font    = join_path(data_dir, 'font'),
       image   = join_path(data_dir, 'image'),
       map     = join_path(data_dir, 'map'),
       plugins = join_path(data_dir, 'plugins'),
       sound   = join_path(data_dir, 'sound'),
       text    = join_path(data_dir, 'text'),
       theme   = join_path(data_dir, 'themes'),
   )

and instructs the users to call this early. You can even provide the
recipe for getting the data_dir in the game starter script.

The benefits are:
1. explicit
2. the library placement is not tied to the data placement, you can
switch different library versions with a one line change in a .pth
file
3. keeping at minimum the code that runs at import time is good
practice, it eases unit testing at the very least.

I like this idea. I will incorporate it or something like it.
 
-----

Kudos for the library; seems to pack a good chunk of functionality,
and the examples looks good.

cheers,

--
claudio

That is encouraging. Thanks a lot, Claudio. :)

Gumm

claudio canepa

unread,
Mar 8, 2011, 4:41:37 PM3/8/11
to gummw...@googlegroups.com


On Sun, Mar 6, 2011 at 7:48 PM, B W <stabbin...@gmail.com> wrote:
Hi, Claudio.

First of all, let me say thanks for struggling through all of that to make it work. I truly appreciate the challenges, and often frustrations, in trying to get something like a new library or module configured and working. Feedback like yours will help me make better documentation, and improve the library.

I planned to write some how-to's. It looks like you've identified just such an opportunity! :) It had already become obvious I need to add some readmes for the distros.

I thought I had documented installation instructions for the bunny game, but I see it's not included in the game's distro. The cleverly hidden =) "quick help" is on the download page, in the download's description: Unpack Gummworld2 0.1.0, then unpack this bundle into the gummworld2/ root directory. Afterward, you should have gummworld/save_the_bunnies.py and the mini game should simply work.

Please see my other comments mixed in below...
[snipped]

Thanks for the detailed explanation.

--
claudio

Reply all
Reply to author
Forward
0 new messages