add crate prelude

This commit is contained in:
yuni 2024-05-12 21:06:38 +02:00
parent 984830e77b
commit 7aa6885509
5 changed files with 26 additions and 18 deletions

View file

@ -15,6 +15,7 @@ use bevy::prelude::*;
use bevy_xpbd_3d::prelude::*; use bevy_xpbd_3d::prelude::*;
use bevy::math::DVec3; use bevy::math::DVec3;
use bevy::pbr::{NotShadowCaster, NotShadowReceiver}; use bevy::pbr::{NotShadowCaster, NotShadowReceiver};
use crate::prelude::*;
use crate::{actor, camera, chat, hud, load, nature, var, world}; use crate::{actor, camera, chat, hud, load, nature, var, world};
use regex::Regex; use regex::Regex;
use std::f32::consts::PI; use std::f32::consts::PI;
@ -624,7 +625,7 @@ fn spawn_entities(
transform: Transform::from_scale(scale), transform: Transform::from_scale(scale),
..default() ..default()
}); });
load::load(model.as_str(), &mut actor, &*asset_server); load_asset(model.as_str(), &mut actor, &*asset_server);
} }
actor.insert(Rotation::from(rotation)); actor.insert(Rotation::from(rotation));
@ -802,7 +803,7 @@ fn spawn_entities(
NotShadowCaster, NotShadowCaster,
NotShadowReceiver, 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 { if state.is_point_of_interest || state.is_moon || state.is_planet {
@ -824,7 +825,7 @@ fn spawn_entities(
} else { } else {
"marker_satellites" "marker_satellites"
}; };
load::load(model, &mut entitycmd, &*asset_server); load_asset(model, &mut entitycmd, &*asset_server);
} }
if state.has_ring { if state.has_ring {

View file

@ -10,7 +10,8 @@
// //
// This module manages the heads-up display and augmented reality overlays. // 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::pbr::{NotShadowCaster, NotShadowReceiver};
use bevy::prelude::*; use bevy::prelude::*;
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}; use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
@ -215,7 +216,7 @@ impl Log {
fn setup( fn setup(
mut commands: Commands, mut commands: Commands,
settings: Res<var::Settings>, settings: Res<Settings>,
asset_server: Res<AssetServer>, asset_server: Res<AssetServer>,
mut ew_updateoverlays: EventWriter<UpdateOverlayVisibility>, mut ew_updateoverlays: EventWriter<UpdateOverlayVisibility>,
) { ) {
@ -612,7 +613,7 @@ fn setup(
..default() ..default()
}, },
)); ));
load::load("selectagon", &mut entitycmd, &*asset_server); load_asset("selectagon", &mut entitycmd, &*asset_server);
ew_updateoverlays.send(UpdateOverlayVisibility); ew_updateoverlays.send(UpdateOverlayVisibility);
} }
@ -621,7 +622,7 @@ fn update_dashboard(
timer: ResMut<FPSUpdateTimer>, timer: ResMut<FPSUpdateTimer>,
mut q_dashboard: Query<(&mut Visibility, &Dashboard)>, mut q_dashboard: Query<(&mut Visibility, &Dashboard)>,
q_player: Query<&actor::Suit, With<actor::Player>>, q_player: Query<&actor::Suit, With<actor::Player>>,
settings: Res<var::Settings>, settings: Res<Settings>,
) { ) {
if !settings.hud_active || !timer.0.just_finished() { if !settings.hud_active || !timer.0.just_finished() {
return; return;
@ -644,7 +645,7 @@ fn update_dashboard(
fn update_speedometer( fn update_speedometer(
timer: ResMut<FPSUpdateTimer>, timer: ResMut<FPSUpdateTimer>,
settings: Res<var::Settings>, settings: Res<Settings>,
q_camera: Query<&LinearVelocity, With<actor::PlayerCamera>>, q_camera: Query<&LinearVelocity, With<actor::PlayerCamera>>,
q_player: Query<&actor::ExperiencesGForce, With<actor::Player>>, q_player: Query<&actor::ExperiencesGForce, With<actor::Player>>,
q_target: Query<&LinearVelocity, With<IsTargeted>>, q_target: Query<&LinearVelocity, With<IsTargeted>>,
@ -709,7 +710,7 @@ fn update_gauges(
timer: ResMut<FPSUpdateTimer>, timer: ResMut<FPSUpdateTimer>,
q_player: Query<(&actor::HitPoints, &actor::Suit, &actor::Battery), With<actor::Player>>, q_player: Query<(&actor::HitPoints, &actor::Suit, &actor::Battery), With<actor::Player>>,
mut q_gauges: Query<(&mut Style, &mut BackgroundColor, &Gauge, &GaugeLength)>, mut q_gauges: Query<(&mut Style, &mut BackgroundColor, &Gauge, &GaugeLength)>,
settings: Res<var::Settings>, settings: Res<Settings>,
) { ) {
if !settings.hud_active || !timer.0.just_finished() { if !settings.hud_active || !timer.0.just_finished() {
return; return;
@ -747,7 +748,7 @@ fn update_hud(
mut q_node_console: Query<&mut Text, (With<NodeConsole>, Without<NodeHud>, Without<NodeChoiceText>)>, mut q_node_console: Query<&mut Text, (With<NodeConsole>, Without<NodeHud>, Without<NodeChoiceText>)>,
mut q_node_choice: Query<&mut Text, (With<NodeChoiceText>, Without<NodeHud>, Without<NodeConsole>)>, mut q_node_choice: Query<&mut Text, (With<NodeChoiceText>, Without<NodeHud>, Without<NodeConsole>)>,
mut q_node_currentline: Query<&mut Text, (With<NodeCurrentChatLine>, Without<NodeHud>, Without<NodeConsole>, Without<NodeChoiceText>)>, mut q_node_currentline: Query<&mut Text, (With<NodeCurrentChatLine>, Without<NodeHud>, Without<NodeConsole>, Without<NodeChoiceText>)>,
settings: Res<var::Settings>, settings: Res<Settings>,
q_target: Query<(&IsClickable, Option<&Position>, Option<&LinearVelocity>), With<IsTargeted>>, q_target: Query<(&IsClickable, Option<&Position>, Option<&LinearVelocity>), With<IsTargeted>>,
) { ) {
if timer.0.tick(time.delta()).just_finished() || log.needs_rerendering { if timer.0.tick(time.delta()).just_finished() || log.needs_rerendering {
@ -944,7 +945,7 @@ fn update_hud(
fn handle_input( fn handle_input(
keyboard_input: Res<ButtonInput<KeyCode>>, keyboard_input: Res<ButtonInput<KeyCode>>,
mouse_input: Res<ButtonInput<MouseButton>>, mouse_input: Res<ButtonInput<MouseButton>>,
mut settings: ResMut<var::Settings>, mut settings: ResMut<Settings>,
mut log: ResMut<Log>, mut log: ResMut<Log>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>, mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_togglemusic: EventWriter<audio::ToggleMusicEvent>, mut ew_togglemusic: EventWriter<audio::ToggleMusicEvent>,
@ -980,7 +981,7 @@ fn handle_input(
fn handle_target_event( fn handle_target_event(
mut commands: Commands, mut commands: Commands,
settings: Res<var::Settings>, settings: Res<Settings>,
mut er_target: EventReader<TargetEvent>, mut er_target: EventReader<TargetEvent>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>, mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
q_target: Query<Entity, With<IsTargeted>>, q_target: Query<Entity, With<IsTargeted>>,
@ -1004,7 +1005,7 @@ fn handle_target_event(
} }
fn update_target_selectagon( fn update_target_selectagon(
settings: Res<var::Settings>, settings: Res<Settings>,
mut q_selectagon: Query<(&mut Transform, &mut Visibility), (With<Selectagon>, Without<IsTargeted>, Without<Camera>)>, mut q_selectagon: Query<(&mut Transform, &mut Visibility), (With<Selectagon>, Without<IsTargeted>, Without<Camera>)>,
q_target: Query<&Transform, (With<IsTargeted>, Without<Camera>, Without<Selectagon>)>, q_target: Query<&Transform, (With<IsTargeted>, Without<Camera>, Without<Selectagon>)>,
q_camera: Query<&Transform, (With<Camera>, Without<IsTargeted>, Without<Selectagon>)>, q_camera: Query<&Transform, (With<Camera>, Without<IsTargeted>, Without<Selectagon>)>,
@ -1044,7 +1045,7 @@ fn update_target_selectagon(
fn update_ar_overlays ( fn update_ar_overlays (
q_owners: Query<(Entity, &Transform, &Visibility), (With<AugmentedRealityOverlayBroadcaster>, Without<AugmentedRealityOverlay>)>, q_owners: Query<(Entity, &Transform, &Visibility), (With<AugmentedRealityOverlayBroadcaster>, Without<AugmentedRealityOverlay>)>,
mut q_overlays: Query<(&mut Transform, &mut Visibility, &mut AugmentedRealityOverlay)>, mut q_overlays: Query<(&mut Transform, &mut Visibility, &mut AugmentedRealityOverlay)>,
settings: ResMut<var::Settings>, settings: ResMut<Settings>,
mut state: ResMut<AugmentedRealityState>, mut state: ResMut<AugmentedRealityState>,
) { ) {
let (need_activate, need_clean, need_update); let (need_activate, need_clean, need_update);
@ -1081,7 +1082,7 @@ fn update_poi_overlays (
mut q_marker: Query<(&mut Transform, &PointOfInterestMarker)>, mut q_marker: Query<(&mut Transform, &PointOfInterestMarker)>,
q_parent: Query<&Transform, Without<PointOfInterestMarker>>, q_parent: Query<&Transform, Without<PointOfInterestMarker>>,
q_camera: Query<&Transform, (With<Camera>, Without<PointOfInterestMarker>)>, q_camera: Query<&Transform, (With<Camera>, Without<PointOfInterestMarker>)>,
settings: ResMut<var::Settings>, settings: ResMut<Settings>,
) { ) {
if !settings.hud_active || !settings.map_active || q_camera.is_empty() { if !settings.hud_active || !settings.map_active || q_camera.is_empty() {
return; return;
@ -1110,7 +1111,7 @@ fn update_overlay_visibility(
q_target: Query<&IsTargeted, (Without<Camera>, Without<Selectagon>, Without<PointOfInterestMarker>, Without<ToggleableHudElement>)>, q_target: Query<&IsTargeted, (Without<Camera>, Without<Selectagon>, Without<PointOfInterestMarker>, Without<ToggleableHudElement>)>,
mut ambient_light: ResMut<AmbientLight>, mut ambient_light: ResMut<AmbientLight>,
er_target: EventReader<UpdateOverlayVisibility>, er_target: EventReader<UpdateOverlayVisibility>,
settings: Res<var::Settings>, settings: Res<Settings>,
) { ) {
if er_target.is_empty() { if er_target.is_empty() {
return; return;

View file

@ -55,7 +55,7 @@ pub fn asset_name_to_path(name: &str) -> &'static str {
} }
} }
pub fn load( pub fn load_asset(
name: &str, name: &str,
entity_commands: &mut EntityCommands, entity_commands: &mut EntityCommands,
asset_server: &AssetServer, asset_server: &AssetServer,

View file

@ -25,6 +25,11 @@ mod world;
#[allow(dead_code)] #[allow(dead_code)]
mod nature; 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::window::{Window, WindowMode, PrimaryWindow, CursorGrabMode};
use bevy::diagnostic::FrameTimeDiagnosticsPlugin; use bevy::diagnostic::FrameTimeDiagnosticsPlugin;
use bevy::prelude::*; use bevy::prelude::*;

View file

@ -10,6 +10,7 @@
// //
// This module populates the world with stars and asteroids. // This module populates the world with stars and asteroids.
use crate::prelude::*;
use crate::{actor, hud, load, nature}; use crate::{actor, hud, load, nature};
use bevy::prelude::*; use bevy::prelude::*;
use bevy::math::{DVec3, I64Vec3}; use bevy::math::{DVec3, I64Vec3};
@ -322,7 +323,7 @@ fn spawn_despawn_asteroids(
}, },
..default() ..default()
}); });
load::load(model, &mut entity_commands, &*asset_server); load_asset(model, &mut entity_commands, &*asset_server);
db.0.insert(origin, AsteroidData { db.0.insert(origin, AsteroidData {
entity: entity_commands.id(), entity: entity_commands.id(),
//viewdistance: 99999999.0, //viewdistance: 99999999.0,