resonance 0.1.0

A modular game engine. Heavy work in progress.
Documentation

use crate::window::WindowConfig;
use crate::app::{Engine, Plugin, Stage};
use crate::renderer::Renderer;

#[derive(Default)]
pub struct WindowPlugin {
    config: Option<WindowConfig>,
}

impl WindowPlugin {

    pub fn new(config: WindowConfig) -> Self {
        Self {
            config: Some(config),
        }
    }

    pub fn with_size(width: u32, height: u32, title: impl Into<String>) -> Self {
        Self {
            config: Some(WindowConfig::new(width, height, title)),
        }
    }

    fn get_config(&self) -> WindowConfig {
        self.config.clone().unwrap_or_default()
    }
}

impl Plugin for WindowPlugin {
    fn build(&self, engine: &mut Engine) {
        use crate::window::WindowEvent;

        engine.world.insert_resource(self.get_config());

        engine.world.init_resource::<bevy_ecs::prelude::Messages<WindowEvent>>();

        *engine = std::mem::take(engine)
            .add_system(Stage::Render, render_system);

        log::info!("WindowPlugin initialized");
    }
}

fn render_system(mut renderer: bevy_ecs::system::ResMut<Renderer>) {
    if let Err(e) = renderer.render() {
        log::error!("Failed to render frame: {}", e);
    }
}