add common.rs

This commit is contained in:
yuni 2024-05-13 00:44:03 +02:00
parent 8515603f2d
commit 78eeef6201
5 changed files with 54 additions and 46 deletions

45
src/common.rs Normal file
View file

@ -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()
}
}

View file

@ -313,13 +313,7 @@ pub fn setup(
let reticule_handle: Handle<Image> = asset_server.load("sprites/reticule4.png"); let reticule_handle: Handle<Image> = asset_server.load("sprites/reticule4.png");
commands.spawn(( commands.spawn((
NodeBundle { NodeBundle {
style: Style { style: style_centered(),
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::SpaceAround,
..default()
},
visibility, visibility,
..default() ..default()
}, },

View file

@ -16,6 +16,7 @@ pub mod audio;
pub mod camera; pub mod camera;
pub mod chat; pub mod chat;
pub mod cmd; pub mod cmd;
pub mod common;
pub mod game; pub mod game;
pub mod hud; pub mod hud;
pub mod load; pub mod load;
@ -27,16 +28,11 @@ pub mod visual;
pub mod world; pub mod world;
pub mod prelude { 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::var::{FONT, Settings};
pub use crate::load::load_asset; 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}; use bevy::window::{Window, WindowMode, PrimaryWindow, CursorGrabMode};

View file

@ -37,14 +37,7 @@ pub fn setup(
BlackScreen, BlackScreen,
DeathScreenElement, DeathScreenElement,
NodeBundle { NodeBundle {
style: Style { style: style_fullscreen(),
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()
},
background_color: Color::BLACK.into(), background_color: Color::BLACK.into(),
visibility: Visibility::Hidden, visibility: Visibility::Hidden,
..default() ..default()
@ -73,13 +66,7 @@ pub fn setup(
commands.spawn(( commands.spawn((
DeathScreenElement, DeathScreenElement,
NodeBundle { NodeBundle {
style: Style { style: style_centered(),
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::SpaceAround,
..default()
},
visibility: Visibility::Hidden, visibility: Visibility::Hidden,
..default() ..default()
}, },

View file

@ -94,14 +94,7 @@ pub fn spawn_effects(
}, },
FadeIn, FadeIn,
NodeBundle { NodeBundle {
style: Style { style: style_fullscreen(),
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()
},
background_color: color.into(), background_color: color.into(),
..default() ..default()
}, },
@ -116,14 +109,7 @@ pub fn spawn_effects(
}, },
FadeOut, FadeOut,
NodeBundle { NodeBundle {
style: Style { style: style_fullscreen(),
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()
},
background_color: color.with_a(0.0).into(), background_color: color.with_a(0.0).into(),
..default() ..default()
}, },