Skip to content

Commit 8bb9a6c

Browse files
committed
removed warnings
1 parent cf1faee commit 8bb9a6c

File tree

5 files changed

+160
-43
lines changed

5 files changed

+160
-43
lines changed

src/battle.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ fn send_cleanup_event(mut events: EventWriter<BattleCleanedUp>) {
112112
events.send(BattleCleanedUp);
113113
}
114114

115-
struct EnemyModels {
116-
models: Vec<Handle<Gltf>>,
115+
pub struct EnemyModels {
116+
pub models: Vec<Handle<Gltf>>,
117117
}
118118

119119
fn load_enemy_models(asset_server: Res<AssetServer>, mut commands: Commands) {
@@ -527,7 +527,11 @@ impl Prefab for BattlePrefab {
527527
let health_bar = spawn(
528528
ProgressBarPrefab {
529529
starting_percentage: 1.0,
530-
transform: Transform::from_xyz(0.0, -2.9, 1.0).with_scale([6.0, 0.3, 1.0].into()),
530+
size: [6.0, 0.3].into(),
531+
border: 0.1,
532+
transform: Transform::from_xyz(0.0, -2.9, 1.0),
533+
color: Color::hex(HEALTH_COLOR_HEX).unwrap(),
534+
..default()
531535
},
532536
commands,
533537
);
@@ -628,13 +632,18 @@ pub struct EnemyPrefab {
628632
pub attack: u32,
629633
}
630634

635+
const HEALTH_COLOR_HEX: &str = "871e16";
636+
631637
impl Prefab for EnemyPrefab {
632638
fn construct(&self, entity: Entity, commands: &mut Commands) {
633639
let health_bar = spawn(
634640
ProgressBarPrefab {
635641
starting_percentage: 1.0,
636-
transform: self.transform
637-
* Transform::from_xyz(0.0, 0.2, 1.2).with_scale([1.0, 0.2, 1.0].into()),
642+
border: 0.1,
643+
size: [1.0, 0.2].into(),
644+
transform: self.transform * Transform::from_xyz(0.0, 0.2, 1.2),
645+
color: Color::hex(HEALTH_COLOR_HEX).unwrap(),
646+
..default()
638647
},
639648
commands,
640649
);

src/board.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::prefab::*;
44
use crate::tween_untils::TweenType;
55
use crate::utils::{
66
square_mesh, white_standard_material, DelayedDespawn, DespawnEvent, DespawnReason, ProgressBar,
7-
ProgressBarPrefab, WorldCursor, WorldHover,
7+
ProgressBarPosition, ProgressBarPrefab, WorldCursor, WorldHover,
88
};
99
use bevy::pbr::{NotShadowCaster, NotShadowReceiver};
1010
use bevy::render::view::RenderLayers;
@@ -95,8 +95,8 @@ fn add_materials(mut materials: ResMut<Assets<StandardMaterial>>) {
9595
}
9696
}
9797

98-
struct Icons {
99-
icons: Vec<Handle<Image>>,
98+
pub struct Icons {
99+
pub icons: Vec<Handle<Image>>,
100100
}
101101

102102
fn load_icons(asset_server: Res<AssetServer>, mut commands: Commands) {
@@ -751,8 +751,8 @@ impl Prefab for BoardPrefab {
751751

752752
children.push(spawn(
753753
TimerPrefab {
754-
transform: Transform::from_xyz(0.0, BOARD_MIDDLE.y + 0.5, 0.0)
755-
.with_scale([BOARD_MIDDLE.x * 2.0, 0.25, 1.0].into()),
754+
size: [BOARD_MIDDLE.x * 2.0, 0.25].into(),
755+
transform: Transform::from_xyz(0.0, BOARD_MIDDLE.y + 0.2, 0.0),
756756
},
757757
commands,
758758
));
@@ -830,14 +830,20 @@ impl Prefab for TilePrefab {
830830
struct TimerProgress;
831831

832832
struct TimerPrefab {
833+
size: Vec2,
833834
transform: Transform,
834835
}
835836

836837
impl Prefab for TimerPrefab {
837838
fn construct(&self, entity: Entity, commands: &mut Commands) {
838839
ProgressBarPrefab {
840+
size: self.size,
839841
starting_percentage: 1.0,
840842
transform: self.transform,
843+
background_color: Color::NONE,
844+
border_color: Color::NONE,
845+
position: ProgressBarPosition::Center,
846+
..default()
841847
}
842848
.construct(entity, commands);
843849

src/cards.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ fn put_cards_in_hand(
9999

100100
fn put_cards_in_pile(
101101
piles: Query<(&Pile, &Transform), Changed<Pile>>,
102-
mut cards: Query<(&mut Transform, &mut Visibility), Without<Pile>>,
102+
mut cards: Query<&mut Transform, Without<Pile>>,
103103
) {
104104
for (pile, pile_transform) in &piles {
105105
let mut iter = cards.iter_many_mut(&pile.cards);
106-
while let Some((mut transform, mut visibility)) = iter.fetch_next() {
106+
while let Some(mut transform) = iter.fetch_next() {
107107
*transform = pile_transform.with_rotation(Quat::from_rotation_y(180_f32.to_radians()));
108108
}
109109
}

src/main_state.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ impl Plugin for MainStatePlugin {
5858

5959
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
6060
pub enum MainState {
61-
MainMenu,
6261
Map,
6362
Battle,
6463
Death,
@@ -164,8 +163,8 @@ fn go_to_restart(mut commands: Commands, mut events: EventReader<Restart>) {
164163
}
165164

166165
fn clean_up_battle(
167-
mut commands: Commands,
168-
mut battle_resources: ResMut<BattleResources>,
166+
commands: Commands,
167+
battle_resources: ResMut<BattleResources>,
169168
mut events: EventReader<TransitionEnd>,
170169
) {
171170
if events.iter().count() > 0 {

src/utils.rs

Lines changed: 131 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -173,40 +173,143 @@ pub struct ProgressBar {
173173
progress: Entity,
174174
}
175175

176-
#[derive(Default)]
176+
#[derive(Default, Clone, Copy)]
177+
pub enum ProgressBarPosition {
178+
#[default]
179+
Left,
180+
Center,
181+
Right,
182+
}
183+
184+
#[derive(Default, Clone)]
177185
pub struct ProgressBarPrefab {
178186
pub starting_percentage: f32,
187+
pub size: Vec2,
188+
pub border: f32,
189+
pub color: Color,
190+
pub border_color: Color,
191+
pub background_color: Color,
192+
pub position: ProgressBarPosition,
179193
pub transform: Transform,
180194
}
181195

182196
impl Prefab for ProgressBarPrefab {
183197
fn construct(&self, entity: Entity, commands: &mut Commands) {
184-
let mesh = commands
185-
.spawn_bundle(PbrBundle {
186-
mesh: square_mesh(),
187-
material: white_standard_material(),
188-
..default()
189-
})
190-
.insert(NotShadowCaster)
191-
.insert(NotShadowReceiver)
192-
.id();
193-
194-
let progress = commands
195-
.spawn_bundle(SpatialBundle::default())
196-
.add_child(mesh)
197-
.id();
198-
199-
commands
200-
.entity(entity)
201-
.insert_bundle(SpatialBundle {
202-
transform: self.transform,
203-
..default()
204-
})
205-
.insert(ProgressBar {
206-
percentage: self.starting_percentage,
207-
progress,
208-
})
209-
.add_child(progress);
198+
let bar = self.clone();
199+
commands.add(move |world: &mut World| {
200+
let (progress_color, background_color, border_color) =
201+
world.resource_scope(|_, mut materials: Mut<Assets<StandardMaterial>>| {
202+
(
203+
materials.add(StandardMaterial {
204+
base_color: bar.color,
205+
unlit: true,
206+
alpha_mode: if bar.color.a() < 1.0 {
207+
AlphaMode::Blend
208+
} else {
209+
default()
210+
},
211+
..default()
212+
}),
213+
materials.add(StandardMaterial {
214+
base_color: bar.background_color,
215+
unlit: true,
216+
alpha_mode: if bar.background_color.a() < 1.0 {
217+
AlphaMode::Blend
218+
} else {
219+
default()
220+
},
221+
..default()
222+
}),
223+
materials.add(StandardMaterial {
224+
base_color: bar.border_color,
225+
unlit: true,
226+
alpha_mode: if bar.border_color.a() < 1.0 {
227+
AlphaMode::Blend
228+
} else {
229+
default()
230+
},
231+
..default()
232+
}),
233+
)
234+
});
235+
236+
let mesh = world
237+
.spawn()
238+
.insert_bundle(PbrBundle {
239+
mesh: square_mesh(),
240+
material: progress_color,
241+
transform: Transform::from_translation(match bar.position {
242+
ProgressBarPosition::Left => Vec3::X / 2.0,
243+
ProgressBarPosition::Center => default(),
244+
ProgressBarPosition::Right => -Vec3::X / 2.0,
245+
}),
246+
..default()
247+
})
248+
.insert(NotShadowCaster)
249+
.insert(NotShadowReceiver)
250+
.id();
251+
252+
let progress = world
253+
.spawn()
254+
.insert_bundle(SpatialBundle {
255+
transform: Transform::from_translation(match bar.position {
256+
ProgressBarPosition::Left => -Vec3::X / 2.0,
257+
ProgressBarPosition::Center => default(),
258+
ProgressBarPosition::Right => Vec3::X / 2.0,
259+
}),
260+
..default()
261+
})
262+
.push_children(&[mesh])
263+
.id();
264+
265+
let background = world
266+
.spawn()
267+
.insert_bundle(PbrBundle {
268+
mesh: square_mesh(),
269+
material: background_color,
270+
transform: Transform::from_translation(-Vec3::Z * 0.001),
271+
..default()
272+
})
273+
.insert(NotShadowCaster)
274+
.insert(NotShadowReceiver)
275+
.id();
276+
277+
let inner = world
278+
.spawn()
279+
.insert_bundle(SpatialBundle {
280+
transform: Transform::from_scale(
281+
((bar.size - bar.border).max(Vec2::ZERO)).extend(1.0),
282+
),
283+
..default()
284+
})
285+
.push_children(&[progress, background])
286+
.id();
287+
288+
let border = world
289+
.spawn()
290+
.insert_bundle(PbrBundle {
291+
mesh: square_mesh(),
292+
material: border_color,
293+
transform: Transform::from_scale(bar.size.extend(1.0))
294+
.with_translation(-Vec3::Z * 0.002),
295+
..default()
296+
})
297+
.insert(NotShadowCaster)
298+
.insert(NotShadowReceiver)
299+
.id();
300+
301+
world
302+
.entity_mut(entity)
303+
.insert_bundle(SpatialBundle {
304+
transform: bar.transform,
305+
..default()
306+
})
307+
.insert(ProgressBar {
308+
percentage: bar.starting_percentage,
309+
progress,
310+
})
311+
.push_children(&[inner, border]);
312+
});
210313
}
211314
}
212315

@@ -340,7 +443,7 @@ fn track_world_hover(
340443
.iter()
341444
.filter(|(_, _, entities)| entities.entities.contains(&check_visibility_of))
342445
.filter_map(|(entity, cursor, _)| cursor.position.map(|x| (entity, x)))
343-
.filter(|(entity, position)| {
446+
.filter(|(_, position)| {
344447
let matrix = transform.compute_matrix().inverse();
345448
let position = matrix.transform_point3(position.extend(0.0)).truncate();
346449

0 commit comments

Comments
 (0)