amethyst_window/
bundle.rs1use crate::{DisplayConfig, EventsLoopSystem, WindowSystem};
2use amethyst_config::{Config, ConfigError};
3use amethyst_core::{bundle::SystemBundle, ecs::World, shred::DispatcherBuilder};
4use amethyst_error::Error;
5use winit::EventsLoop;
6
7#[cfg(feature = "test-support")]
9pub const SCREEN_WIDTH: u32 = 800;
10#[cfg(feature = "test-support")]
12pub const SCREEN_HEIGHT: u32 = 600;
13
14#[derive(Debug)]
17pub struct WindowBundle {
18 config: DisplayConfig,
19}
20
21impl WindowBundle {
22 pub fn from_config(config: DisplayConfig) -> Self {
24 WindowBundle { config }
25 }
26
27 pub fn from_config_path(path: impl AsRef<std::path::Path>) -> Result<Self, ConfigError> {
31 Ok(WindowBundle::from_config(DisplayConfig::load(
32 path.as_ref(),
33 )?))
34 }
35
36 #[cfg(feature = "test-support")]
43 pub fn from_test_config() -> Self {
44 let mut display_config = DisplayConfig::default();
45 display_config.dimensions = Some((SCREEN_WIDTH, SCREEN_HEIGHT));
46 display_config.visibility = false;
47
48 WindowBundle::from_config(display_config)
49 }
50}
51
52impl<'a, 'b> SystemBundle<'a, 'b> for WindowBundle {
53 fn build(
54 self,
55 world: &mut World,
56 builder: &mut DispatcherBuilder<'a, 'b>,
57 ) -> Result<(), Error> {
58 let event_loop = EventsLoop::new();
59 builder.add(
60 WindowSystem::from_config(world, &event_loop, self.config),
61 "window",
62 &[],
63 );
64 builder.add_thread_local(EventsLoopSystem::new(event_loop));
65 Ok(())
66 }
67}