From 78eeef62011d622ab4de7929f73acf4be2efa319 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 13 May 2024 00:44:03 +0200 Subject: [PATCH] add common.rs --- src/common.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/hud.rs | 8 +------- src/main.rs | 12 ++++-------- src/menu.rs | 17 ++--------------- src/visual.rs | 18 ++---------------- 5 files changed, 54 insertions(+), 46 deletions(-) create mode 100644 src/common.rs diff --git a/src/common.rs b/src/common.rs new file mode 100644 index 0000000..5debfc5 --- /dev/null +++ b/src/common.rs @@ -0,0 +1,45 @@ +// ▄████████▄ + ███ + ▄█████████ ███ + +// ███▀ ▀███ + + ███ ███▀ + ███ + + +// ███ + ███ ███ ███ █████████ ███ ███ ███ ███ +// ███ +███ ███ ███ ███ ███▐██████ ███ ███ ███ +// ███ + ███ ███+ ███ +███ ███ + ███ ███ + ███ +// ███▄ ▄███ ███▄ ███ ███ + ███ + ███ ███▄ ███ +// ▀████████▀ + ▀███████ ███▄ ███▄ ▀████ ▀███████ +// + + + ███ +// + ▀████████████████████████████████████████████████████▀ +// +// Various common functions + +use bevy::prelude::*; + +#[inline] +pub fn bool2vis(boolean: bool) -> bevy::prelude::Visibility { + if boolean { + bevy::prelude::Visibility::Inherited + } else { + bevy::prelude::Visibility::Hidden + } +} + +#[inline] +pub fn style_fullscreen() -> Style { + Style { + width: Val::Vw(100.0), + height: Val::Vh(100.0), + position_type: PositionType::Absolute, + top: Val::Px(0.0), + left: Val::Px(0.0), + ..default() + } +} + +#[inline] +pub fn style_centered() -> Style { + Style { + width: Val::Percent(100.0), + height: Val::Percent(100.0), + align_items: AlignItems::Center, + justify_content: JustifyContent::SpaceAround, + ..default() + } +} diff --git a/src/hud.rs b/src/hud.rs index 9b668eb..e22a7e3 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -313,13 +313,7 @@ pub fn setup( let reticule_handle: Handle = asset_server.load("sprites/reticule4.png"); commands.spawn(( NodeBundle { - style: Style { - width: Val::Percent(100.0), - height: Val::Percent(100.0), - align_items: AlignItems::Center, - justify_content: JustifyContent::SpaceAround, - ..default() - }, + style: style_centered(), visibility, ..default() }, diff --git a/src/main.rs b/src/main.rs index 3e29167..771b7b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ pub mod audio; pub mod camera; pub mod chat; pub mod cmd; +pub mod common; pub mod game; pub mod hud; pub mod load; @@ -27,16 +28,11 @@ pub mod visual; pub mod world; pub mod prelude { - pub use crate::{actor, audio, camera, chat, cmd, game, hud, load, menu, nature, var, visual, world}; + pub use crate::{actor, audio, camera, chat, cmd, common, game, hud, + load, menu, nature, var, visual, world}; + pub use crate::common::*; pub use crate::var::{FONT, Settings}; pub use crate::load::load_asset; - pub fn bool2vis(boolean: bool) -> bevy::prelude::Visibility { - if boolean { - bevy::prelude::Visibility::Inherited - } else { - bevy::prelude::Visibility::Hidden - } - } } use bevy::window::{Window, WindowMode, PrimaryWindow, CursorGrabMode}; diff --git a/src/menu.rs b/src/menu.rs index c296a4d..95e02db 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -37,14 +37,7 @@ pub fn setup( BlackScreen, DeathScreenElement, NodeBundle { - style: Style { - width: Val::Vw(100.0), - height: Val::Vh(100.0), - position_type: PositionType::Absolute, - top: Val::Px(0.0), - left: Val::Px(0.0), - ..default() - }, + style: style_fullscreen(), background_color: Color::BLACK.into(), visibility: Visibility::Hidden, ..default() @@ -73,13 +66,7 @@ pub fn setup( commands.spawn(( DeathScreenElement, NodeBundle { - style: Style { - width: Val::Percent(100.0), - height: Val::Percent(100.0), - align_items: AlignItems::Center, - justify_content: JustifyContent::SpaceAround, - ..default() - }, + style: style_centered(), visibility: Visibility::Hidden, ..default() }, diff --git a/src/visual.rs b/src/visual.rs index 2ad6ce4..74a8376 100644 --- a/src/visual.rs +++ b/src/visual.rs @@ -94,14 +94,7 @@ pub fn spawn_effects( }, FadeIn, NodeBundle { - style: Style { - width: Val::Vw(100.0), - height: Val::Vh(100.0), - position_type: PositionType::Absolute, - top: Val::Px(0.0), - left: Val::Px(0.0), - ..default() - }, + style: style_fullscreen(), background_color: color.into(), ..default() }, @@ -116,14 +109,7 @@ pub fn spawn_effects( }, FadeOut, NodeBundle { - style: Style { - width: Val::Vw(100.0), - height: Val::Vh(100.0), - position_type: PositionType::Absolute, - top: Val::Px(0.0), - left: Val::Px(0.0), - ..default() - }, + style: style_fullscreen(), background_color: color.with_a(0.0).into(), ..default() },