Mercurial > rinkhals
annotate gamelib/tiles.py @ 552:11c4cebfe4c5
Preparatory work for woodland biodiversity.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 28 Nov 2009 17:37:13 +0000 |
parents | 3ed6c011106d |
children | 5cdf26bde2f2 |
rev | line source |
---|---|
24 | 1 """Extension to pgu's tilevid.""" |
2 | |
3 from pgu import tilevid, vid | |
4 import os | |
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
|
5 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
|
6 import imagecache |
463
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
7 import serializer |
24 | 8 |
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
|
9 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
|
10 """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
|
11 |
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 # 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
|
13 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
|
14 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
|
15 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
|
16 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
|
17 3: ("henhouse", "grassland.png"), |
175
a4e3d26d16f0
Fix tile image for guardtower.
Simon Cross <hodgestar@gmail.com>
parents:
133
diff
changeset
|
18 4: ("guardtower", "grassland.png"), |
62 | 19 5: ("broken fence", "broken_fence.png"), |
133
b7dc405a28be
Add Hendominium image support.
Simon Cross <hodgestar@gmail.com>
parents:
62
diff
changeset
|
20 6: ("hendominium", "grassland.png"), |
552
11c4cebfe4c5
Preparatory work for woodland biodiversity.
Jeremy Thurgood <firxen@gmail.com>
parents:
505
diff
changeset
|
21 |
11c4cebfe4c5
Preparatory work for woodland biodiversity.
Jeremy Thurgood <firxen@gmail.com>
parents:
505
diff
changeset
|
22 255: ("woodland", "woodland.png"), |
11c4cebfe4c5
Preparatory work for woodland biodiversity.
Jeremy Thurgood <firxen@gmail.com>
parents:
505
diff
changeset
|
23 254: ("woodland", "woodland2.png"), |
11c4cebfe4c5
Preparatory work for woodland biodiversity.
Jeremy Thurgood <firxen@gmail.com>
parents:
505
diff
changeset
|
24 253: ("woodland", "woodland3.png"), |
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
|
25 } |
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
|
26 |
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
|
27 def __init__(self, tiles=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
|
28 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
|
29 tiles = self.DEFAULT_TILES.copy() |
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 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
|
31 self._reverse_map = dict((v[0], k) for k, v in self._tiles.iteritems()) |
552
11c4cebfe4c5
Preparatory work for woodland biodiversity.
Jeremy Thurgood <firxen@gmail.com>
parents:
505
diff
changeset
|
32 # Wood is different: |
11c4cebfe4c5
Preparatory work for woodland biodiversity.
Jeremy Thurgood <firxen@gmail.com>
parents:
505
diff
changeset
|
33 self._reverse_map["woodland"] = 0 |
24 | 34 |
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
|
35 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
|
36 """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
|
37 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
|
38 |
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
|
39 def tile_number(self, 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
|
40 """Return the tile number of the tile with the given 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
|
41 return self._reverse_map[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
|
42 |
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 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
|
44 """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
|
45 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
|
46 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
|
47 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
|
48 |
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 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
|
50 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
|
51 |
379
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
52 |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
53 class LayeredSprites(object): |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
54 # 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
|
55 # 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
|
56 # 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
|
57 |
379
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
58 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
|
59 # 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
|
60 if layers is None: |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
61 layers = ['default'] |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
62 self.layers = layers |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
63 if default_layer is None: |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
64 default_layer = layers[0] |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
65 self.default_layer = default_layer |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
66 self._sprites = {} |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
67 for layer in layers: |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
68 self._sprites[layer] = [] |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
69 self.removed = [] |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
70 |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
71 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
|
72 if layer is None: |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
73 layer = self.default_layer |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
74 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
|
75 sprite.updated = 1 |
5cb0e0b9cd16
Make sprite cursors stay on top by fudging the sprite list. :/
Simon Cross <hodgestar@gmail.com>
parents:
175
diff
changeset
|
76 |
379
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
77 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
|
78 if layer is None: |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
79 layer = self.default_layer |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
80 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
|
81 sprite.updated = 1 |
5cb0e0b9cd16
Make sprite cursors stay on top by fudging the sprite list. :/
Simon Cross <hodgestar@gmail.com>
parents:
175
diff
changeset
|
82 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
|
83 |
379
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
84 def __getitem__(self, key): |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
85 # 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
|
86 # 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
|
87 if not isinstance(key, slice): |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
88 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
|
89 return iter(self) |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
90 |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
91 def __iter__(self): |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
92 # 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
|
93 for layer in self.layers: |
a8a7ada27fa2
Multilayer sprite ordering. Only used by cursors so far.
Jeremy Thurgood <firxen@gmail.com>
parents:
303
diff
changeset
|
94 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
|
95 yield sprite |
218
5cb0e0b9cd16
Make sprite cursors stay on top by fudging the sprite list. :/
Simon Cross <hodgestar@gmail.com>
parents:
175
diff
changeset
|
96 |
24 | 97 |
463
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
98 class FarmVid(tilevid.Tilevid, serializer.Simplifiable): |
24 | 99 """Extension of pgu's TileVid class to handle the complications |
100 of raising chickens. | |
101 """ | |
463
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
102 |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
103 SIMPLIFY = [ |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
104 'size', |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
105 'layers', |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
106 'tlayer', |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
107 'alayer', |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
108 'blayer', |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
109 'clayer', |
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 |
24 | 112 def __init__(self): |
113 tilevid.Tilevid.__init__(self) | |
381
7a58dadfd251
little cleanups, every sprite in its proper layer.
Jeremy Thurgood <firxen@gmail.com>
parents:
379
diff
changeset
|
114 self.sprites = LayeredSprites(['buildings', 'animals', 'animations', 'cursor'], 'animals') |
24 | 115 |
505
3ed6c011106d
Switch to classmethod decorators.
Simon Cross <hodgestar@gmail.com>
parents:
463
diff
changeset
|
116 @classmethod |
463
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
117 def make(cls): |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
118 """Override default Simplifiable object creation.""" |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
119 return cls() |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
120 |
505
3ed6c011106d
Switch to classmethod decorators.
Simon Cross <hodgestar@gmail.com>
parents:
463
diff
changeset
|
121 @classmethod |
463
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
122 def unsimplify(cls, *args, **kwargs): |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
123 """Override default Simplifiable unsimplification.""" |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
124 obj = serializer.Simplifiable.unsimplify(*args, **kwargs) |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
125 |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
126 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
|
127 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
|
128 obj.bounds = None |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
129 obj.updates = [] |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
130 |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
131 return obj |
e3408c803b12
Save and restore tilevid when loading / saving games.
Simon Cross <hodgestar@gmail.com>
parents:
381
diff
changeset
|
132 |
24 | 133 def png_folder_load_tiles(self, path): |
134 """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
|
135 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
|
136 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
|
137 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
|
138 relative_path = "/".join(relative_path.split(os.path.sep)) |
24 | 139 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
|
140 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
|
141 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
|
142 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
|
143 self.tiles[tile_no] = FarmTile(tile_no, tile_name, image_name) |
24 | 144 |
30 | 145 def sun(self, sun_on): |
146 """Make it night.""" | |
147 for tile in self.tiles: | |
148 if hasattr(tile, "sun"): | |
149 tile.sun(sun_on) | |
150 for sprite in self.sprites: | |
151 if hasattr(sprite, "sun"): | |
152 sprite.sun(sun_on) | |
153 | |
24 | 154 class FarmTile(vid.Tile): |
30 | 155 |
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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 vid.Tile.__init__(self, self.day_image) |
30 | 162 |
163 def sun(self, sun_on): | |
164 if sun_on: | |
165 self.image = self.day_image | |
166 else: | |
167 self.image = self.night_image |