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
#[cfg(feature = "desktop")]
pub mod desktop;
#[cfg(feature = "web")]
pub mod web;

use oxygengine_core::{prelude::*, scripting::intuicio::prelude::*};
use oxygengine_ha_renderer::prelude::*;
use oxygengine_input::prelude::*;
use oxygengine_nodes::*;

pub trait PrototypeApp {
    fn clear_color(self, value: Rgba) -> Self;
    fn sprite_filtering(self, value: ImageFiltering) -> Self;
    fn view_size(self, value: Scalar) -> Self;
    fn preload_asset(self, path: impl ToString) -> Self;
    fn input_mappings(self, mappings: InputMappings) -> Self;
    fn nodes(self, nodes: ScriptedNodes) -> Self;
    fn scripting_registry(self, registry: Registry) -> Self;
    fn run(self);
}

pub(crate) struct BootState {
    next_state: Option<Box<dyn State>>,
    view_size: Scalar,
}

impl State for BootState {
    fn on_process(&mut self, universe: &mut Universe) -> StateChange {
        if let Some(state) = self.next_state.take() {
            let mut commands = universe.expect_resource_mut::<UniverseCommands>();
            commands.schedule(SpawnEntity::from_bundle((
                Name("camera".into()),
                HaCamera::default()
                    .with_projection(HaCameraProjection::Orthographic(HaCameraOrthographic {
                        scaling: HaCameraOrtographicScaling::FitToView(
                            self.view_size.into(),
                            false,
                        ),
                        centered: true,
                        ignore_depth_planes: false,
                    }))
                    .with_clip_area(Default::default())
                    .with_pipeline(PipelineSource::Registry("prototype".to_owned())),
                HaDefaultCamera,
                HaTransform::default(),
            )));
            StateChange::Swap(state)
        } else {
            StateChange::Pop
        }
    }
}