effect_engine/
lib.rs

1pub extern crate effect_audio as audio;
2pub extern crate effect_core as core;
3pub extern crate effect_events as events;
4pub extern crate effect_gui as gui;
5pub extern crate effect_util as util;
6pub extern crate effect_vulkan as vulkan;
7pub extern crate effect_wgpu as web_render;
8
9use effect_wgpu::app::effect2d::EffectWeb2D;
10use winit::{dpi::PhysicalSize, event_loop::EventLoop};
11
12pub enum EngineType {
13    D2,
14    // D3,
15}
16
17pub enum GraphicsAPI {
18    WGPU,
19    // VULKAN,
20}
21
22pub enum EffectAppVariant {
23    Web2D((EffectWeb2D, EventLoop<()>)),
24    // Web3D(EffectWeb3D),
25}
26
27pub struct EffectAppBuilder {
28    engine_type: EngineType,
29    app_name: &'static str,
30    window_dimensions: PhysicalSize<u32>,
31    resizable_window: bool,
32    graphics_api: GraphicsAPI, // pixel art should be on a per texture basis
33    vsync: bool,
34}
35
36impl Default for EffectAppBuilder {
37    fn default() -> Self {
38        let engine_type = EngineType::D2;
39        let app_name = "";
40        let window_dimensions = PhysicalSize::new(800, 600);
41        let resizable_window = false;
42        let graphics_api = GraphicsAPI::WGPU;
43        let vsync = true;
44        Self {
45            engine_type,
46            app_name,
47            window_dimensions,
48            resizable_window,
49            graphics_api,
50            vsync,
51        }
52    }
53}
54
55#[allow(unreachable_patterns)]
56impl EffectAppBuilder {
57    pub fn engine_type(mut self, ty: EngineType) -> Self {
58        self.engine_type = ty;
59        self
60    }
61
62    pub fn app_name(mut self, app_name: &'static str) -> Self {
63        self.app_name = app_name;
64        self
65    }
66
67    pub fn window_dimensions(mut self, width: u32, height: u32) -> Self {
68        self.window_dimensions = PhysicalSize::new(width, height);
69        self
70    }
71
72    pub fn resizable_window(mut self, resizable: bool) -> Self {
73        self.resizable_window = resizable;
74        self
75    }
76
77    pub fn graphics_api(mut self, graphics_api: GraphicsAPI) -> Self {
78        self.graphics_api = graphics_api;
79        self
80    }
81
82    pub fn vsync(mut self, vsync: bool) -> Self {
83        self.vsync = vsync;
84        self
85    }
86
87    pub fn build(self) -> EffectAppVariant {
88        match self.graphics_api {
89            GraphicsAPI::WGPU => match self.engine_type {
90                EngineType::D2 => EffectAppVariant::Web2D(EffectWeb2D::new(
91                    self.window_dimensions,
92                    self.vsync,
93                    self.app_name,
94                    self.resizable_window,
95                )),
96                _ => {
97                    unimplemented!()
98                }
99            },
100            _ => {
101                unimplemented!()
102            }
103        }
104    }
105}
106
107#[allow(unreachable_patterns)]
108impl EffectAppVariant {
109    pub fn get_wgpu_2d(self) -> (EffectWeb2D, EventLoop<()>) {
110        match self {
111            EffectAppVariant::Web2D(val) => return val,
112            _ => {
113                panic!("App was not configured to use WGPU in 2D mode, please check your configuration.")
114            }
115        }
116    }
117}