1use camera::Camera;
2use thedes_domain::game::{Game, MovePlayerError};
3use thedes_geometry::orientation::Direction;
4use thedes_tui::core::App;
5
6use thiserror::Error;
7
8pub mod camera;
9
10#[derive(Debug, Error)]
11pub enum RenderError {
12 #[error("Failed to handle session camera")]
13 Camera(
14 #[from]
15 #[source]
16 camera::Error,
17 ),
18}
19
20#[derive(Debug, Error)]
21pub enum MoveAroundError {
22 #[error("Failed to move player pointer")]
23 MovePlayer(
24 #[from]
25 #[source]
26 MovePlayerError,
27 ),
28}
29
30#[derive(Debug, Error)]
31pub enum QuickStepError {
32 #[error("Failed to move player head")]
33 MovePlayer(
34 #[from]
35 #[source]
36 MovePlayerError,
37 ),
38}
39
40#[derive(Debug, Clone)]
41pub struct Config {
42 camera: camera::Config,
43}
44
45impl Default for Config {
46 fn default() -> Self {
47 Self::new()
48 }
49}
50
51impl Config {
52 pub fn new() -> Self {
53 Self { camera: camera::Config::new() }
54 }
55
56 pub fn with_camera(self, config: camera::Config) -> Self {
57 Self { camera: config, ..self }
58 }
59
60 pub fn finish(self, game: Game) -> Session {
61 Session { game, camera: self.camera.finish() }
62 }
63}
64
65#[derive(Debug, Clone)]
66pub struct Session {
67 game: Game,
68 camera: Camera,
69}
70
71impl Session {
72 pub fn render(&mut self, app: &mut App) -> Result<(), RenderError> {
73 self.camera.render(app, &mut self.game)?;
74 self.camera.update(app, &mut self.game);
75 Ok(())
76 }
77
78 pub fn move_around(
79 &mut self,
80 app: &mut App,
81 direction: Direction,
82 ) -> Result<(), MoveAroundError> {
83 self.game.move_player_pointer(direction)?;
84 self.camera.update(app, &mut self.game);
85 Ok(())
86 }
87
88 pub fn quick_step(
89 &mut self,
90 app: &mut App,
91 direction: Direction,
92 ) -> Result<(), QuickStepError> {
93 self.game.move_player_head(direction)?;
94 self.camera.update(app, &mut self.game);
95 Ok(())
96 }
97}