Permalink
Browse files

Buildings now have one and off states and toggle them.

  • Loading branch information...
dfloer committed Nov 8, 2018
1 parent bae2065 commit 93648c614dbc216be85a2a52d3c0c7ffd9fde6ea
@@ -371,13 +371,20 @@ def __init__(self):
def draw_buildings(self):
self.children = []
for k, building in terrain_map.buildings.items():
powered = network_map.network[k]["powered"]
position = hex_math.hex_to_pixel(layout, k, False)
anchor = sprite_width / 2, sprite_height / 2
sprite = Sprite(sprite_images[building.sprite_id], position=position, anchor=anchor)
p = " off"
if powered:
p = " on"
if building.building_id == 0:
p = ''
sprite = Sprite(sprite_images[f"{building.sprite_id}{p}"], position=position, anchor=anchor)
try:
self.buildings_batch.add(sprite, z=-k.r, name=f"{k.q}_{k.r}_{k.s}")
except Exception:
pass # This sprite must already exist, so we skip it.
self.buildings_batch.remove(f"{k.q}_{k.r}_{k.s}")
self.buildings_batch.add(sprite, z=-k.r, name=f"{k.q}_{k.r}_{k.s}")
self.add(self.buildings_batch)
def plop_building(self, cell, building):
@@ -629,6 +636,7 @@ def plop_network(self, cell, network_type="energy"):
# Going to either need to tell neighbours to check themselves again, or force a redraw and reparse of the whole network, which could be painful.
network_map.network[cell] = {"type": network_type, "powered": powered}
self.draw_network()
building_layer.draw_buildings()
else:
print("Network already exists, skipping.")
@@ -655,6 +663,7 @@ def remove_network(self, cell):
except Exception:
pass # This sprite must already exist, so we skip it.)
self.draw_network()
building_layer.draw_buildings()
def set_focus(self, *args, **kwargs):
super().set_focus(*args, **kwargs)
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.

0 comments on commit 93648c6

Please sign in to comment.