74 lines
1.8 KiB
Rust
74 lines
1.8 KiB
Rust
use bevy::app::AppExit;
|
|
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
|
|
use bevy::prelude::*;
|
|
#[allow(unused_imports)]
|
|
use bevy_egui::EguiPlugin;
|
|
use bevy_inspector_egui::{WorldInspectorParams, WorldInspectorPlugin};
|
|
use std::env::consts::OS;
|
|
|
|
const VERSION: &'static str = "0.0-a1";
|
|
|
|
mod egui_ui;
|
|
mod setup;
|
|
mod tilemap;
|
|
|
|
#[cfg(debug_assertions)]
|
|
fn use_egui() -> impl Plugin {
|
|
WorldInspectorPlugin::new()
|
|
}
|
|
|
|
#[cfg(not(debug_assertions))]
|
|
fn use_egui() -> impl Plugin {
|
|
EguiPlugin
|
|
}
|
|
|
|
fn main() {
|
|
App::build()
|
|
.insert_resource(WindowDescriptor {
|
|
width: 1600.,
|
|
height: 1200.,
|
|
title: format!("Lily {}", VERSION),
|
|
vsync: false,
|
|
mode: bevy::window::WindowMode::Windowed,
|
|
..Default::default()
|
|
})
|
|
.insert_resource(WorldInspectorParams {
|
|
enabled: false,
|
|
..Default::default()
|
|
})
|
|
.add_plugins(DefaultPlugins)
|
|
.add_plugin(use_egui())
|
|
.add_plugin(LogDiagnosticsPlugin::default())
|
|
.add_plugin(FrameTimeDiagnosticsPlugin::default())
|
|
.add_plugin(setup::SetupPlugin)
|
|
.add_plugin(egui_ui::EguiUiPlugin)
|
|
.add_plugin(tilemap::TilemapPlugin)
|
|
.add_system(keyboard_exit.system())
|
|
.add_system(keyboard_toggle_world_inspector.system())
|
|
.run();
|
|
}
|
|
|
|
fn keyboard_exit(keys: Res<Input<KeyCode>>, mut exit: EventWriter<AppExit>) {
|
|
// Cmd+W or Cmd+Q do the same here
|
|
// TODO maybe change this?
|
|
if OS == "macos"
|
|
&& (keys.pressed(KeyCode::LWin) && (keys.pressed(KeyCode::W) || keys.pressed(KeyCode::Q)))
|
|
{
|
|
exit.send(AppExit);
|
|
}
|
|
|
|
// Alt+F4 on Windows
|
|
if OS == "windows" && keys.pressed(KeyCode::LAlt) && keys.pressed(KeyCode::F4) {
|
|
exit.send(AppExit);
|
|
}
|
|
}
|
|
|
|
fn keyboard_toggle_world_inspector(
|
|
keys: Res<Input<KeyCode>>,
|
|
mut wi: ResMut<WorldInspectorParams>,
|
|
) {
|
|
if cfg!(debug_assertions) && keys.just_pressed(KeyCode::Backslash) {
|
|
wi.enabled = !wi.enabled
|
|
}
|
|
}
|