aboutsummaryrefslogtreecommitdiff
path: root/games/rstnode/rst-client/src/window.rs
blob: 3dcf375a9009d227fdf1313b9dfcfa44c0b81bb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//! Basic window setup code

use crate::{ctx, state::ClientState, GameSettings};
use ggez::{
    event::{self, EventLoop},
    Context,
};

pub struct Window {
    ctx: Context,
    eloop: EventLoop<()>,
}

impl Window {
    pub fn ctx(&mut self) -> &mut Context {
        &mut self.ctx
    }
    
    pub fn run(self, state: ClientState) -> ! {
        event::run(self.ctx, self.eloop, state)
    }
}

/// Start the main event loop with game settings and state
pub fn create(settings: &GameSettings) -> Window {
    let (ctx, eloop) = ctx::build(settings).build().unwrap();
    Window { ctx, eloop }
}