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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use crate::{DisplayConfig, EventsLoopSystem, WindowSystem};
use amethyst_config::Config;
use amethyst_core::{bundle::SystemBundle, ecs::World, shred::DispatcherBuilder};
use amethyst_error::Error;
use winit::EventsLoop;
#[cfg(feature = "test-support")]
pub const SCREEN_WIDTH: u32 = 800;
#[cfg(feature = "test-support")]
pub const SCREEN_HEIGHT: u32 = 600;
#[derive(Debug)]
pub struct WindowBundle {
config: DisplayConfig,
}
impl WindowBundle {
pub fn from_config(config: DisplayConfig) -> Self {
WindowBundle { config }
}
pub fn from_config_path(path: impl AsRef<std::path::Path>) -> Self {
WindowBundle::from_config(DisplayConfig::load(path.as_ref()))
}
#[cfg(feature = "test-support")]
pub fn from_test_config() -> Self {
let mut display_config = DisplayConfig::default();
display_config.dimensions = Some((SCREEN_WIDTH, SCREEN_HEIGHT));
display_config.visibility = false;
WindowBundle::from_config(display_config)
}
}
impl<'a, 'b> SystemBundle<'a, 'b> for WindowBundle {
fn build(
self,
world: &mut World,
builder: &mut DispatcherBuilder<'a, 'b>,
) -> Result<(), Error> {
let event_loop = EventsLoop::new();
builder.add(
WindowSystem::from_config(world, &event_loop, self.config),
"window",
&[],
);
builder.add_thread_local(EventsLoopSystem::new(event_loop));
Ok(())
}
}