Skip to content

Commit

Permalink
Add tailwind palette
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmauro committed Apr 4, 2024
1 parent 2ccf3bf commit 5e191ed
Show file tree
Hide file tree
Showing 6 changed files with 406 additions and 130 deletions.
5 changes: 0 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ use bevy::prelude::*;
// tile
pub const TILE_SIZE: f32 = 100.0;
pub const TILE_SPACING: f32 = 10.0;
pub const TILE_COLOR_A: Color = Color::rgb(1.0, 0.56, 0.0);
pub const TILE_COLOR_B: Color = Color::rgb(0.60, 0.05, 1.0);
pub const TILE_COLOR_C: Color = Color::rgb(1.0, 0.0, 0.65);
pub const TILE_COLOR_D: Color = Color::rgb(0.12, 1.0, 0.14);
pub const TILE_COLOR_E: Color = Color::rgb(0.12, 0.80, 1.0);
pub const TILE_SOUND_C: &str = "sounds/letters/c.ogg";
pub const TILE_SOUND_H: &str = "sounds/letters/h.ogg";
pub const TILE_SOUND_K: &str = "sounds/letters/k.ogg";
Expand Down
116 changes: 1 addition & 115 deletions src/game/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use self::{
score::{GameScore, LatestGameScores},
settings::GameSettings,
tile::{color::TileColor, position::TilePosition, sound::TileSound, TileBundle, TilePlugin},
ui::button::{GameButtonBundle, GameButtonPlugin, Shortcut},
ui::button::GameButtonPlugin,
ui::UiPlugin,
};

Expand Down Expand Up @@ -54,7 +54,6 @@ impl Plugin for GamePlugin {
fn setup(
mut commands: Commands,
settings: Res<GameSettings>,
asset_server: Res<AssetServer>,
mut animations: ResMut<Assets<AnimationClip>>,
) {
// Add walls
Expand Down Expand Up @@ -169,119 +168,6 @@ fn setup(
},
OnGameScreen,
));

// buttons
commands
.spawn((
NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
..default()
},
OnGameScreen,
))
.with_children(|parent| {
if settings.position {
parent
.spawn(GameButtonBundle {
button: ButtonBundle {
style: Style {
left: Val::Px(-100.0),
top: Val::Px(230.0),
width: Val::Px(150.0),
height: Val::Px(65.0),
border: UiRect::all(Val::Px(3.0)),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
border_color: config::BUTTON_BORDER_COLOR.into(),
background_color: config::NORMAL_BUTTON.into(),
..default()
},
shortcut: Shortcut(KeyCode::KeyA),
})
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"Position (A)",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 20.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
));
});
}

if settings.sound {
parent
.spawn(GameButtonBundle {
button: ButtonBundle {
style: Style {
left: Val::Px(0.0),
top: Val::Px(230.0),
width: Val::Px(150.0),
height: Val::Px(65.0),
border: UiRect::all(Val::Px(3.0)),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
border_color: config::BUTTON_BORDER_COLOR.into(),
background_color: config::NORMAL_BUTTON.into(),
..default()
},
shortcut: Shortcut(KeyCode::KeyS),
})
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"Sound (S)",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 20.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
));
});
}

if settings.color {
parent
.spawn(GameButtonBundle {
button: ButtonBundle {
style: Style {
left: Val::Px(100.0),
top: Val::Px(230.0),
width: Val::Px(150.0),
height: Val::Px(65.0),
border: UiRect::all(Val::Px(3.0)),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
border_color: config::BUTTON_BORDER_COLOR.into(),
background_color: config::NORMAL_BUTTON.into(),
..default()
},
shortcut: Shortcut(KeyCode::KeyD),
})
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"Color (D)",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 20.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
));
});
}
});
}

/// Tick all the `CueTimer` components on entities within the scene using bevy's
Expand Down
14 changes: 7 additions & 7 deletions src/game/tile/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rand::{
Rng,
};

use crate::config;
use crate::palette;

#[derive(Component, Clone, Debug, Default, PartialEq)]
pub enum TileColor {
Expand Down Expand Up @@ -32,12 +32,12 @@ impl Distribution<TileColor> for Standard {
impl From<&TileColor> for Color {
fn from(c: &TileColor) -> Self {
match c {
TileColor::A => config::TILE_COLOR_A,
TileColor::B => config::TILE_COLOR_B,
TileColor::C => config::TILE_COLOR_C,
TileColor::D => config::TILE_COLOR_D,
TileColor::E => config::TILE_COLOR_E,
TileColor::None => config::TILE_COLOR_C,
TileColor::A => palette::RED_500,
TileColor::B => palette::ORANGE_500,
TileColor::C => palette::YELLOW_400,
TileColor::D => palette::EMERALD_500,
TileColor::E => palette::BLUE_500,
TileColor::None => palette::PURPLE_500,
}
}
}
129 changes: 126 additions & 3 deletions src/game/ui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,143 @@
use bevy::prelude::*;
use bevy_egui::{egui, EguiContexts};

use crate::state::AppState;
use crate::{
config,
state::{AppState, OnGameScreen},
};

use super::core::{cue::CueEngine, round::Round, score::Score, state::GameState};
use self::button::{GameButtonBundle, Shortcut};

use super::{
core::{cue::CueEngine, round::Round, score::Score, state::GameState},
settings::GameSettings,
};

pub mod button;

pub struct UiPlugin;

impl Plugin for UiPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, debug_ui.run_if(in_state(AppState::Game)));
app.add_systems(OnEnter(AppState::Game), setup)
.add_systems(Update, debug_ui.run_if(in_state(AppState::Game)));
}
}

pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>, settings: Res<GameSettings>) {
commands
.spawn((
NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
..default()
},
OnGameScreen,
))
.with_children(|parent| {
if settings.position {
parent
.spawn(GameButtonBundle {
button: ButtonBundle {
style: Style {
left: Val::Px(-100.0),
top: Val::Px(230.0),
width: Val::Px(150.0),
height: Val::Px(65.0),
border: UiRect::all(Val::Px(3.0)),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
border_color: config::BUTTON_BORDER_COLOR.into(),
background_color: config::NORMAL_BUTTON.into(),
..default()
},
shortcut: Shortcut(KeyCode::KeyA),
})
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"Position (A)",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 20.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
));
});
}

if settings.sound {
parent
.spawn(GameButtonBundle {
button: ButtonBundle {
style: Style {
left: Val::Px(0.0),
top: Val::Px(230.0),
width: Val::Px(150.0),
height: Val::Px(65.0),
border: UiRect::all(Val::Px(3.0)),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
border_color: config::BUTTON_BORDER_COLOR.into(),
background_color: config::NORMAL_BUTTON.into(),
..default()
},
shortcut: Shortcut(KeyCode::KeyS),
})
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"Sound (S)",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 20.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
));
});
}

if settings.color {
parent
.spawn(GameButtonBundle {
button: ButtonBundle {
style: Style {
left: Val::Px(100.0),
top: Val::Px(230.0),
width: Val::Px(150.0),
height: Val::Px(65.0),
border: UiRect::all(Val::Px(3.0)),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
border_color: config::BUTTON_BORDER_COLOR.into(),
background_color: config::NORMAL_BUTTON.into(),
..default()
},
shortcut: Shortcut(KeyCode::KeyD),
})
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"Color (D)",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 20.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
));
});
}
});
}

/// Debug interface.
pub fn debug_ui(
mut egui_context: EguiContexts,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ pub mod asset;
pub mod config;
pub mod game;
pub mod menu;
pub mod palette;
pub mod splash;
pub mod state;
Loading

0 comments on commit 5e191ed

Please sign in to comment.