micro_games_kit/
lib.rs

1pub mod third_party {
2    pub use anim8;
3    pub use anput;
4    pub use emergent;
5    pub use fontdue;
6    pub use gilrs;
7    #[cfg(not(target_arch = "wasm32"))]
8    pub use glutin as windowing;
9    pub use image;
10    #[cfg(target_arch = "wasm32")]
11    pub use instant::Instant;
12    pub use intuicio_backend_vm;
13    pub use intuicio_core;
14    pub use intuicio_data;
15    pub use intuicio_derive;
16    pub use intuicio_frontend_simpleton;
17    pub use kira;
18    pub use nodio;
19    pub use noise;
20    pub use rand;
21    pub use raui_core;
22    pub use raui_immediate;
23    pub use raui_immediate_widgets;
24    pub use rstar;
25    pub use serde;
26    pub use spitfire_core;
27    pub use spitfire_draw;
28    pub use spitfire_fontdue;
29    pub use spitfire_glow;
30    pub use spitfire_gui;
31    pub use spitfire_input;
32    #[cfg(not(target_arch = "wasm32"))]
33    pub use std::time::Instant;
34    pub use toml;
35    pub use typid;
36    pub use vek;
37    #[cfg(target_arch = "wasm32")]
38    pub use winit as windowing;
39}
40
41pub mod animation;
42pub mod assets;
43pub mod audio;
44pub mod character;
45pub mod config;
46pub mod context;
47pub mod game;
48pub mod gamepad;
49pub mod grid_world;
50pub mod pcg;
51pub mod scripting;
52pub mod tag;
53
54use config::Config;
55use game::GameInstance;
56use spitfire_draw::utils::Vertex;
57use spitfire_glow::app::App;
58use std::{error::Error, path::Path};
59
60pub struct GameLauncher {
61    instance: GameInstance,
62    title: String,
63    config: Config,
64}
65
66impl GameLauncher {
67    pub fn new(instance: GameInstance) -> Self {
68        Self {
69            instance,
70            title: "MicroGamesKit".to_owned(),
71            config: Config::default(),
72        }
73    }
74
75    pub fn title(mut self, title: impl ToString) -> Self {
76        self.title = title.to_string();
77        self
78    }
79
80    pub fn config(mut self, config: Config) -> Self {
81        self.config = config;
82        self
83    }
84
85    pub fn load_config_from_file(
86        mut self,
87        config: impl AsRef<Path>,
88    ) -> Result<Self, Box<dyn Error>> {
89        self.config = Config::load_from_file(config)?;
90        Ok(self)
91    }
92
93    pub fn load_config_from_str(mut self, config: &str) -> Result<Self, Box<dyn Error>> {
94        self.config = Config::load_from_str(config)?;
95        Ok(self)
96    }
97
98    pub fn run(self) {
99        #[cfg(debug_assertions)]
100        spitfire_glow::console_log!("* Game {:#?}", self.config);
101        App::<Vertex>::new(self.config.to_app_config(self.title)).run(self.instance);
102    }
103}