Skip to content

Commit

Permalink
Update level display text
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jul 27, 2024
1 parent 4380096 commit 9c5ee20
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
12 changes: 5 additions & 7 deletions src/game/actor/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::core::UpdateSet;
use crate::util::prelude::*;

pub(super) fn plugin(app: &mut App) {
app.configure::<(ConfigHandle<LevelConfig>, Level, IsLevelIndicator)>();
app.configure::<(ConfigHandle<LevelConfig>, Level, IsLevelDisplay)>();

app.add_plugins((up::plugin, xp::plugin));
}
Expand Down Expand Up @@ -54,26 +54,24 @@ impl Configure for Level {

#[derive(Component, Reflect)]
#[reflect(Component)]
pub struct IsLevelIndicator;
pub struct IsLevelDisplay;

impl Configure for IsLevelIndicator {
impl Configure for IsLevelDisplay {
fn configure(app: &mut App) {
app.register_type::<Self>();
app.add_systems(Update, update_level_indicator.in_set(UpdateSet::SyncLate));
}
}

fn update_level_indicator(
mut indicator_query: Query<(&mut Text, &Selection), With<IsLevelIndicator>>,
mut indicator_query: Query<(&mut Text, &Selection), With<IsLevelDisplay>>,
level_query: Query<&Level>,
) {
for (mut text, selection) in &mut indicator_query {
let level = c!(level_query.get(selection.0));
let level = level.current + level.up;
let level = level.to_string();

for section in &mut text.sections {
section.value.clone_from(&level);
}
text.sections[1].value.clone_from(&level);
}
}
32 changes: 18 additions & 14 deletions src/screen/playing/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bevy::ecs::system::SystemState;
use bevy::prelude::*;

use crate::game::actor::level::xp::IsXpBarFill;
use crate::game::actor::level::IsLevelIndicator;
use crate::game::actor::level::IsLevelDisplay;
use crate::game::card::deck::IsDeckDisplay;
use crate::game::card::CardConfig;
use crate::screen::playing::PlayingAssets;
Expand Down Expand Up @@ -52,30 +52,34 @@ fn upper_hud(player: Entity) -> impl EntityCommand<World> {
},
))
.with_children(|children| {
children.spawn_with(level_indicator(player));
children.spawn_with(level_display(player));
children.spawn_with(xp_bar(player));
});
}
}

fn level_indicator(player: Entity) -> impl EntityCommand<World> {
fn level_display(player: Entity) -> impl EntityCommand<World> {
const TEXT_STYLE: TextStyle = TextStyle {
font: FONT_HANDLE,
font_size: 32.0,
color: Color::WHITE,
};

move |mut entity: EntityWorldMut| {
entity.insert((
Name::new("LevelIndicator"),
TextBundle::from_section(
"",
TextStyle {
font: FONT_HANDLE,
font_size: 32.0,
..default()
},
)
Name::new("LevelDisplay"),
TextBundle::from_sections([
TextSection::new("Level ", TEXT_STYLE),
TextSection::new("", TEXT_STYLE),
TextSection::new("/10", TEXT_STYLE),
])
.with_no_wrap()
.with_style(Style {
margin: UiRect::new(Val::ZERO, Px(-4.0), Px(-4.0), Val::ZERO),
..default()
}),
ThemeColorForText(vec![ThemeColor::Indicator]),
IsLevelIndicator,
ThemeColorForText(vec![ThemeColor::Indicator; 3]),
IsLevelDisplay,
Selection(player),
));
}
Expand Down

0 comments on commit 9c5ee20

Please sign in to comment.