WIP sdl renderer
This commit is contained in:
parent
68aa90cac8
commit
ef3f64bfa2
3 changed files with 22 additions and 11 deletions
1
g.py
1
g.py
|
|
@ -5,6 +5,7 @@ from __future__ import annotations
|
||||||
import tcod.console
|
import tcod.console
|
||||||
import tcod.context
|
import tcod.context
|
||||||
import tcod.ecs
|
import tcod.ecs
|
||||||
|
import tcod.sdl.video
|
||||||
import tcod.tileset
|
import tcod.tileset
|
||||||
import tcod.sdl.render
|
import tcod.sdl.render
|
||||||
import tcod.render
|
import tcod.render
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@ from __future__ import annotations
|
||||||
from typing import Protocol, TypeAlias
|
from typing import Protocol, TypeAlias
|
||||||
|
|
||||||
import attrs
|
import attrs
|
||||||
import tcod.console
|
from tcod.console import Console
|
||||||
|
from tcod.event import Event, Quit
|
||||||
|
from tcod.event import wait as wait_for_event
|
||||||
import tcod.event
|
import tcod.event
|
||||||
|
|
||||||
import g
|
import g
|
||||||
|
|
@ -16,10 +18,10 @@ class Screen(Protocol):
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
def on_event(self, event: tcod.event.Event) -> ScreenResult:
|
def on_event(self, event: Event) -> ScreenResult:
|
||||||
"""Called on events."""
|
"""Called on events."""
|
||||||
|
|
||||||
def on_draw(self, console: tcod.console.Console) -> None:
|
def on_draw(self, console: Console) -> None:
|
||||||
"""Called when the screen is being drawn."""
|
"""Called when the screen is being drawn."""
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -84,9 +86,10 @@ def main_loop() -> None:
|
||||||
"""Run the active screen forever."""
|
"""Run the active screen forever."""
|
||||||
while g.screens:
|
while g.screens:
|
||||||
main_draw()
|
main_draw()
|
||||||
for event in tcod.event.wait():
|
for event in wait_for_event():
|
||||||
if event.type == 'WindowClose':
|
match event:
|
||||||
raise SystemExit()
|
case Quit():
|
||||||
|
raise SystemExit()
|
||||||
tile_event = g.context.convert_event(event)
|
tile_event = g.context.convert_event(event)
|
||||||
if g.screens:
|
if g.screens:
|
||||||
_apply_screen_result(g.screens[-1].on_event(tile_event))
|
_apply_screen_result(g.screens[-1].on_event(tile_event))
|
||||||
|
|
|
||||||
17
main.py
17
main.py
|
|
@ -5,10 +5,13 @@ from __future__ import annotations
|
||||||
|
|
||||||
import tcod.console
|
import tcod.console
|
||||||
import tcod.context
|
import tcod.context
|
||||||
|
import tcod.render
|
||||||
import tcod.tileset
|
import tcod.tileset
|
||||||
import game.tilesetmanager
|
import tcod.sdl.video
|
||||||
import g
|
import tcod.sdl.render
|
||||||
|
|
||||||
|
import g
|
||||||
|
import game.tilesetmanager
|
||||||
import game.screens
|
import game.screens
|
||||||
from game.screens.menu_screens import MainMenu
|
from game.screens.menu_screens import MainMenu
|
||||||
|
|
||||||
|
|
@ -20,17 +23,21 @@ def main() -> None:
|
||||||
g.screens = [MainMenu()]
|
g.screens = [MainMenu()]
|
||||||
g.background = tcod.console.Console(80, 35)
|
g.background = tcod.console.Console(80, 35)
|
||||||
g.foreground = tcod.console.Console(80, 35)
|
g.foreground = tcod.console.Console(80, 35)
|
||||||
g.sdl_window = tcod.sdl.video.new_window(
|
win = tcod.sdl.video.new_window(
|
||||||
g.background.width * g.tileset.tile_width,
|
g.background.width * g.tileset.tile_width,
|
||||||
g.background.height * g.tileset.tile_height,
|
g.background.height * g.tileset.tile_height,
|
||||||
flags=tcod.lib.SDL_WINDOW_RESIZABLE,
|
flags=tcod.lib.SDL_WINDOW_RESIZABLE,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
g.sdl_window = win
|
||||||
|
|
||||||
|
|
||||||
g.sdl_renderer = tcod.sdl.render.new_renderer(g.sdl_window, target_textures=True)
|
g.sdl_renderer = tcod.sdl.render.new_renderer(g.sdl_window, target_textures=True)
|
||||||
|
|
||||||
g.atlas = tcod.render.SDLTilesetAtlas(g.sdl_renderer, g.tileset)
|
g.atlas = tcod.render.SDLTilesetAtlas(g.sdl_renderer, g.tileset)
|
||||||
|
|
||||||
g.console_render = tcod.render.SDLConsoleRender(atlas=g.atlas)
|
g.console_render = tcod.render.SDLConsoleRender(atlas=g.atlas)
|
||||||
|
|
||||||
with tcod.context.new(console=g.background, tileset=g.tileset) as g.context:
|
with tcod.context.new(console=g.background, tileset=g.tileset) as g.context:
|
||||||
game.screens.main_loop()
|
game.screens.main_loop()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue