sdl renderer working as before
This commit is contained in:
parent
ef3f64bfa2
commit
6cfa795463
5 changed files with 10 additions and 12 deletions
3
g.py
3
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"""
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
1
main.py
1
main.py
|
|
@ -38,7 +38,6 @@ 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()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue