Skip to content

Commit e8a039e

Browse files
committed
Some minor fixes
1 parent c38649d commit e8a039e

File tree

9 files changed

+991
-802
lines changed

9 files changed

+991
-802
lines changed

Cargo.lock

Lines changed: 902 additions & 725 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

justfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
_list:
2+
just --list
13

24
# build web version and put it out directory
35
web_build:
@@ -16,10 +18,10 @@ check:
1618
# self host web version
1719
web_host:
1820
lwa_simple_server out
19-
21+
2022
gen_cards:
2123
cargo run -p utils_svg_cards_gen
22-
24+
2325
# installs used cli tools
2426
prepare:
2527
cargo install lwa_simple_server

src/components/card_display.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ fn update_card_color(
191191
for (mut sprite, action, can_throw) in q.iter_mut() {
192192
sprite.color = match (action, can_throw.is_some()) {
193193
(ActionToPerform::Use, true) => tailwind::AMBER_300.into(),
194-
(ActionToPerform::Discard, _) => Color::linear_rgb(1.0, 0.6, 0.6),
195-
(_, false) => Color::WHITE.darker(0.4),
194+
(ActionToPerform::Discard, _) => Color::linear_rgba(1.0, 0.6, 0.6, 0.7),
195+
(_, false) => Color::WHITE.darker(0.7),
196196
(_, _) => Color::WHITE,
197197
};
198198
}

src/components/player_ui.rs

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ pub struct UiValueAnimator {
5050
pub negative: AnimationNodeIndex,
5151
}
5252

53+
#[derive(Reflect, Resource, Deref)]
54+
#[reflect(Resource)]
55+
pub struct PlayerUiAnimationInfo(pub AnimationInfo);
56+
5357
#[derive(Component, Default, Reflect, Serialize, Deserialize, Debug)]
5458
#[require(Text, UiValueAnimator)]
5559
pub struct PlayerUiValue(pub i32);
@@ -121,47 +125,46 @@ impl Plugin for PlayerUiPlugin {
121125
Update,
122126
(update_created_player_ui, update_player_ui).run_if(in_state(GameState::Game)),
123127
)
128+
.register_type::<PlayerUiAnimationInfo>()
129+
.add_systems(PostStartup, create_player_anim)
124130
.add_systems(
125131
OnEnter(GameState::Game),
126132
(setup_player_ui).after(game::init_players),
127133
);
128134
}
129135
}
130136

137+
fn create_player_anim(
138+
mut animation_graphs: ResMut<Assets<AnimationGraph>>,
139+
mut animation_clips: ResMut<Assets<AnimationClip>>,
140+
mut commands: Commands,
141+
) {
142+
let anim = AnimationInfo::create(&mut animation_graphs, &mut animation_clips, "UiTarget");
143+
commands.insert_resource(PlayerUiAnimationInfo(anim));
144+
}
145+
131146
#[derive(Component, Reflect, Serialize, Deserialize, Deref, Default, Debug)]
132147
#[require(AnimationPlayer)]
133148
pub struct PlayerUi(pub PlayerNumber);
134149

