From 7aa6885509b9f102fdd1d9ea0420773f658592ed Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 12 May 2024 21:06:38 +0200 Subject: [PATCH] add crate prelude --- src/commands.rs | 7 ++++--- src/hud.rs | 27 ++++++++++++++------------- src/load.rs | 2 +- src/main.rs | 5 +++++ src/world.rs | 3 ++- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 53301f6..2924072 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -15,6 +15,7 @@ use bevy::prelude::*; use bevy_xpbd_3d::prelude::*; use bevy::math::DVec3; use bevy::pbr::{NotShadowCaster, NotShadowReceiver}; +use crate::prelude::*; use crate::{actor, camera, chat, hud, load, nature, var, world}; use regex::Regex; use std::f32::consts::PI; @@ -624,7 +625,7 @@ fn spawn_entities( transform: Transform::from_scale(scale), ..default() }); - load::load(model.as_str(), &mut actor, &*asset_server); + load_asset(model.as_str(), &mut actor, &*asset_server); } actor.insert(Rotation::from(rotation)); @@ -802,7 +803,7 @@ fn spawn_entities( NotShadowCaster, NotShadowReceiver, )); - load::load(ar_asset_name, &mut entitycmd, &*asset_server); + load_asset(ar_asset_name, &mut entitycmd, &*asset_server); } if state.is_point_of_interest || state.is_moon || state.is_planet { @@ -824,7 +825,7 @@ fn spawn_entities( } else { "marker_satellites" }; - load::load(model, &mut entitycmd, &*asset_server); + load_asset(model, &mut entitycmd, &*asset_server); } if state.has_ring { diff --git a/src/hud.rs b/src/hud.rs index 3485a4a..df8709a 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -10,7 +10,8 @@ // // This module manages the heads-up display and augmented reality overlays. -use crate::{actor, audio, camera, chat, nature, load, var}; +use crate::prelude::*; +use crate::{actor, audio, camera, chat, nature}; use bevy::pbr::{NotShadowCaster, NotShadowReceiver}; use bevy::prelude::*; use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}; @@ -215,7 +216,7 @@ impl Log { fn setup( mut commands: Commands, - settings: Res, + settings: Res, asset_server: Res, mut ew_updateoverlays: EventWriter, ) { @@ -612,7 +613,7 @@ fn setup( ..default() }, )); - load::load("selectagon", &mut entitycmd, &*asset_server); + load_asset("selectagon", &mut entitycmd, &*asset_server); ew_updateoverlays.send(UpdateOverlayVisibility); } @@ -621,7 +622,7 @@ fn update_dashboard( timer: ResMut, mut q_dashboard: Query<(&mut Visibility, &Dashboard)>, q_player: Query<&actor::Suit, With>, - settings: Res, + settings: Res, ) { if !settings.hud_active || !timer.0.just_finished() { return; @@ -644,7 +645,7 @@ fn update_dashboard( fn update_speedometer( timer: ResMut, - settings: Res, + settings: Res, q_camera: Query<&LinearVelocity, With>, q_player: Query<&actor::ExperiencesGForce, With>, q_target: Query<&LinearVelocity, With>, @@ -709,7 +710,7 @@ fn update_gauges( timer: ResMut, q_player: Query<(&actor::HitPoints, &actor::Suit, &actor::Battery), With>, mut q_gauges: Query<(&mut Style, &mut BackgroundColor, &Gauge, &GaugeLength)>, - settings: Res, + settings: Res, ) { if !settings.hud_active || !timer.0.just_finished() { return; @@ -747,7 +748,7 @@ fn update_hud( mut q_node_console: Query<&mut Text, (With, Without, Without)>, mut q_node_choice: Query<&mut Text, (With, Without, Without)>, mut q_node_currentline: Query<&mut Text, (With, Without, Without, Without)>, - settings: Res, + settings: Res, q_target: Query<(&IsClickable, Option<&Position>, Option<&LinearVelocity>), With>, ) { if timer.0.tick(time.delta()).just_finished() || log.needs_rerendering { @@ -944,7 +945,7 @@ fn update_hud( fn handle_input( keyboard_input: Res>, mouse_input: Res>, - mut settings: ResMut, + mut settings: ResMut, mut log: ResMut, mut ew_sfx: EventWriter, mut ew_togglemusic: EventWriter, @@ -980,7 +981,7 @@ fn handle_input( fn handle_target_event( mut commands: Commands, - settings: Res, + settings: Res, mut er_target: EventReader, mut ew_sfx: EventWriter, q_target: Query>, @@ -1004,7 +1005,7 @@ fn handle_target_event( } fn update_target_selectagon( - settings: Res, + settings: Res, mut q_selectagon: Query<(&mut Transform, &mut Visibility), (With, Without, Without)>, q_target: Query<&Transform, (With, Without, Without)>, q_camera: Query<&Transform, (With, Without, Without)>, @@ -1044,7 +1045,7 @@ fn update_target_selectagon( fn update_ar_overlays ( q_owners: Query<(Entity, &Transform, &Visibility), (With, Without)>, mut q_overlays: Query<(&mut Transform, &mut Visibility, &mut AugmentedRealityOverlay)>, - settings: ResMut, + settings: ResMut, mut state: ResMut, ) { let (need_activate, need_clean, need_update); @@ -1081,7 +1082,7 @@ fn update_poi_overlays ( mut q_marker: Query<(&mut Transform, &PointOfInterestMarker)>, q_parent: Query<&Transform, Without>, q_camera: Query<&Transform, (With, Without)>, - settings: ResMut, + settings: ResMut, ) { if !settings.hud_active || !settings.map_active || q_camera.is_empty() { return; @@ -1110,7 +1111,7 @@ fn update_overlay_visibility( q_target: Query<&IsTargeted, (Without, Without, Without, Without)>, mut ambient_light: ResMut, er_target: EventReader, - settings: Res, + settings: Res, ) { if er_target.is_empty() { return; diff --git a/src/load.rs b/src/load.rs index 3c98304..b44b44c 100644 --- a/src/load.rs +++ b/src/load.rs @@ -55,7 +55,7 @@ pub fn asset_name_to_path(name: &str) -> &'static str { } } -pub fn load( +pub fn load_asset( name: &str, entity_commands: &mut EntityCommands, asset_server: &AssetServer, diff --git a/src/main.rs b/src/main.rs index 6d51bf7..c828bb0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,11 @@ mod world; #[allow(dead_code)] mod nature; +pub mod prelude { + pub use crate::var::Settings; + pub use crate::load::load_asset; +} + use bevy::window::{Window, WindowMode, PrimaryWindow, CursorGrabMode}; use bevy::diagnostic::FrameTimeDiagnosticsPlugin; use bevy::prelude::*; diff --git a/src/world.rs b/src/world.rs index db7de0d..93cd310 100644 --- a/src/world.rs +++ b/src/world.rs @@ -10,6 +10,7 @@ // // This module populates the world with stars and asteroids. +use crate::prelude::*; use crate::{actor, hud, load, nature}; use bevy::prelude::*; use bevy::math::{DVec3, I64Vec3}; @@ -322,7 +323,7 @@ fn spawn_despawn_asteroids( }, ..default() }); - load::load(model, &mut entity_commands, &*asset_server); + load_asset(model, &mut entity_commands, &*asset_server); db.0.insert(origin, AsteroidData { entity: entity_commands.id(), //viewdistance: 99999999.0,