Skip to content

Commit 09e56e4

Browse files
committed
Fix clippy warning
1 parent 8f4ff76 commit 09e56e4

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed
File renamed without changes.

src/game/actor/health.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,33 @@ use crate::game::combat::death::OnDeath;
1010
use crate::util::prelude::*;
1111

1212
pub(super) fn plugin(app: &mut App) {
13-
app.configure::<(Health, ConfigHandle<HealthBarConfig>, HealthBar)>();
13+
app.configure::<(ConfigHandle<HealthConfig>, Health, HealthBar)>();
14+
}
15+
16+
#[derive(Asset, Reflect, Serialize, Deserialize)]
17+
pub struct HealthConfig {
18+
pub color_ramp: Vec<Color>,
19+
}
20+
21+
impl Config for HealthConfig {
22+
const PATH: &'static str = "config/health.ron";
23+
const EXTENSION: &'static str = "health.ron";
24+
}
25+
26+
impl HealthConfig {
27+
fn color(&self, t: f32) -> Color {
28+
let n = self.color_ramp.len();
29+
let t = t * (n - 1) as f32;
30+
let lo = t as usize;
31+
let hi = lo + 1;
32+
let t = t.fract();
33+
34+
if hi >= n {
35+
self.color_ramp[n - 1]
36+
} else {
37+
self.color_ramp[lo].mix(&self.color_ramp[hi], t)
38+
}
39+
}
1440
}
1541

1642
#[derive(Component, Reflect, Serialize, Deserialize, Copy, Clone)]
@@ -60,32 +86,6 @@ fn trigger_death_from_health(
6086
}
6187
}
6288

63-
#[derive(Asset, Reflect, Serialize, Deserialize)]
64-
pub struct HealthBarConfig {
65-
pub color_ramp: Vec<Color>,
66-
}
67-
68-
impl Config for HealthBarConfig {
69-
const PATH: &'static str = "config/health_bar.ron";
70-
const EXTENSION: &'static str = "health_bar.ron";
71-
}
72-
73-
impl HealthBarConfig {
74-
fn color(&self, t: f32) -> Color {
75-
let n = self.color_ramp.len();
76-
let t = t * (n - 1) as f32;
77-
let lo = t as usize;
78-
let hi = lo + 1;
79-
let t = t.fract();
80-
81-
if hi >= n {
82-
self.color_ramp[n - 1]
83-
} else {
84-
self.color_ramp[lo].mix(&self.color_ramp[hi], t)
85-
}
86-
}
87-
}
88-
8989
/// Reads from the `Health` component on its parent entity.
9090
#[derive(Component, Reflect)]
9191
#[reflect(Component)]
@@ -101,7 +101,7 @@ impl Configure for HealthBar {
101101
}
102102

103103
fn update_health_bar(
104-
config: ConfigRef<HealthBarConfig>,
104+
config: ConfigRef<HealthConfig>,
105105
health_query: Query<&Health>,
106106
mut health_bar_query: Query<(&HealthBar, &Parent, &mut Sprite)>,
107107
) {

src/game/cleanup.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ fn despawn_on_timer(
121121
}
122122
}
123123

124-
#[allow(dead_code)]
125124
#[derive(Component, Reflect)]
126125
#[reflect(Component)]
127126
pub struct RemoveOnTimer<C: Component + TypePath> {
@@ -131,6 +130,7 @@ pub struct RemoveOnTimer<C: Component + TypePath> {
131130
}
132131

133132
impl<C: Component + TypePath> RemoveOnTimer<C> {
133+
#[allow(dead_code)]
134134
pub fn new(timer: Timer) -> Self {
135135
RemoveOnTimer {
136136
timer,

src/screen/loading.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bevy_asset_loader::prelude::*;
44
use iyes_progress::prelude::*;
55
use pyri_state::prelude::*;
66

7-
use crate::game::actor::health::HealthBarConfig;
7+
use crate::game::actor::health::HealthConfig;
88
use crate::game::actor::ActorConfig;
99
use crate::game::card::CardConfig;
1010
use crate::game::combat::projectile::ProjectileConfig;
@@ -29,7 +29,7 @@ pub(super) fn plugin(app: &mut App) {
2929
Screen::Loading.on_update((
3030
ActorConfig::progress.track_progress(),
3131
CardConfig::progress.track_progress(),
32-
HealthBarConfig::progress.track_progress(),
32+
HealthConfig::progress.track_progress(),
3333
LevelConfig::progress.track_progress(),
3434
MusicConfig::progress.track_progress(),
3535
ProjectileConfig::progress.track_progress(),

src/screen/title.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bevy_mod_picking::prelude::*;
44
use iyes_progress::prelude::*;
55
use pyri_state::prelude::*;
66

7-
use crate::game::actor::health::HealthBarConfig;
7+
use crate::game::actor::health::HealthConfig;
88
use crate::game::actor::ActorConfig;
99
use crate::game::card::CardConfig;
1010
use crate::game::combat::projectile::ProjectileConfig;
@@ -29,7 +29,7 @@ pub(super) fn plugin(app: &mut App) {
2929
Screen::Title.on_update((
3030
ActorConfig::progress.track_progress(),
3131
CardConfig::progress.track_progress(),
32-
HealthBarConfig::progress.track_progress(),
32+
HealthConfig::progress.track_progress(),
3333
LevelConfig::progress.track_progress(),
3434
MusicConfig::progress.track_progress(),
3535
ProjectileConfig::progress.track_progress(),

0 commit comments

Comments
 (0)