Changeset 303:e12d99215b74


Ignore:
Timestamp:
Sep 5, 2009, 5:35:17 PM (11 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@304
Message:

Fix up data module unix-to-local path fixing. Fix similar problems in tile importing.

Location:
gamelib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • gamelib/data.py

    r89 r303  
    1111data_dir = os.path.normpath(os.path.join(data_py, '..', 'data'))
    1212
     13def unix_to_local(filename):
     14    '''Convert a relative unix / http filename to a local one.'''
     15    return os.path.join(*filename.split("/"))
     16
    1317def filepath(*filenames):
    1418    '''Determine the path to a file in the data directory.
    1519    '''
    16     return os.path.join(data_dir, *filenames)
     20    os_filenames = [unix_to_local(f) for f in filenames]
     21    return os.path.join(data_dir, *os_filenames)
    1722
    1823def load(filename, mode='rb'):
     
    2227    '''
    2328    # convert unix path separator to platform appropriate one
    24     filename = os.path.join(*filename.split("/"))
     29    filename = unix_to_local(filename)
    2530    return open(os.path.join(data_dir, filename), mode)
    2631
  • gamelib/gameboard.py

    r302 r303  
    308308        self.disp = main_app
    309309        self.tv = tiles.FarmVid()
    310         self.tv.png_folder_load_tiles(data.filepath('tiles'))
     310        self.tv.png_folder_load_tiles('tiles')
    311311        self.tv.tga_load_level(data.filepath('levels/farm.tga'))
    312312        self.create_display()
  • gamelib/tiles.py

    r285 r303  
    33from pgu import tilevid, vid
    44import os
     5import data
    56import imagecache
    67
     
    7980    def png_folder_load_tiles(self, path):
    8081        """Load tiles from a folder of PNG files."""
    81         for dirpath, dirnames, filenames in os.walk(path):
    82             abstract_dirpath = "/".join(dirpath.split(os.path.sep))
     82        full_path = data.filepath(path)
     83        for dirpath, dirnames, filenames in os.walk(full_path):
     84            relative_path = dirpath[len(full_path):]
     85            relative_path = "/".join(relative_path.split(os.path.sep))
    8386            for filename in filenames:
    84                 image_name = abstract_dirpath + "/" + filename
     87                image_name = "/".join([path, relative_path, filename])
    8588                for tile_no in TILE_MAP.tiles_for_image(filename):
    8689                    tile_name = TILE_MAP[tile_no]
Note: See TracChangeset for help on using the changeset viewer.