135150
fn update_created_player_ui(
136151
mut ui_query: Query<TextUiPlayerElements, Added<PlayerTextInterface>>,
137152
player_query: Players,
138-
mut animation_graphs: ResMut<Assets<AnimationGraph>>,
139-
mut animation_clips: ResMut<Assets<AnimationClip>>,
153+
anim_info: Res<PlayerUiAnimationInfo>,
140154
mut commands: Commands,
141155
) {
142156
for mut el in ui_query.iter_mut() {
143157
if let Some(player) = player_query.get_player(el.target.0) {
144-
let AnimationInfo {
145-
target_name: animation_target_name,
146-
target_id: animation_target_id,
147-
graph: animation_graph,
148-
pos_node_index,
149-
neg_node_index,
150-
} = AnimationInfo::create(
151-
&mut animation_graphs,
152-
&mut animation_clips,
153-
format!("Ui{:?}", el.element),
154-
);
155158
el.update(&player);
156-
el.anim_config.positive = pos_node_index;
157-
el.anim_config.negative = neg_node_index;
159+
el.anim_config.positive = anim_info.pos_node_index;
160+
el.anim_config.negative = anim_info.neg_node_index;
158161
commands.entity(el.entity).insert((
159-
AnimationGraphHandle(animation_graph),
162+
AnimationGraphHandle(anim_info.graph.clone()),
160163
AnimationTarget {
161-
id: animation_target_id,
164+
id: anim_info.target_id,
162165
player: el.entity,
163166
},
164-
animation_target_name,
167+
anim_info.target_name.clone(),
165168
));
166169
}
167170
}
@@ -220,11 +223,20 @@ fn setup_player_ui(mut commands: Commands, asset_server: Res<AssetServer>, playe
220223
] {
221224
let player_info = player_query.get_player(player).expect("ERROR");
222225
let avatar_path = player_info.details.avatar_path();
226+
let order = if player == PlayerNumber::First {
227+
FlexDirection::Row
228+
} else {
229+
FlexDirection::RowReverse
230+
};
223231
commands
224232
.spawn((style.clone(), GameObject))
225233
.insert(Name::new(format!("Ui{:?}", player)))
226234
.with_children(|p| {
227-
p.spawn((
235+
p.spawn(Node {
236+
flex_direction: order,
237+
..default()
238+
})
239+
.with_child((
228240
ImageNode {
229241
image: asset_server.load(avatar_path),
230242
..default()
@@ -236,33 +248,24 @@ fn setup_player_ui(mut commands: Commands, asset_server: Res<AssetServer>, playe
236248
..default()
237249
},
238250
))
239-
.with_children(|p| {
240-
p.spawn((
241-
ImageNode {
242-
image: asset_server.load("img/player_frame_name.png"),
243-
flip_x: right_align,
244-
..default()
245-
},
246-
Node {
247-
padding: UiRect::all(Val::Px(8.0)),
248-
position_type: PositionType::Absolute,
249-
bottom: Val::Px(0.0),
250-
..default()
251-
},
252-
))
253-
.with_children(|name| {
254-
name.spawn((
255-
Text::new(player_info.details.name.clone()),
256-
header_style.clone(),
257-
TextLayout::new_with_justify(if right_align {
258-
JustifyText::Right
259-
} else {
260-
JustifyText::Left
261-
}),
262-
))
263-
.insert(PlayerUi(player));
264-
});
265-
});
251+
.with_child((
252+
ImageNode {
253+
image: asset_server.load("img/player_frame_name.png"),
254+
flip_x: right_align,
255+
..default()
256+
},
257+
Node {
258+
padding: UiRect::axes(Val::Px(12.0), Val::Px(0.0)),
259+
height: Val::Px(64.0),
260+
align_items: AlignItems::Center,
261+
..default()
262+
},
263+
children![(
264+
Text::new(player_info.details.name.clone()),
265+
header_style.clone(),
266+
PlayerUi(player)
267+
)],
268+
));
266269
p.spawn((
267270
ImageNode::new(asset_server.load("img/player_frame_resources.png")),
268271
Node {
@@ -303,9 +306,9 @@ fn setup_player_ui(mut commands: Commands, asset_server: Res<AssetServer>, playe
303306
margin: UiRect::bottom(Val::Px(5.0)),
304307
..default()
305308
},
309+
children![ImageNode::new(asset_server.load("img/resource_frame.png"))],
306310
))
307311
.with_children(|p| {
308-
p.spawn(ImageNode::new(asset_server.load("img/resource_frame.png")));
309312
p.spawn(Node {
310313
position_type: PositionType::Absolute,
311314
top: Val::Px(0.0),

src/data/deck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl CardInfo<'_> {
4040
}
4141

4242
impl HandQueryReadItem<'_> {
43-
pub fn card_info_array(&self) -> Vec<CardInfo> {
43+
pub fn card_info_array(&'_ self) -> Vec<CardInfo<'_>> {
4444
self.cards
4545
.iter()
4646
.enumerate()

src/states/game.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl Plugin for GamePlugin {
195195
fn end_game(query: Query<&PlayerHealth, With<HumanPlayer>>, mut commands: Commands) -> Result {
196196
let player = query.single()?;
197197
let player_won = player.has_max_possible_tower() || player.is_alive();
198-
info!("PLAYER WON? {}", player_won);
198+
// info!("PLAYER WON? {}", player_won);
199199
let sound = if player_won {
200200
"snd/game_won.ogg"
201201
} else {
@@ -358,7 +358,7 @@ fn esc_to_menu(
358358
mut query: Query<&mut Node, With<HelpDisplay>>,
359359
) {
360360
if keys.just_released(KeyCode::Escape) {
361-
next_state.set(GameState::AssetsLoading);
361+
next_state.set(GameState::Menu);
362362
// keys.reset(KeyCode::Escape);
363363
} else if keys.just_released(KeyCode::KeyH) {
364364
for mut style in &mut query {
@@ -376,10 +376,10 @@ fn handle_card_events(
376376
any_action: Query<&ActionTaken>,
377377
mut next_state: ResMut<NextState<GameTurnSteps>>,
378378
) {
379-
let Ok(action_to_do) = any_action.single() else {
379+
let Ok(_action_to_do) = any_action.single() else {
380380
return;
381381
};
382-
info!("{:#?}", action_to_do);
382+
// info!("{:#?}", action_to_do);
383383
next_state.set(GameTurnSteps::PerformAction);
384384
}
385385

src/states/menu.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn setup_menu(mut commands: Commands, asset_server: Res<AssetServer>) {
116116
font_size: 30.0,
117117
..default()
118118
};
119-
let clr = TextColor(Color::linear_rgb(0.7, 0.7, 0.7));
119+
let clr = TextColor(Color::linear_rgb(0.65, 0.6, 0.6));
120120
let mut start_time_ms = 500;
121121

122122
for (text, margin, observer) in [
@@ -180,7 +180,7 @@ fn setup_menu(mut commands: Commands, asset_server: Res<AssetServer>) {
180180
},
181181
Node {
182182
margin,
183-
padding: UiRect::all(Val::Px(15.0)),
183+
padding: UiRect::axes(Val::Px(25.0), Val::Px(20.0)),
184184
align_items: AlignItems::Center,
185185
justify_content: JustifyContent::Center,
186186
..default()

src/states/profile_selection.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>, pkv: Res<Pkv
128128
));
129129
// .insert(Class::new("menu_background"));
130130

131+
let init_scale = Vec3::splat(0.01);
132+
let tween_scale = Tween::new(
133+
EaseFunction::QuadraticInOut,
134+
Duration::from_millis(500),
135+
TransformScaleLens {
136+
start: init_scale,
137+
end: Vec3::ONE,
138+
},
139+
);
131140
parent
132141
.spawn((
133142
ImageNode {
@@ -141,29 +150,28 @@ fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>, pkv: Res<Pkv
141150
color: Color::srgb_u8(110, 116, 77),
142151
..default()
143152
},
153+
Animator::new(tween_scale),
144154
Node {
145-
padding: UiRect::all(Val::Px(20.0)),
155+
padding: UiRect::axes(Val::Px(30.0), Val::Px(40.0)),
146156
flex_direction: FlexDirection::Column,
157+
align_items: AlignItems::Center,
147158
row_gap: Val::Px(10.0),
148159
..default()
149160
},
150161
Name::new("profile_edit"),
151162
// Class::new("popup_window"),
152163
))
153164
.with_children(|parent| {
154-
parent
155-
.spawn(Node::default())
156-
.with_child(Text::new("Edit profile"));
157-
158-
let init_scale = Vec3::splat(0.01);
159-
let tween_scale = Tween::new(
160-
EaseFunction::QuadraticInOut,
161-
Duration::from_millis(500),
162-
TransformScaleLens {
163-
start: init_scale,
164-
end: Vec3::ONE,
165+
parent.spawn(Node::default()).with_child((
166+
Text::new("Edit profile"),
167+
TextFont {
168+
font: asset_server.load(consts::LABEL_FONT),
169+
font_size: 45.0,
170+
..default()
165171
},
166-
);
172+
TextColor(Color::linear_rgb(0.8, 0.7, 0.7)),
173+
));
174+
167175
parent.spawn((
168176
BorderColor(Srgba::hex("fcfd9e").unwrap().into()),
169177
BackgroundColor(Srgba::hex("2c422e").unwrap().into()),
@@ -198,7 +206,6 @@ fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>, pkv: Res<Pkv
198206
.spawn((
199207
ImageNode::new(asset_server.load(avatar_path)),
200208
Name::new("avatar"),
201-
Animator::new(tween_scale),
202209
AvatarDisplay { id: avatar_id },
203210
Node {
204211
width: Val::Px(100.0),

src/visual/animation_interface.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ impl AnimationInfo {
4646
AnimatableCurve::new(
4747
animated_field!(Transform::scale),
4848
AnimatableKeyframeCurve::new(
49-
[0.0, 0.2, 0.6, 0.8]
49+
[0.0, 0.2, 0.6, 0.7, 0.8]
5050
.into_iter()
51-
.zip([Vec3::splat(1.0),Vec3::splat(0.3),Vec3::splat(0.3), Vec3::splat(1.0)]),
51+
.zip([Vec3::splat(1.0),Vec3::splat(0.3),Vec3::splat(0.3),Vec3::splat(1.3),Vec3::splat(1.0)]),
5252
)
5353
.expect(
5454
"should be able to build translation curve because we pass in valid samples",
@@ -100,12 +100,12 @@ pub struct TextColorProperty;
100100
impl AnimatableProperty for TextColorProperty {
101101
type Property = Srgba;
102102

103-
fn evaluator_id(&self) -> EvaluatorId {
104-
EvaluatorId::Type(TypeId::of::<Self>())
103+
fn evaluator_id(&'_ self) -> EvaluatorId<'_> {
104+
EvaluatorId::Type(TypeId::of::<TextColorProperty>())
105105
}
106106

107107
fn get_mut<'a>(
108-
&self,
108+
&'_ self,
109109
entity: &'a mut AnimationEntityMut,
110110
) -> Result<&'a mut Self::Property, AnimationEvaluationError> {
111111
let text_color = entity

0 commit comments

Comments
 (0)