add common.rs
This commit is contained in:
parent
8515603f2d
commit
78eeef6201
45
src/common.rs
Normal file
45
src/common.rs
Normal 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()
|
||||
}
|
||||
}
|
|
@ -313,13 +313,7 @@ pub fn setup(
|
|||
let reticule_handle: Handle<Image> = 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()
|
||||
},
|
||||
|
|
12
src/main.rs
12
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};
|
||||
|
|
17
src/menu.rs
17
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()
|
||||
},
|
||||
|
|
|
@ -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()
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue