Skip to content

Commit 588abad

Browse files
committed
Do things with deck display UI
1 parent dcfe79c commit 588abad

29 files changed

+284
-328
lines changed

assets/config/card.ron

+20-15
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
(
33
// Deck:
44
deck_cap: 18,
5-
deck_height: Px(96.0),
6-
deck_column_gap: Px(-6.0),
75

86
// Cards:
7+
card_height: Px(96.0),
98
card_background_map: {
109
"yellow": CardBackground (
1110
texture: "image/card/yellow_card.png",
@@ -40,49 +39,55 @@
4039
),
4140
),
4241
},
42+
card_icon_map: {
43+
"step": CardIcon(texture: "image/card/step.png"),
44+
"double_beat": CardIcon(texture: "image/card/double_beat.png"),
45+
"counter_point": CardIcon(texture: "image/card/counter_point.png"),
46+
"splits": CardIcon(texture: "image/card/splits.png"),
47+
},
4348
card_map: {
4449
"step": Card(
4550
name: "Basic Step",
4651
description: "A-one and a-two and a-step.",
4752
background: "blue",
48-
icon_texture: "image/card/step.png",
53+
icon: "step",
4954
action: Step,
5055
action_config: CardActionConfig(
51-
remove_on_beat: 2,
56+
remove_on_beat: 2,
5257
),
5358
),
5459
"double_beat": Card(
5560
name: "Double Beat",
5661
description: "Two beats, rapid fire!",
5762
background: "pink",
58-
icon_texture: "image/card/double_beat.png",
63+
icon: "double_beat",
5964
action: DoubleBeat,
6065
action_config: CardActionConfig(
61-
remove_on_beat: 2,
62-
attack: Attack (
63-
power: 2.0,
64-
force: 4.0,
65-
projectile: Some("quarter_note")
66-
)
66+
remove_on_beat: 2,
67+
attack: Attack (
68+
power: 2.0,
69+
force: 4.0,
70+
projectile: Some("quarter_note"),
71+
),
6772
),
6873
),
6974
"counter_point": Card(
7075
name: "Counter Point",
7176
description: "Notes that move apart synchronously",
7277
background: "pink",
73-
icon_texture: "image/card/counter_point.png",
78+
icon: "counter_point",
7479
action_config: CardActionConfig(
75-
remove_on_beat: 2,
80+
remove_on_beat: 2,
7681
),
7782
),
7883
"splits": Card(
7984
name: "Splits",
8085
description: "Split in two!",
8186
background: "blue",
82-
icon_texture: "image/card/splits.png",
87+
icon: "splits",
8388
modifier: 1.0,
8489
action_config: CardActionConfig(
85-
remove_on_beat: 2,
90+
remove_on_beat: 2,
8691
),
8792
),
8893
}

assets/config/theme.ron

+2
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@
2525
Srgba(Srgba(red: 0.106, green: 0.118, blue: 0.122, alpha: 0.850)),
2626
// Indicator
2727
Srgba(Srgba(red: 0.384, green: 0.827, blue: 0.769, alpha: 1.000)),
28+
// CardBorder
29+
Srgba(Srgba(red: 0.071, green: 0.082, blue: 0.133, alpha: 1.000)),
2830
)),
2931
)

assets/image/card/blue_card.aseprite

-20 Bytes
Binary file not shown.

assets/image/card/blue_card.png

-24 Bytes
Loading
-9 Bytes
Binary file not shown.

assets/image/card/double_beat.png

-1 Bytes
Loading

assets/image/card/green_card.aseprite

-20 Bytes
Binary file not shown.

assets/image/card/green_card.png

-24 Bytes
Loading

assets/image/card/pink_card.aseprite

-20 Bytes
Binary file not shown.

assets/image/card/pink_card.png

-24 Bytes
Loading

assets/image/card/splits.aseprite

0 Bytes
Binary file not shown.

assets/image/card/splits.png

5 Bytes
Loading

assets/image/card/step.aseprite

-12 Bytes
Binary file not shown.

assets/image/card/step.png

-18 Bytes
Loading
-20 Bytes
Binary file not shown.

assets/image/card/yellow_card.png

-24 Bytes
Loading

src/animation/transition.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use pyri_state::prelude::*;
33

44
use crate::core::PostColorSet;
55
use crate::screen::Screen;
6-
use crate::util::despawn::DespawnSet;
6+
use crate::util::despawn::LateDespawn;
77
use crate::util::prelude::*;
88

99
pub(super) fn plugin(app: &mut App) {
@@ -35,7 +35,7 @@ impl FadeIn {
3535

3636
fn apply_fade_in(
3737
time: Res<Time>,
38-
mut despawn: ResMut<DespawnSet>,
38+
mut despawn: ResMut<LateDespawn>,
3939
mut fade_query: Query<(Entity, &mut FadeIn, &mut BackgroundColor)>,
4040
) {
4141
let dt = time.delta_seconds();
@@ -76,7 +76,7 @@ impl FadeOut {
7676

7777
fn apply_fade_out(
7878
time: Res<Time>,
79-
mut despawn: ResMut<DespawnSet>,
79+
mut despawn: ResMut<LateDespawn>,
8080
mut screen: NextMut<Screen>,
8181
mut fade_query: Query<(Entity, &mut FadeOut, &mut BackgroundColor)>,
8282
) {

src/core.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ pub enum UpdateSet {
6060
TriggerDeath,
6161
/// Detect XP and trigger level up.
6262
TriggerLevelUp,
63-
/// Spawn and despawn entities.
64-
SpawnDespawn,
63+
/// Despawn entities.
64+
Despawn,
65+
/// Spawn entities.
66+
Spawn,
6567
/// Synchronize end-of-frame values.
6668
SyncLate,
6769
}
@@ -78,7 +80,8 @@ impl Configure for UpdateSet {
7880
Self::Update,
7981
Self::TriggerDeath,
8082
Self::TriggerLevelUp,
81-
Self::SpawnDespawn,
83+
Self::Despawn,
84+
Self::Spawn,
8285
Self::SyncLate,
8386
)
8487
.chain(),

src/core/theme.rs

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub enum ThemeColor {
7070
// Misc UI colors
7171
Popup,
7272
Indicator,
73+
CardBorder,
7374
}
7475

7576
impl ThemeColor {

src/game/actor/attack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct Attack {
3737
impl Configure for Attack {
3838
fn configure(app: &mut App) {
3939
app.register_type::<Self>();
40-
app.add_systems(Update, apply_attack.in_set(UpdateSet::Update));
40+
app.add_systems(Update, apply_attack.in_set(UpdateSet::Spawn));
4141
}
4242
}
4343

src/game/card.rs

+90-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use bevy::ecs::system::EntityCommand;
12
use bevy::ecs::system::SystemState;
23
use bevy::prelude::*;
34
use bevy::utils::HashMap;
@@ -8,12 +9,12 @@ use crate::game::card::action::CardAction;
89
use crate::game::card::action::CardActionConfig;
910
use crate::game::card::action::CardActionKey;
1011
use crate::game::card::action::CardActionMap;
12+
use crate::ui::prelude::*;
1113
use crate::util::prelude::*;
1214

1315
pub mod action;
1416
pub mod attack;
1517
pub mod deck;
16-
pub mod deck_dock;
1718
pub mod movement;
1819

1920
pub(super) fn plugin(app: &mut App) {
@@ -23,7 +24,6 @@ pub(super) fn plugin(app: &mut App) {
2324
action::plugin,
2425
attack::plugin,
2526
deck::plugin,
26-
deck_dock::plugin,
2727
movement::plugin,
2828
));
2929
}
@@ -32,11 +32,11 @@ pub(super) fn plugin(app: &mut App) {
3232
pub struct CardConfig {
3333
// Deck:
3434
pub deck_cap: usize,
35-
pub deck_height: Val,
36-
pub deck_column_gap: Val,
3735

3836
// Cards:
37+
pub card_height: Val,
3938
pub card_background_map: HashMap<String, CardBackground>,
39+
pub card_icon_map: HashMap<String, CardIcon>,
4040
pub card_map: HashMap<String, Card>,
4141
}
4242

@@ -57,8 +57,11 @@ impl Config for CardConfig {
5757
background.texture_atlas_layout = layouts.add(&background.texture_atlas_grid);
5858
}
5959

60+
for icon in self.card_icon_map.values_mut() {
61+
icon.texture = asset_server.load(&icon.texture_path);
62+
}
63+
6064
for card in self.card_map.values_mut() {
61-
card.icon_texture = asset_server.load(&card.icon_texture_path);
6265
card.action = *c!(card_action_map.0.get(&card.action_key));
6366
}
6467
}
@@ -68,13 +71,13 @@ impl Config for CardConfig {
6871
.values()
6972
.all(|x| asset_server.is_loaded_with_dependencies(&x.texture))
7073
&& self
71-
.card_map
74+
.card_icon_map
7275
.values()
73-
.all(|x| asset_server.is_loaded_with_dependencies(&x.icon_texture))
76+
.all(|x| asset_server.is_loaded_with_dependencies(&x.texture))
7477
}
7578
}
7679

77-
#[derive(Asset, Reflect, Serialize, Deserialize)]
80+
#[derive(Asset, Reflect, Serialize, Deserialize, Clone)]
7881
pub struct CardBackground {
7982
#[serde(rename = "texture")]
8083
texture_path: String,
@@ -83,24 +86,97 @@ pub struct CardBackground {
8386
texture_atlas_grid: TextureAtlasGrid,
8487
#[serde(skip)]
8588
pub texture_atlas_layout: Handle<TextureAtlasLayout>,
89+
#[serde(skip)]
90+
active: bool,
91+
}
92+
93+
impl EntityCommand for CardBackground {
94+
fn apply(self, id: Entity, world: &mut World) {
95+
world.entity_mut(id).insert((
96+
Name::new("CardBackground"),
97+
ImageBundle {
98+
image: UiImage::new(self.texture),
99+
..default()
100+
},
101+
TextureAtlas {
102+
layout: self.texture_atlas_layout,
103+
index: if self.active { 1 } else { 0 },
104+
},
105+
));
106+
}
107+
}
108+
109+
#[derive(Asset, Reflect, Serialize, Deserialize, Clone)]
110+
pub struct CardIcon {
111+
#[serde(rename = "texture")]
112+
texture_path: String,
113+
#[serde(skip)]
114+
pub texture: Handle<Image>,
115+
}
116+
117+
impl EntityCommand for CardIcon {
118+
fn apply(self, id: Entity, world: &mut World) {
119+
world.entity_mut(id).insert((
120+
Name::new("CardIcon"),
121+
ImageBundle {
122+
image: UiImage::new(self.texture),
123+
..default()
124+
},
125+
ThemeColor::CardBorder.target::<UiImage>(),
126+
));
127+
}
86128
}
87129

88-
#[derive(Reflect, Serialize, Deserialize)]
130+
#[derive(Reflect, Serialize, Deserialize, Clone)]
89131
pub struct Card {
90132
pub name: String,
91133
pub description: String,
92-
pub background: String,
93-
#[serde(rename = "icon_texture")]
94-
icon_texture_path: String,
95-
#[serde(skip)]
96-
pub icon_texture: Handle<Image>,
134+
#[serde(rename = "background")]
135+
pub background_key: String,
136+
#[serde(rename = "icon")]
137+
pub icon_key: String,
97138
#[serde(rename = "action", default)]
98139
action_key: CardActionKey,
99140
#[serde(skip)]
100141
pub action: CardAction,
101142
pub action_config: CardActionConfig, // TODO: Naming
102143
}
103144

145+
fn card(key: impl Into<String>, active: bool) -> impl EntityCommand {
146+
let key = key.into();
147+
148+
move |entity: Entity, world: &mut World| {
149+
let config = SystemState::<ConfigRef<CardConfig>>::new(world).get(world);
150+
let config = r!(config.get());
151+
let card = r!(config.card_map.get(&key));
152+
let mut background = r!(config.card_background_map.get(&card.background_key)).clone();
153+
background.active = active;
154+
let icon = r!(config.card_icon_map.get(&card.icon_key)).clone();
155+
let name = format!("Card(\"{}\")", card.name);
156+
let height = config.card_height;
157+
158+
world
159+
.entity_mut(entity)
160+
.insert((
161+
Name::new(name),
162+
NodeBundle {
163+
style: Style {
164+
height,
165+
border: UiRect::all(Px(4.0)),
166+
..default()
167+
},
168+
..default()
169+
},
170+
ThemeColor::CardBorder.target::<BorderColor>(),
171+
))
172+
.with_children(|children| {
173+
children.spawn_with(background).with_children(|children| {
174+
children.spawn_with(icon);
175+
});
176+
});
177+
}
178+
}
179+
104180
#[derive(Event)]
105181
pub struct AddCardEvent(pub String);
106182

src/game/card/action.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl FromWorld for CardActionMap {
6969
}
7070
}
7171

72-
#[derive(Reflect, Serialize, Deserialize, Eq, PartialEq, Hash, Default)]
72+
#[derive(Reflect, Serialize, Deserialize, Eq, PartialEq, Hash, Copy, Clone, Default)]
7373
pub enum CardActionKey {
7474
#[default]
7575
Rest,

0 commit comments

Comments
 (0)