From 6cfa79546398fdcecd8a985d9d1774a6d26aa9aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20N=C3=B6llemeyer?= Date: Mon, 19 Aug 2024 16:33:59 +0200 Subject: [PATCH] sdl renderer working as before --- g.py | 3 --- game/screens/__init__.py | 12 +++++++++--- game/screens/game_screens.py | 2 -- game/screens/menus.py | 2 -- main.py | 3 +-- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/g.py b/g.py index cd93e45..c90b6b0 100644 --- a/g.py +++ b/g.py @@ -22,9 +22,6 @@ world: tcod.ecs.Registry screens: list[Screen] = [] """A stack of states with the last item being the active state.""" -console: tcod.console.Console -"""The current main console.""" - foreground: tcod.console.Console """The foreground console""" diff --git a/game/screens/__init__.py b/game/screens/__init__.py index f68b882..3bdf442 100644 --- a/game/screens/__init__.py +++ b/game/screens/__init__.py @@ -55,11 +55,11 @@ def main_draw() -> None: g.background.clear() g.foreground.clear() g.screens[-1].on_draw(g.background) - # g.context.present(g.console) + # g.context.present(g.background) g.sdl_renderer.copy(g.console_render.render(g.background)) - # g.sdl_renderer.copy(g.console_render.render(g.foreground)) + g.sdl_renderer.copy(g.console_render.render(g.foreground)) g.foreground.blit(g.background, fg_alpha=1.0, bg_alpha=0.0) g.sdl_renderer.copy(g.console_render.render(g.background)) g.sdl_renderer.present() @@ -81,6 +81,12 @@ def _apply_screen_result(result: ScreenResult) -> None: case _: raise TypeError(result) +def convert_event(event: tcod.event.Event): + match event: + case tcod.event.MouseState(position=pos): + width, height = g.tileset.tile_width, g.tileset.tile_height + event.position = (pos[0]//width, pos[1]//height) + return event def main_loop() -> None: """Run the active screen forever.""" @@ -90,7 +96,7 @@ def main_loop() -> None: match event: case Quit(): raise SystemExit() - tile_event = g.context.convert_event(event) + tile_event = convert_event(event) if g.screens: _apply_screen_result(g.screens[-1].on_event(tile_event)) diff --git a/game/screens/game_screens.py b/game/screens/game_screens.py index fdc1985..0a7ca66 100644 --- a/game/screens/game_screens.py +++ b/game/screens/game_screens.py @@ -76,8 +76,6 @@ class MainScreen(Screen): match event: case tcod.event.KeyDown(sym=sym) if sym in ACTION_KEYS: _handle_action(player) - case tcod.event.Quit(): - raise SystemExit() case tcod.event.KeyDown(sym=sym) if sym in DIRECTION_KEYS: dir = DIRECTION_KEYS[sym] return _handle_movement(player, map, dir) diff --git a/game/screens/menus.py b/game/screens/menus.py index 7927cc5..9df7066 100644 --- a/game/screens/menus.py +++ b/game/screens/menus.py @@ -60,8 +60,6 @@ class ListMenu(Screen): def on_event(self, event: tcod.event.Event) -> ScreenResult: """Handle events for menus.""" match event: - case tcod.event.Quit(): - raise SystemExit() case tcod.event.KeyDown(sym=sym) if sym in DIRECTION_KEYS: dx, dy = DIRECTION_KEYS[sym] if dx != 0 or dy == 0: diff --git a/main.py b/main.py index 328220e..0f2653e 100755 --- a/main.py +++ b/main.py @@ -38,8 +38,7 @@ def main() -> None: g.console_render = tcod.render.SDLConsoleRender(atlas=g.atlas) - with tcod.context.new(console=g.background, tileset=g.tileset) as g.context: - game.screens.main_loop() + game.screens.main_loop() if __name__ == "__main__":