outfly/src/main.rs

87 lines
2.5 KiB
Rust
Raw Normal View History

2024-03-16 19:53:57 +00:00
mod audio;
mod camera;
mod commands;
2024-03-16 20:44:51 +00:00
mod world;
2024-03-16 21:20:23 +00:00
mod settings;
2024-03-17 14:23:22 +00:00
mod hud;
2024-03-17 22:49:50 +00:00
mod actor;
2024-03-30 20:14:04 +00:00
mod effects;
2024-03-16 19:53:57 +00:00
#[allow(dead_code)]
mod nature;
2024-03-17 23:04:23 +00:00
use bevy::window::{Window, WindowMode, PrimaryWindow, CursorGrabMode};
2024-03-18 03:41:52 +00:00
use bevy::diagnostic::FrameTimeDiagnosticsPlugin;
2024-03-16 20:44:51 +00:00
use bevy::prelude::*;
use bevy_embedded_assets::{EmbeddedAssetPlugin, PluginMode};
2024-03-28 21:34:16 +00:00
use std::env;
2024-03-16 14:00:31 +00:00
fn main() {
2024-03-28 21:34:16 +00:00
let args: Vec<String> = env::args().collect();
if args.len() > 1 {
if args[1] == "--version" || args[1] == "-v" {
let version = option_env!("CARGO_PKG_VERSION").unwrap();
let name = option_env!("CARGO_PKG_NAME").unwrap();
let homepage = option_env!("CARGO_PKG_HOMEPAGE").unwrap();
println!("{name} {version}");
println!("License: GNU GPL version 3: https://gnu.org/licenses/gpl.html");
println!("{homepage}");
return;
}
}
if cfg!(debug_assertions) {
App::new().add_plugins(OutFlyPlugin).run();
} else {
// In release builds, embed assets into the binary
App::new().add_plugins((
EmbeddedAssetPlugin { mode: PluginMode::ReplaceDefault },
OutFlyPlugin,
)).run();
}
2024-03-17 23:04:23 +00:00
}
pub struct OutFlyPlugin;
impl Plugin for OutFlyPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup);
app.add_systems(Update, handle_input);
app.insert_resource(settings::Settings::default());
app.add_plugins((
2024-03-18 19:58:16 +00:00
DefaultPlugins,//.set(ImagePlugin::default_nearest()),
2024-03-17 23:04:23 +00:00
FrameTimeDiagnosticsPlugin,
world::WorldPlugin,
2024-03-17 14:23:22 +00:00
camera::CameraControllerPlugin,
commands::CommandsPlugin,
2024-03-17 22:49:50 +00:00
hud::HudPlugin,
actor::ActorPlugin,
2024-03-17 23:04:23 +00:00
audio::AudioPlugin,
2024-03-30 20:14:04 +00:00
effects::EffectsPlugin,
2024-03-17 23:04:23 +00:00
));
}
2024-03-16 14:00:31 +00:00
}
fn setup(
mut windows: Query<&mut Window, With<PrimaryWindow>>
) {
for mut window in &mut windows {
window.cursor.grab_mode = CursorGrabMode::Locked;
window.cursor.visible = false;
window.mode = WindowMode::Fullscreen;
2024-03-16 23:24:47 +00:00
window.title = "OutFly".to_string();
}
2024-03-16 15:22:44 +00:00
}
2024-03-16 15:12:35 +00:00
fn handle_input(
keyboard_input: Res<ButtonInput<KeyCode>>,
2024-03-17 17:26:44 +00:00
mut settings: ResMut<settings::Settings>,
2024-03-16 15:12:35 +00:00
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>
) {
2024-03-18 03:39:26 +00:00
if keyboard_input.pressed(settings.key_exit) {
2024-03-16 15:12:35 +00:00
app_exit_events.send(bevy::app::AppExit);
2024-03-16 14:13:00 +00:00
}
2024-03-18 03:39:26 +00:00
if keyboard_input.just_pressed(settings.key_restart) {
2024-03-17 17:26:44 +00:00
settings.reset();
2024-03-16 21:20:23 +00:00
}
2024-03-16 14:13:00 +00:00
}