From 4145abda19fe236dcc1037c46e898d7ff0b3010d Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sun, 5 Jan 2025 00:33:27 +0200 Subject: [PATCH] =?UTF-8?q?feat(colors):=20add=20all=20Ros=C3=A9=20Pine=20?= =?UTF-8?q?variants?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- justfile | 4 +- src/constants.rs | 2 +- src/floor/systems/fog.rs | 18 +++ src/floor/systems/mod.rs | 3 + src/floor/systems/movement.rs | 3 - src/lib.rs | 11 +- src/maze/assets.rs | 6 +- src/maze/triggers/spawn.rs | 7 +- src/player/assets.rs | 4 +- src/theme/palette/rose_pine.rs | 219 +++++++++++++++++++++++++++------ 10 files changed, 222 insertions(+), 55 deletions(-) create mode 100644 src/floor/systems/fog.rs diff --git a/justfile b/justfile index a1d667d..1c2d281 100644 --- a/justfile +++ b/justfile @@ -8,7 +8,7 @@ native-dev: # Run native release native-release: - cargo run --release --no-default-features + RUSTC_WRAPPER=sccache cargo run --release --no-default-features # Run web dev web-dev: @@ -16,7 +16,7 @@ web-dev: # Run web release web-release: - trunk serve --release --no-default-features + RUSTC_WRAPPER=sccache trunk serve --release --no-default-features # Run tests test: diff --git a/src/constants.rs b/src/constants.rs index d603828..e806040 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,4 +1,4 @@ pub const MOVEMENT_THRESHOLD: f32 = 0.01; pub const WALL_OVERLAP_MODIFIER: f32 = 1.25; -pub const FLOOR_Y_OFFSET: u8 = 100; +pub const FLOOR_Y_OFFSET: u8 = 200; pub const MOVEMENT_COOLDOWN: f32 = 1.0; // one second cooldown diff --git a/src/floor/systems/fog.rs b/src/floor/systems/fog.rs new file mode 100644 index 0000000..0c1de24 --- /dev/null +++ b/src/floor/systems/fog.rs @@ -0,0 +1,18 @@ +use bevy::prelude::*; + +use crate::theme::{palette::rose_pine::RosePineDawn, prelude::ColorScheme}; + +pub fn setup_camera_fog(mut commands: Commands) { + commands.spawn(( + Name::new("Fog"), + DistanceFog { + color: RosePineDawn::Overlay.to_color(), + directional_light_color: RosePineDawn::Overlay.to_color(), + falloff: FogFalloff::Linear { + start: 1., + end: 20., + }, + ..default() + }, + )); +} diff --git a/src/floor/systems/mod.rs b/src/floor/systems/mod.rs index 8428a20..e8e252f 100644 --- a/src/floor/systems/mod.rs +++ b/src/floor/systems/mod.rs @@ -1,14 +1,17 @@ mod despawn; +mod fog; mod movement; mod spawn; use crate::maze::MazePluginLoaded; use bevy::prelude::*; use despawn::despawn_floor; +use fog::setup_camera_fog; use movement::{handle_floor_transition_events, move_floors}; use spawn::spawn_floor; pub(super) fn plugin(app: &mut App) { + app.add_systems(Startup, setup_camera_fog); app.add_systems( Update, ( diff --git a/src/floor/systems/movement.rs b/src/floor/systems/movement.rs index bfe1e01..48140f4 100644 --- a/src/floor/systems/movement.rs +++ b/src/floor/systems/movement.rs @@ -48,7 +48,6 @@ pub fn handle_floor_transition_events( } for event in event_reader.read() { - dbg!(&event); let Some((current_entity, current_floor)) = current_query.get_single().ok() else { continue; }; @@ -68,7 +67,6 @@ pub fn handle_floor_transition_events( for (entity, transforms, _, movement_state) in maze_query.iter_mut() { let target_y = (FLOOR_Y_OFFSET as f32).mul_add(direction, transforms.translation.y); - dbg!(movement_state, target_y); if movement_state.is_none() { commands.entity(entity).insert(FloorYTarget(target_y)); } @@ -77,7 +75,6 @@ pub fn handle_floor_transition_events( update_current_next_floor(&mut commands, current_entity, target_entity); break; } - event_reader.clear(); } fn update_current_next_floor(commands: &mut Commands, current: Entity, target: Entity) { diff --git a/src/lib.rs b/src/lib.rs index ef7ecd9..da23fd1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ use bevy::{ audio::{AudioPlugin, Volume}, prelude::*, }; +use theme::{palette::rose_pine, prelude::ColorScheme}; pub struct AppPlugin; @@ -26,7 +27,7 @@ impl Plugin for AppPlugin { ); // Spawn the main camera. - app.add_systems(Startup, spawn_camera); + app.add_systems(Startup, (spawn_camera, load_background)); // Add Bevy plugins. app.add_plugins( @@ -100,3 +101,11 @@ fn spawn_camera(mut commands: Commands) { IsDefaultUiCamera, )); } + +fn load_background(mut commands: Commands) { + #[cfg(feature = "dev")] + let colorcheme = rose_pine::RosePine::Base; + #[cfg(not(feature = "dev"))] + let colorcheme = rose_pine::RosePineDawn::Base; + commands.insert_resource(ClearColor(colorcheme.to_color())); +} diff --git a/src/maze/assets.rs b/src/maze/assets.rs index 2548297..7b9f108 100644 --- a/src/maze/assets.rs +++ b/src/maze/assets.rs @@ -1,7 +1,7 @@ use super::resources::GlobalMazeConfig; use crate::{ constants::WALL_OVERLAP_MODIFIER, - theme::{palette::rose_pine::RosePine, prelude::ColorScheme}, + theme::{palette::rose_pine::RosePineDawn, prelude::ColorScheme}, }; use bevy::{prelude::*, utils::HashMap}; use std::f32::consts::FRAC_PI_2; @@ -15,7 +15,7 @@ pub struct MazeAssets { pub wall_mesh: Handle, pub hex_material: Handle, pub wall_material: Handle, - pub custom_materials: HashMap>, + pub custom_materials: HashMap>, } impl MazeAssets { @@ -24,7 +24,7 @@ impl MazeAssets { materials: &mut ResMut>, global_config: &GlobalMazeConfig, ) -> Self { - let custom_materials = RosePine::iter() + let custom_materials = RosePineDawn::iter() .map(|color| (color, materials.add(color.to_standart_material()))) .collect(); Self { diff --git a/src/maze/triggers/spawn.rs b/src/maze/triggers/spawn.rs index 9ed2179..ba02770 100644 --- a/src/maze/triggers/spawn.rs +++ b/src/maze/triggers/spawn.rs @@ -8,8 +8,9 @@ use crate::{ events::SpawnMaze, resources::GlobalMazeConfig, }, - theme::palette::rose_pine::RosePine, + theme::palette::rose_pine::RosePineDawn, }; + use bevy::prelude::*; use hexlab::prelude::{Tile as HexTile, *}; use hexx::HexOrientation; @@ -100,12 +101,12 @@ pub(super) fn spawn_single_hex_tile( let material = match tile.pos() { pos if pos == maze_config.start_pos => assets .custom_materials - .get(&RosePine::Pine) + .get(&RosePineDawn::Pine) .cloned() .unwrap_or_default(), pos if pos == maze_config.end_pos => assets .custom_materials - .get(&RosePine::Love) + .get(&RosePineDawn::Love) .cloned() .unwrap_or_default(), _ => assets.hex_material.clone(), diff --git a/src/player/assets.rs b/src/player/assets.rs index fe2c77a..0f8345a 100644 --- a/src/player/assets.rs +++ b/src/player/assets.rs @@ -1,6 +1,6 @@ use bevy::prelude::*; -use crate::theme::{palette::rose_pine::RosePine, prelude::ColorScheme}; +use crate::theme::{palette::rose_pine::RosePineDawn, prelude::ColorScheme}; pub(super) fn generate_pill_mesh(radius: f32, half_length: f32) -> Mesh { Mesh::from(Capsule3d { @@ -10,7 +10,7 @@ pub(super) fn generate_pill_mesh(radius: f32, half_length: f32) -> Mesh { } pub(super) fn blue_material() -> StandardMaterial { - let color = RosePine::Pine; + let color = RosePineDawn::Pine; StandardMaterial { base_color: color.to_color(), emissive: color.to_linear_rgba() * 3., diff --git a/src/theme/palette/rose_pine.rs b/src/theme/palette/rose_pine.rs index 5d1fa3e..507b577 100644 --- a/src/theme/palette/rose_pine.rs +++ b/src/theme/palette/rose_pine.rs @@ -1,45 +1,184 @@ -use super::rgb_u8; -use crate::theme::prelude::ColorScheme; +use crate::{ + create_color_scheme, + theme::{colorscheme::ColorScheme, palette::rgb_u8}, +}; use bevy::prelude::*; use strum::EnumIter; -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter)] -pub enum RosePine { - Base, - Surface, - Overlay, - Muted, - Subtle, - Text, - Love, - Gold, - Rose, - Pine, - Foam, - Iris, - HighlightLow, - HighlightMed, - HighlightHigh, -} - -impl ColorScheme for RosePine { - fn to_color(&self) -> Color { - match self { - Self::Base => rgb_u8(25, 23, 36), - Self::Surface => rgb_u8(31, 29, 46), - Self::Overlay => rgb_u8(38, 35, 58), - Self::Muted => rgb_u8(110, 106, 134), - Self::Subtle => rgb_u8(144, 140, 170), - Self::Text => rgb_u8(224, 222, 244), - Self::Love => rgb_u8(235, 111, 146), - Self::Gold => rgb_u8(246, 193, 119), - Self::Rose => rgb_u8(235, 188, 186), - Self::Pine => rgb_u8(49, 116, 143), - Self::Foam => rgb_u8(156, 207, 216), - Self::Iris => rgb_u8(196, 167, 231), - Self::HighlightLow => rgb_u8(33, 32, 46), - Self::HighlightMed => rgb_u8(64, 61, 82), - Self::HighlightHigh => rgb_u8(82, 79, 103), - } +create_color_scheme!( + pub RosePine, { + Base: "#191724", + Surface: "#1f1d2e", + Overlay: "#26233a", + Muted: "#6e6a86", + Subtle: "#908caa", + Text: "#e0def4", + Love: "#eb6f92", + Gold: "#f6c177", + Rose: "#ebbcba", + Pine: "#31748f", + Foam: "#9ccfd8", + Iris: "#c4a7e7", + HighlightLow: "#21202e", + HighlightMed: "#403d52", + HighlightHigh: "#524f67" } +); + +create_color_scheme!( + pub RosePineMoon, { + Base: "#232136", + Surface: "#2a273f", + Overlay: "#393552", + Muted: "#6e6a86", + Subtle: "#908caa", + Text: "#e0def4", + Love: "#eb6f92", + Gold: "#f6c177", + Rose: "#ea9a97", + Pine: "#3e8fb0", + Foam: "#9ccfd8", + Iris: "#c4a7e7", + HighlightLow: "#2a283e", + HighlightMed: "#44415a", + HighlightHigh: "#56526e" + } +); + +create_color_scheme!( + pub RosePineDawn, { + Base: "#faf4ed", + Surface: "#fffaf3", + Overlay: "#f2e9e1", + Muted: "#9893a5", + Subtle: "#797593", + Text: "#575279", + Love: "#b4637a", + Gold: "#ea9d34", + Rose: "#d7827e", + Pine: "#286983", + Foam: "#56949f", + Iris: "#907aa9", + HighlightLow: "#f4ede8", + HighlightMed: "#dfdad9", + HighlightHigh: "#cecacd" + } +); + +#[macro_export] +macro_rules! create_color_scheme { + ($(#[$meta:meta])* $vis:vis $name:ident, { + Base: $base:expr, + Surface: $surface:expr, + Overlay: $overlay:expr, + Muted: $muted:expr, + Subtle: $subtle:expr, + Text: $text:expr, + Love: $love:expr, + Gold: $gold:expr, + Rose: $rose:expr, + Pine: $pine:expr, + Foam: $foam:expr, + Iris: $iris:expr, + HighlightLow: $hl_low:expr, + HighlightMed: $hl_med:expr, + HighlightHigh: $hl_high:expr + }) => { + $(#[$meta])* + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter)] + $vis enum $name { + Base, + Surface, + Overlay, + Muted, + Subtle, + Text, + Love, + Gold, + Rose, + Pine, + Foam, + Iris, + HighlightLow, + HighlightMed, + HighlightHigh, + } + + impl $name { + fn hex_to_rgb(hex: &str) -> (u8, u8, u8) { + let hex = if hex.starts_with('#') { &hex[1..] } else { hex }; + let r = u8::from_str_radix(&hex[0..2], 16).unwrap_or(0); + let g = u8::from_str_radix(&hex[2..4], 16).unwrap_or(0); + let b = u8::from_str_radix(&hex[4..6], 16).unwrap_or(0); + (r, g, b) + } + } + + impl ColorScheme for $name { + fn to_color(&self) -> Color { + match self { + Self::Base => { + let (r, g, b) = Self::hex_to_rgb($base); + rgb_u8(r, g, b) + }, + Self::Surface => { + let (r, g, b) = Self::hex_to_rgb($surface); + rgb_u8(r, g, b) + }, + Self::Overlay => { + let (r, g, b) = Self::hex_to_rgb($overlay); + rgb_u8(r, g, b) + }, + Self::Muted => { + let (r, g, b) = Self::hex_to_rgb($muted); + rgb_u8(r, g, b) + }, + Self::Subtle => { + let (r, g, b) = Self::hex_to_rgb($subtle); + rgb_u8(r, g, b) + }, + Self::Text => { + let (r, g, b) = Self::hex_to_rgb($text); + rgb_u8(r, g, b) + }, + Self::Love => { + let (r, g, b) = Self::hex_to_rgb($love); + rgb_u8(r, g, b) + }, + Self::Gold => { + let (r, g, b) = Self::hex_to_rgb($gold); + rgb_u8(r, g, b) + }, + Self::Rose => { + let (r, g, b) = Self::hex_to_rgb($rose); + rgb_u8(r, g, b) + }, + Self::Pine => { + let (r, g, b) = Self::hex_to_rgb($pine); + rgb_u8(r, g, b) + }, + Self::Foam => { + let (r, g, b) = Self::hex_to_rgb($foam); + rgb_u8(r, g, b) + }, + Self::Iris => { + let (r, g, b) = Self::hex_to_rgb($iris); + rgb_u8(r, g, b) + }, + Self::HighlightLow => { + let (r, g, b) = Self::hex_to_rgb($hl_low); + rgb_u8(r, g, b) + }, + Self::HighlightMed => { + let (r, g, b) = Self::hex_to_rgb($hl_med); + rgb_u8(r, g, b) + }, + Self::HighlightHigh => { + let (r, g, b) = Self::hex_to_rgb($hl_high); + rgb_u8(r, g, b) + }, + } + } + } + }; }