Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bevy 0.15 #13

Merged
merged 17 commits into from
Dec 18, 2024
1,380 changes: 928 additions & 452 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { version = "0.14", default-features = false, features = [
bevy = { version = "0.15", default-features = false, features = [
"bevy_asset",
"bevy_audio",
"bevy_winit",
"bevy_window",
"bevy_core_pipeline",
"bevy_sprite",
"bevy_text",
Expand All @@ -24,14 +25,14 @@ bevy = { version = "0.14", default-features = false, features = [
"webgl2",
] }

bevy_asset_loader = "0.21"
bevy_common_assets = { version = "0.11", features = ["ron"] }
bevy_ecs_tilemap = { version = "0.14", features = ["atlas"] }
bevy_asset_loader = "0.22"
bevy_common_assets = { version = "0.12", features = ["ron"] }
bevy_ecs_tilemap = { version = "0.15", features = ["atlas"] }

tiled = { version = "0.11", default-features = false }
serde = { version = "1", features = ["derive"] }
anyhow = "1.0"
ron = "0.8"
ron = "*"
chumsky = "0.9"
rand = { version = "0.8" }

Expand Down
187 changes: 83 additions & 104 deletions src/action_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ impl Plugin for ActionPanelPlugin {
}
}

pub static FONT_SIZE_ACTION_PANEL: f32 = 32.0;
pub static FONT_SIZE_ACTION_PANEL: f32 = 22.0;
pub static FONT_SIZE_COST: f32 = 12.0;

#[derive(Resource, Default)]
pub struct ActionPanel {
Expand Down Expand Up @@ -63,20 +64,17 @@ fn setup_action_panel(
) {
let action_container = commands
.spawn((
NodeBundle {
style: Style {
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::FlexEnd,
align_items: AlignItems::FlexEnd,
width: Val::Percent(30.0),
position_type: PositionType::Absolute,
right: Val::Px(0.),
top: Val::Px(0.),
..default()
},
background_color: ui_color::TRANSPARENT_BACKGROUND.into(),
Node {
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::FlexEnd,
align_items: AlignItems::FlexEnd,
width: Val::Percent(30.0),
position_type: PositionType::Absolute,
right: Val::Px(0.),
top: Val::Px(0.),
..default()
},
BackgroundColor(ui_color::TRANSPARENT_BACKGROUND.into()),
ActionPanelContainer,
))
.id();
Expand Down Expand Up @@ -152,20 +150,16 @@ fn spawn_action_panel_item(
) -> Entity {
let child = commands
.spawn((
NodeBundle {
style: Style {
display: if item.visible {
Display::Flex
} else {
Display::None
},
justify_content: JustifyContent::FlexStart,
align_items: AlignItems::Center,
width: Val::Percent(100.0),
height: Val::Px(42.0),
..default()
Node {
display: if item.visible {
Display::Flex
} else {
Display::None
},
background_color: Color::NONE.into(),
justify_content: JustifyContent::FlexStart,
align_items: AlignItems::Center,
width: Val::Percent(100.0),
height: Val::Px(42.0),
..default()
},
TypingTargetBundle {
Expand All @@ -176,47 +170,48 @@ fn spawn_action_panel_item(
))
.with_children(|parent| {
parent.spawn((
ImageBundle {
style: Style {
margin: UiRect {
left: Val::Px(5.0),
right: Val::Px(5.0),
..default()
},
height: Val::Px(32.0),
ImageNode {
image: item.icon.clone(),
..default()
},
Node {
margin: UiRect {
left: Val::Px(5.0),
right: Val::Px(5.0),
..default()
},
image: item.icon.clone().into(),
height: Val::Px(32.0),
..default()
},
ActionPanelItemImage,
));
parent
.spawn((
NodeBundle {
style: Style {
position_type: PositionType::Absolute,
bottom: Val::Px(0.0),
Node {
position_type: PositionType::Absolute,
bottom: Val::Px(0.0),
left: Val::Px(2.0),
padding: UiRect {
left: Val::Px(2.0),
padding: UiRect {
left: Val::Px(2.0),
right: Val::Px(2.0),
..default()
},
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
width: Val::Px(38.0),
height: Val::Px(16.0),
right: Val::Px(2.0),
..default()
},
background_color: ui_color::TRANSPARENT_BACKGROUND.into(),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
width: Val::Px(38.0),
height: Val::Px(16.0),
..default()
},
BackgroundColor(ui_color::TRANSPARENT_BACKGROUND.into()),
ActionPanelItemPriceContainer,
))
.with_children(|parent| {
parent.spawn(ImageBundle {
style: Style {
parent.spawn((
ImageNode {
image: texture_handles.coin_ui.clone(),
..default()
},
Node {
margin: UiRect {
right: Val::Px(2.0),
..default()
Expand All @@ -225,52 +220,38 @@ fn spawn_action_panel_item(
height: Val::Px(12.0),
..default()
},
image: texture_handles.coin_ui.clone().into(),
..default()
});
));
parent.spawn((
TextBundle {
style: Style { ..default() },
text: Text::from_section(
"0",
TextStyle {
font: font_handles.jptext.clone(),
font_size: 16.0, // 16px in this font is just not quite 16px is it?
color: ui_color::NORMAL_TEXT.into(),
},
),
Text::new("0"),
TextFont {
font: font_handles.jptext.clone(),
font_size: FONT_SIZE_COST,
..default()
},
TextColor(ui_color::NORMAL_TEXT.into()),
ActionPanelItemPriceText,
));
});
parent.spawn((
TextBundle {
text: Text {
sections: vec![
TextSection {
value: "".into(),
style: TextStyle {
font: font_handles.jptext.clone(),
font_size: FONT_SIZE_ACTION_PANEL,
color: ui_color::GOOD_TEXT.into(),
},
},
TextSection {
value: item.target.displayed_chunks.join(""),
style: TextStyle {
font: font_handles.jptext.clone(),
font_size: FONT_SIZE_ACTION_PANEL,
color: ui_color::NORMAL_TEXT.into(),
},
},
],
parent
.spawn((
Text::default(),
TextFont {
font: font_handles.jptext.clone(),
font_size: FONT_SIZE_ACTION_PANEL,
..default()
},
..default()
},
TypingTargetText,
));
TextColor(ui_color::GOOD_TEXT.into()),
TypingTargetText,
))
.with_child((
TextSpan::new(item.target.displayed_chunks.join("")),
TextFont {
font: font_handles.jptext.clone(),
font_size: FONT_SIZE_ACTION_PANEL,
..default()
},
TextColor(ui_color::NORMAL_TEXT.into()),
));
})
.id();

Expand All @@ -281,15 +262,13 @@ fn spawn_action_panel_item(

fn update_action_panel(
mut typing_target_query: Query<(&mut TypingTargetSettings, &Children)>,
mut style_query: Query<&mut Style>,
mut text_query: Query<&mut Text, (With<TypingTargetText>, Without<ActionPanelItemPriceText>)>,
mut price_text_query: Query<
&mut Text,
(With<ActionPanelItemPriceText>, Without<TypingTargetText>),
>,
mut node_query: Query<&mut Node>,
text_query: Query<(), With<TypingTargetText>>,
price_text_query: Query<(), With<ActionPanelItemPriceText>>,
tower_query: Query<(&TowerState, &TowerKind, &TowerStats)>,
price_query: Query<(Entity, &Children), With<ActionPanelItemPriceContainer>>,
(actions, currency, selection): (Res<ActionPanel>, Res<Currency>, Res<TowerSelection>),
mut writer: TextUiWriter,
) {
if !actions.is_changed() {
return;
Expand Down Expand Up @@ -343,8 +322,8 @@ fn update_action_panel(

// visibility

if let Ok(mut style) = style_query.get_mut(*entity) {
style.display = if visible {
if let Ok(mut node) = node_query.get_mut(*entity) {
node.display = if visible {
Display::Flex
} else {
Display::None
Expand All @@ -356,7 +335,7 @@ fn update_action_panel(
if let Ok((_, target_children)) = typing_target_query.get(*entity) {
for target_child in target_children.iter() {
if let Ok((price_entity, children)) = price_query.get(*target_child) {
if let Ok(mut style) = style_query.get_mut(price_entity) {
if let Ok(mut style) = node_query.get_mut(price_entity) {
style.display = if price_visible {
Display::Flex
} else {
Expand All @@ -365,9 +344,9 @@ fn update_action_panel(
}

for child in children.iter() {
if let Ok(mut text) = price_text_query.get_mut(*child) {
text.sections[0].value = format!("{}", price);
text.sections[0].style.color = if disabled {
if price_text_query.get(*child).is_ok() {
*writer.text(*child, 0) = format!("{}", price);
writer.color(*child, 0).0 = if disabled {
ui_color::BAD_TEXT.into()
} else {
ui_color::NORMAL_TEXT.into()
Expand All @@ -383,13 +362,13 @@ fn update_action_panel(

if let Ok((_, target_children)) = typing_target_query.get(*entity) {
for target_child in target_children.iter() {
if let Ok(mut text) = text_query.get_mut(*target_child) {
text.sections[0].style.color = if disabled {
if text_query.get(*target_child).is_ok() {
writer.color(*target_child, 0).0 = if disabled {
ui_color::BAD_TEXT.into()
} else {
ui_color::GOOD_TEXT.into()
};
text.sections[1].style.color = if disabled {
writer.color(*target_child, 1).0 = if disabled {
ui_color::BAD_TEXT.into()
} else {
ui_color::NORMAL_TEXT.into()
Expand Down
12 changes: 6 additions & 6 deletions src/atlas_loader.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy::{
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
asset::{io::Reader, AssetLoader, LoadContext},
prelude::*,
};
use serde::Deserialize;
Expand All @@ -26,11 +26,11 @@ impl AssetLoader for AtlasImageLoader {
type Asset = AtlasImage;
type Settings = ();
type Error = anyhow::Error;
async fn load<'a>(
&'a self,
reader: &'a mut Reader<'_>,
_settings: &'a (),
load_context: &'a mut LoadContext<'_>,
async fn load(
&self,
reader: &mut dyn Reader,
_settings: &(),
load_context: &mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
Expand Down
11 changes: 4 additions & 7 deletions src/bullet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ pub fn spawn(
speed: f32,
status_effect: Option<StatusEffect>,
commands: &mut Commands,
texture: Handle<Image>,
image: Handle<Image>,
) {
position.z = layer::BULLET;

commands.spawn((
SpriteBundle {
texture,
transform: Transform::from_translation(position),
..default()
},
Sprite { image, ..default() },
Transform::from_translation(position),
Bullet {
target,
damage,
Expand Down Expand Up @@ -74,7 +71,7 @@ fn update(

let dist = bullet_pos.distance(target_pos);

let delta = time.delta_seconds();
let delta = time.delta_secs();
let step = bullet.speed * delta;

if step < dist {
Expand Down
Loading
Loading