Refactor map rendering

- Move all map rendering to a new MapWindow class
- Clip map rendering to the bounds of the Window
- Pass in Entities list from the Engine and render them relative to the window

The map doesn't scroll yet, so it'll always be clipped on the bottom and
right.
This commit is contained in:
Eryn Wells 2023-02-12 15:55:01 -08:00
parent ec28f984da
commit 8efd3ce207
4 changed files with 109 additions and 40 deletions

View file

@ -106,23 +106,11 @@ class Engine:
'''Print the whole game to the given console.'''
self.map.highlight_points(self.__mouse_path_points or [])
self.interface.update(self.hero, self.current_turn)
sorted_entities = sorted(self.entities, key=lambda e: e.render_order.value)
self.interface.update(self.current_turn, self.hero, sorted_entities)
self.interface.draw(console)
entities_at_mouse_position = []
for ent in sorted(self.entities, key=lambda e: e.render_order.value):
# Only process entities that are in the field of view
if not self.map.visible[tuple(ent.position)]:
continue
ent.print_to_console(console)
if ent.position == self.__current_mouse_point:
entities_at_mouse_position.append(ent)
if len(entities_at_mouse_position) > 0:
console.print(x=1, y=43, string=', '.join(e.name for e in entities_at_mouse_position))
def run_event_loop(self, context: tcod.context.Context, console: tcod.Console) -> NoReturn:
'''Run the event loop forever. This method never returns.'''
while True: