outfly/src/main.rs

129 lines
4.7 KiB
Rust
Raw Normal View History

2024-04-21 16:23:40 +00:00
// ▄████████▄ + ███ + ▄█████████ ███ +
// ███▀ ▀███ + + ███ ███▀ + ███ + +
// ███ + ███ ███ ███ █████████ ███ ███ ███ ███
2024-04-21 17:34:00 +00:00
// ███ +███ ███ ███ ███ ███▐██████ ███ ███ ███
2024-04-21 16:23:40 +00:00
// ███ + ███ ███+ ███ +███ ███ + ███ ███ + ███
// ███▄ ▄███ ███▄ ███ ███ + ███ + ███ ███▄ ███
// ▀████████▀ + ▀███████ ███▄ ███▄ ▀████ ▀███████
// + + + ███
// + ▀████████████████████████████████████████████████████▀
mod actor;
2024-03-16 19:53:57 +00:00
mod audio;
mod camera;
mod chat;
mod commands;
2024-03-30 20:14:04 +00:00
mod effects;
mod hud;
2024-04-16 14:27:17 +00:00
mod shading;
mod var;
mod world;
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};
use bevy::pbr::ExtendedMaterial;
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.add_systems(Update, debug);
app.insert_resource(var::Settings::default());
2024-04-14 14:20:51 +00:00
app.insert_resource(var::GameVars::default());
2024-03-17 23:04:23 +00:00
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,
2024-03-17 22:49:50 +00:00
actor::ActorPlugin,
2024-03-17 23:04:23 +00:00
audio::AudioPlugin,
camera::CameraPlugin,
chat::ChatPlugin,
commands::CommandsPlugin,
2024-03-30 20:14:04 +00:00
effects::EffectsPlugin,
hud::HudPlugin,
shading::ShadingPlugin,
world::WorldPlugin,
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::BorderlessFullscreen;
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>>,
settings: Res<var::Settings>,
2024-04-07 22:23:55 +00:00
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>,
mut windows: Query<&mut Window, With<PrimaryWindow>>,
2024-03-16 15:12:35 +00:00
) {
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-04-07 22:23:55 +00:00
if keyboard_input.just_pressed(settings.key_fullscreen) {
for mut window in &mut windows {
window.mode = if window.mode == WindowMode::Windowed {
WindowMode::BorderlessFullscreen
} else {
WindowMode::Windowed
}
}
}
2024-03-16 14:13:00 +00:00
}
fn debug(
settings: Res<var::Settings>,
keyboard_input: Res<ButtonInput<KeyCode>>,
mut commands: Commands,
mut extended_materials: ResMut<Assets<ExtendedMaterial<StandardMaterial, shading::AsteroidSurface>>>,
materials: Query<(Entity, Option<&Name>, &Handle<Mesh>)>,
) {
if settings.dev_mode && keyboard_input.pressed(KeyCode::KeyP) {
for (entity, _name, mesh) in &materials {
dbg!(mesh);
let mut entity = commands.entity(entity);
entity.remove::<Handle<StandardMaterial>>();
let material = extended_materials.add(shading::AsteroidSurface::material());
entity.insert(material);
}
}
}