Mercurial > rinkhals
annotate gamelib/tiles.py @ 558:5cdf26bde2f2
Botanical biodiversity.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 28 Nov 2009 18:20:55 +0000 |
parents | 11c4cebfe4c5 |
children |
rev | line source |
---|---|
24 | 1 """Extension to pgu's tilevid.""" |
2 | |
558 | 3 import random |
4 import os | |
5 | |
24 | 6 from pgu import tilevid, vid |
303
e12d99215b74
Fix up data module unix-to-local path fixing. Fix similar problems in tile importing.
Simon Cross <hodgestar@gmail.com>
parents:
285
diff
changeset
|
7 import data |
49
dd9d2a4dd494
Update tile loading to use imagecache and new data.py auto-converting of paths.
Simon Cross <hodgestar@gmail.com>
parents:
30
diff
changeset
|
8 import imagecache |
463
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
9 import serializer |
24 | 10 |
56
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
11 class TileMap(object): |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
12 """Helper class for describing all the game tiles.""" |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
13 |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
14 # number -> (name, image file name) |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
15 DEFAULT_TILES = { |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
16 0: ("woodland", "woodland.png"), |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
17 1: ("grassland", "grassland.png"), |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
18 2: ("fence", "fence.png"), |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
19 3: ("henhouse", "grassland.png"), |
175
a4e3d26d16f0
Fix tile image for guardtower.
Simon Cross <hodgestar@gmail.com>
parents:
133
diff
changeset
|
20 4: ("guardtower", "grassland.png"), |
62 | 21 5: ("broken fence", "broken_fence.png"), |
133
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
62
diff
changeset
|
22 6: ("hendominium", "grassland.png"), |
558 | 23 } |
552
11c4cebfe4c5
Preparatory work for woodland biodiversity.
Jeremy Thurgood <firxen@gmail.com>
parents:
505
diff
changeset
|
24 |
558 | 25 ALTERNATE_TILES = { |
552
11c4cebfe4c5
Preparatory work for woodland biodiversity.
Jeremy Thurgood <firxen@gmail.com>
parents:
505
diff
changeset
|
26 255: ("woodland", "woodland.png"), |
11c4cebfe4c5
Preparatory work for woodland biodiversity.
Jeremy Thurgood <firxen@gmail.com>
parents:
505
diff
changeset
|
27 254: ("woodland", "woodland2.png"), |
11c4cebfe4c5
Preparatory work for woodland biodiversity.
Jeremy Thurgood <firxen@gmail.com>
parents:
505
diff
changeset
|
28 253: ("woodland", "woodland3.png"), |
558 | 29 } |
56
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
30 |
558 | 31 def __init__(self, tiles=None, alternate_tiles=None): |
56
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
32 if tiles is None: |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
33 tiles = self.DEFAULT_TILES.copy() |
558 | 34 if alternate_tiles is None: |
35 alternate_tiles = self.ALTERNATE_TILES.copy() | |
36 self._alternate_tiles = alternate_tiles | |
56
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
37 self._tiles = tiles |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
38 self._reverse_map = dict((v[0], k) for k, v in self._tiles.iteritems()) |
558 | 39 self._tiles.update(alternate_tiles) |
24 | 40 |
56
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
41 def __getitem__(self, n): |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
42 """Get the string name of tile n.""" |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
43 return self._tiles[n][0] |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
44 |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
45 def tiles_for_image(self, image_name): |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
46 """Return tile numbers associated with the given image name.""" |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
47 for n, (name, image) in self._tiles.iteritems(): |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
48 if image_name == image: |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
49 yield n |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
50 |
558 | 51 def random_alternate(self, n): |
52 alts = [a for a, (name, image) in self._alternate_tiles.iteritems() if name == self[n]] | |
53 if alts: | |
54 return random.choice(alts) | |
55 return n | |
56 | |
56
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
57 TILE_MAP = TileMap() |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
58 REVERSE_TILE_MAP = TILE_MAP._reverse_map |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
59 |
379
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
60 |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
61 class LayeredSprites(object): |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
62 # This is as small a subset of list behaviour as we can get away with. |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
63 # WARNING: It makes assumptions that may not be justified in the general case. |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
64 # Caveat utilitor and all the rest. |
218
5cb0e0b9cd16
Make sprite cursors stay on top by fudging the sprite list. :/
Simon Cross <hodgestar@gmail.com>
parents:
175
diff
changeset
|
65 |
379
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
66 def __init__(self, layers=None, default_layer=None): |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
67 # Layers are ordered from bottom to top. |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
68 if layers is None: |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
69 layers = ['default'] |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
70 self.layers = layers |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
71 if default_layer is None: |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
72 default_layer = layers[0] |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
73 self.default_layer = default_layer |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
74 self._sprites = {} |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
75 for layer in layers: |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
76 self._sprites[layer] = [] |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
77 self.removed = [] |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
78 |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
79 def append(self, sprite, layer=None): |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
80 if layer is None: |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
81 layer = self.default_layer |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
82 self._sprites[layer].append(sprite) |
218
5cb0e0b9cd16
Make sprite cursors stay on top by fudging the sprite list. :/
Simon Cross <hodgestar@gmail.com>
parents:
175
diff
changeset
|
83 sprite.updated = 1 |
5cb0e0b9cd16
Make sprite cursors stay on top by fudging the sprite list. :/
Simon Cross <hodgestar@gmail.com>
parents:
175
diff
changeset
|
84 |
379
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
85 def remove(self, sprite, layer=None): |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
86 if layer is None: |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
87 layer = self.default_layer |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
88 self._sprites[layer].remove(sprite) |
218
5cb0e0b9cd16
Make sprite cursors stay on top by fudging the sprite list. :/
Simon Cross <hodgestar@gmail.com>
parents:
175
diff
changeset
|
89 sprite.updated = 1 |
5cb0e0b9cd16
Make sprite cursors stay on top by fudging the sprite list. :/
Simon Cross <hodgestar@gmail.com>
parents:
175
diff
changeset
|
90 self.removed.append(sprite) |
5cb0e0b9cd16
Make sprite cursors stay on top by fudging the sprite list. :/
Simon Cross <hodgestar@gmail.com>
parents:
175
diff
changeset
|
91 |
379
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
92 def __getitem__(self, key): |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
93 # vid.py uses sprites[:] to get a mutation-safe list copy, so we need this. |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
94 # No other indexing or slicing operations make sense. |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
95 if not isinstance(key, slice): |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
96 raise IndexError('[:] is the only supported slice/index operation.') |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
97 return iter(self) |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
98 |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
99 def __iter__(self): |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
100 # We iterate over all sprites in layer order. |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
101 for layer in self.layers: |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
102 for sprite in self._sprites[layer]: |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
103 yield sprite |
218
5cb0e0b9cd16
Make sprite cursors stay on top by fudging the sprite list. :/
Simon Cross <hodgestar@gmail.com>
parents:
175
diff
changeset
|
104 |
24 | 105 |
463
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
106 class FarmVid(tilevid.Tilevid, serializer.Simplifiable): |
24 | 107 """Extension of pgu's TileVid class to handle the complications |
108 of raising chickens. | |
109 """ | |
463
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
110 |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
111 SIMPLIFY = [ |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
112 'size', |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
113 'layers', |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
114 'tlayer', |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
115 'alayer', |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
116 'blayer', |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
117 'clayer', |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
118 ] |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
119 |
24 | 120 def __init__(self): |
121 tilevid.Tilevid.__init__(self) | |
381
7a58dadfd251
little cleanups, every sprite in its proper layer.
Jeremy Thurgood <firxen@gmail.com>
parents:
379
diff
changeset
|
122 self.sprites = LayeredSprites(['buildings', 'animals', 'animations', 'cursor'], 'animals') |
24 | 123 |
505
3ed6c011106d
Switch to classmethod decorators.
Simon Cross <hodgestar@gmail.com>
parents:
463
diff
changeset
|
124 @classmethod |
463
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
125 def make(cls): |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
126 """Override default Simplifiable object creation.""" |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
127 return cls() |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
128 |
505
3ed6c011106d
Switch to classmethod decorators.
Simon Cross <hodgestar@gmail.com>
parents:
463
diff
changeset
|
129 @classmethod |
463
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
130 def unsimplify(cls, *args, **kwargs): |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
131 """Override default Simplifiable unsimplification.""" |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
132 obj = serializer.Simplifiable.unsimplify(*args, **kwargs) |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
133 |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
134 obj.view.x, obj.view.y = 0,0 |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
135 obj._view.x, obj._view.y = 0,0 |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
136 obj.bounds = None |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
137 obj.updates = [] |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
138 |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
139 return obj |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
140 |
558 | 141 def tga_load_level(self, level_map): |
142 tilevid.Tilevid.tga_load_level(self, level_map) | |
143 for xy in [(x, y) for x in range(self.size[0]) for y in range(self.size[1])]: | |
144 self.set(xy, TILE_MAP.random_alternate(self.get(xy))) | |
145 | |
24 | 146 def png_folder_load_tiles(self, path): |
147 """Load tiles from a folder of PNG files.""" | |
303
e12d99215b74
Fix up data module unix-to-local path fixing. Fix similar problems in tile importing.
Simon Cross <hodgestar@gmail.com>
parents:
285
diff
changeset
|
148 full_path = data.filepath(path) |
e12d99215b74
Fix up data module unix-to-local path fixing. Fix similar problems in tile importing.
Simon Cross <hodgestar@gmail.com>
parents:
285
diff
changeset
|
149 for dirpath, dirnames, filenames in os.walk(full_path): |
e12d99215b74
Fix up data module unix-to-local path fixing. Fix similar problems in tile importing.
Simon Cross <hodgestar@gmail.com>
parents:
285
diff
changeset
|
150 relative_path = dirpath[len(full_path):] |
e12d99215b74
Fix up data module unix-to-local path fixing. Fix similar problems in tile importing.
Simon Cross <hodgestar@gmail.com>
parents:
285
diff
changeset
|
151 relative_path = "/".join(relative_path.split(os.path.sep)) |
24 | 152 for filename in filenames: |
303
e12d99215b74
Fix up data module unix-to-local path fixing. Fix similar problems in tile importing.
Simon Cross <hodgestar@gmail.com>
parents:
285
diff
changeset
|
153 image_name = "/".join([path, relative_path, filename]) |
56
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
154 for tile_no in TILE_MAP.tiles_for_image(filename): |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
155 tile_name = TILE_MAP[tile_no] |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
156 self.tiles[tile_no] = FarmTile(tile_no, tile_name, image_name) |
24 | 157 |
30 | 158 def sun(self, sun_on): |
159 """Make it night.""" | |
160 for tile in self.tiles: | |
161 if hasattr(tile, "sun"): | |
162 tile.sun(sun_on) | |
163 for sprite in self.sprites: | |
164 if hasattr(sprite, "sun"): | |
165 sprite.sun(sun_on) | |
166 | |
24 | 167 class FarmTile(vid.Tile): |
30 | 168 |
56
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
169 def __init__(self, tile_no, tile_name, image_name): |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
170 self.tile_no = tile_no |
205789321a46
Replace TILE_MAP with richer (but backwards compatible) structure. Record tile number and tile name on tile object.
Simon Cross <hodgestar@gmail.com>
parents:
51
diff
changeset
|
171 self.tile_name = tile_name |
49
dd9d2a4dd494
Update tile loading to use imagecache and new data.py auto-converting of paths.
Simon Cross <hodgestar@gmail.com>
parents:
30
diff
changeset
|
172 self.day_image = imagecache.load_image(image_name) |
dd9d2a4dd494
Update tile loading to use imagecache and new data.py auto-converting of paths.
Simon Cross <hodgestar@gmail.com>
parents:
30
diff
changeset
|
173 self.night_image = imagecache.load_image(image_name, ("night",)) |
51
32fb395cf71c
Add missing call to vid.Tile.__init__ to FarmTile.
Simon Cross <hodgestar@gmail.com>
parents:
49
diff
changeset
|
174 vid.Tile.__init__(self, self.day_image) |
30 | 175 |
176 def sun(self, sun_on): | |
177 if sun_on: | |
178 self.image = self.day_image | |
179 else: | |
180 self.image = self.night_image |