Skip to content

Commit

Permalink
Upgrade to Bevy 0.14 (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
rparrett authored Jul 13, 2024
1 parent 1c38469 commit 767d076
Show file tree
Hide file tree
Showing 24 changed files with 1,000 additions and 811 deletions.
1,421 changes: 815 additions & 606 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ 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.13", default-features = false, features = [
bevy = { version = "0.14", default-features = false, features = [
"bevy_asset",
"bevy_audio",
"bevy_winit",
"bevy_core_pipeline",
"bevy_sprite",
"bevy_text",
"bevy_ui",
"multi-threaded",
"multi_threaded",
"png",
"x11",
"vorbis",
"webgl2",
] }

bevy_asset_loader = { version = "0.20" }
bevy_common_assets = { version = "0.10", features = ["ron"] }
bevy_ecs_tilemap = { git = "https://github.com/StarArawn/bevy_ecs_tilemap", features = [
bevy_asset_loader = "0.21"
bevy_common_assets = { version = "0.11", features = ["ron"] }
bevy_ecs_tilemap = { git = "https://github.com/StarArawn/bevy_ecs_tilemap", rev = "a88eeab", features = [
"atlas",
] }

Expand Down
2 changes: 1 addition & 1 deletion assets/atlas/crab.atlas.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(
path: "textures/enemies/crab.png",
tile_size: Vec2(32., 32.),
tile_size: UVec2(32, 32),
columns: 8,
rows: 10,
padding: None,
Expand Down
2 changes: 1 addition & 1 deletion assets/atlas/deathknight.atlas.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(
path: "textures/enemies/deathknight.png",
tile_size: Vec2(42., 42.),
tile_size: UVec2(42, 42),
columns: 5,
rows: 9,
padding: None,
Expand Down
2 changes: 1 addition & 1 deletion assets/atlas/skeleton.atlas.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(
path: "textures/enemies/skeleton.png",
tile_size: Vec2(48., 48.),
tile_size: UVec2(48, 48),
columns: 4,
rows: 9,
padding: None,
Expand Down
2 changes: 1 addition & 1 deletion assets/atlas/skeleton2.atlas.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(
path: "textures/enemies/skeleton2.png",
tile_size: Vec2(48., 48.),
tile_size: UVec2(48, 48),
columns: 4,
rows: 9,
padding: None,
Expand Down
2 changes: 1 addition & 1 deletion assets/atlas/snake.atlas.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(
path: "textures/enemies/snake.png",
tile_size: Vec2(28., 28.),
tile_size: UVec2(28, 28),
columns: 6,
rows: 9,
padding: None,
Expand Down
2 changes: 0 additions & 2 deletions assets/data/anim/crab.anim.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
AnimationData(
width: 32,
height: 32,
rows: 10,
cols: 8,
offset_x: -8,
Expand Down
2 changes: 0 additions & 2 deletions assets/data/anim/deathknight.anim.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
AnimationData(
width: 42,
height: 42,
rows: 9,
cols: 5,
offset_x: -13,
Expand Down
2 changes: 0 additions & 2 deletions assets/data/anim/skeleton.anim.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
AnimationData(
width: 48,
height: 48,
rows: 9,
cols: 4,
offset_x: -16,
Expand Down
2 changes: 0 additions & 2 deletions assets/data/anim/skeleton2.anim.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
AnimationData(
width: 48,
height: 48,
rows: 9,
cols: 4,
offset_x: -16,
Expand Down
2 changes: 0 additions & 2 deletions assets/data/anim/snake.anim.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
AnimationData(
width: 28,
height: 28,
rows: 9,
cols: 6,
offset_x: -6,
Expand Down
15 changes: 9 additions & 6 deletions src/action_panel.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use bevy::prelude::*;
use bevy::{
color::palettes::css::{LIME, RED, WHITE},
prelude::*,
};

use crate::{
loading::{FontHandles, UiTextureHandles},
Expand Down Expand Up @@ -254,15 +257,15 @@ fn spawn_action_panel_item(
style: TextStyle {
font: font_handles.jptext.clone(),
font_size: FONT_SIZE_ACTION_PANEL,
color: Color::GREEN,
color: LIME.into(),
},
},
TextSection {
value: item.target.displayed_chunks.join(""),
style: TextStyle {
font: font_handles.jptext.clone(),
font_size: FONT_SIZE_ACTION_PANEL,
color: Color::WHITE,
color: WHITE.into(),
},
},
],
Expand Down Expand Up @@ -369,7 +372,7 @@ fn update_action_panel(
if let Ok(mut text) = price_text_query.get_mut(*child) {
text.sections[0].value = format!("{}", price);
text.sections[0].style.color =
if disabled { Color::RED } else { Color::WHITE };
if disabled { RED.into() } else { WHITE.into() };
}
}
}
Expand All @@ -382,8 +385,8 @@ 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 { Color::RED } else { Color::GREEN };
text.sections[1].style.color = if disabled { Color::RED } else { Color::WHITE };
text.sections[0].style.color = if disabled { RED.into() } else { LIME.into() };
text.sections[1].style.color = if disabled { RED.into() } else { WHITE.into() };
}
}
}
Expand Down
55 changes: 26 additions & 29 deletions src/atlas_loader.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use bevy::{
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
prelude::*,
utils::BoxedFuture,
};
use serde::Deserialize;

#[derive(Asset, TypePath, Deserialize)]
struct AtlasImageDescriptor {
path: String,
tile_size: Vec2,
columns: usize,
rows: usize,
padding: Option<Vec2>,
offset: Option<Vec2>,
tile_size: UVec2,
columns: u32,
rows: u32,
padding: Option<UVec2>,
offset: Option<UVec2>,
}

#[derive(Asset, TypePath)]
Expand All @@ -27,31 +26,29 @@ impl AssetLoader for AtlasImageLoader {
type Asset = AtlasImage;
type Settings = ();
type Error = anyhow::Error;
fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let desc = ron::de::from_bytes::<AtlasImageDescriptor>(&bytes)?;

let layout = TextureAtlasLayout::from_grid(
desc.tile_size,
desc.columns,
desc.rows,
desc.padding,
desc.offset,
);

let layout_handle = load_context.add_labeled_asset("layout".to_string(), layout);

Ok(AtlasImage {
image: load_context.load(desc.path),
layout: layout_handle,
})
load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let desc = ron::de::from_bytes::<AtlasImageDescriptor>(&bytes)?;

let layout = TextureAtlasLayout::from_grid(
desc.tile_size,
desc.columns,
desc.rows,
desc.padding,
desc.offset,
);

let layout_handle = load_context.add_labeled_asset("layout".to_string(), layout);

Ok(AtlasImage {
image: load_context.load(desc.path),
layout: layout_handle,
})
}

Expand Down
91 changes: 42 additions & 49 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::{
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
prelude::*,
reflect::TypePath,
utils::{BoxedFuture, HashMap},
utils::HashMap,
};

use bevy_common_assets::ron::RonAssetPlugin;
Expand Down Expand Up @@ -41,9 +41,8 @@ pub struct GameData {
}

#[derive(Debug, Asset, Deserialize, TypePath)]
#[allow(dead_code)]
pub struct AnimationData {
pub width: usize,
pub height: usize,
pub rows: usize,
pub cols: usize,
pub offset_x: f32,
Expand Down Expand Up @@ -81,19 +80,17 @@ impl AssetLoader for PlainWordListLoader {
type Settings = ();
type Error = anyhow::Error;

fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let words = parse_plain(std::str::from_utf8(&bytes)?)?;
let list = WordList { words };
Ok(list)
})
_load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let words = parse_plain(std::str::from_utf8(&bytes)?)?;
let list = WordList { words };
Ok(list)
}

fn extensions(&self) -> &[&str] {
Expand All @@ -106,19 +103,17 @@ impl AssetLoader for JapaneseWordListLoader {
type Settings = ();
type Error = anyhow::Error;

fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let words = japanese_parser::parse(std::str::from_utf8(&bytes)?)?;
let list = WordList { words };
Ok(list)
})
_load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let words = japanese_parser::parse(std::str::from_utf8(&bytes)?)?;
let list = WordList { words };
Ok(list)
}

fn extensions(&self) -> &[&str] {
Expand All @@ -131,38 +126,36 @@ impl AssetLoader for GameDataLoader {
type Settings = ();
type Error = anyhow::Error;

fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;

let raw_game_data = ron::de::from_bytes::<RawGameData>(&bytes)?;
let raw_game_data = ron::de::from_bytes::<RawGameData>(&bytes)?;

let mut word_list_handles: HashMap<String, Handle<WordList>> = HashMap::default();
let mut word_list_handles: HashMap<String, Handle<WordList>> = HashMap::default();

for file_name in raw_game_data
.word_list_menu
.iter()
.cloned()
.flat_map(|word_list| word_list.word_lists)
{
let handle = load_context.load(file_name.clone());
for file_name in raw_game_data
.word_list_menu
.iter()
.cloned()
.flat_map(|word_list| word_list.word_lists)
{
let handle = load_context.load(file_name.clone());

word_list_handles.insert(file_name, handle);
}
word_list_handles.insert(file_name, handle);
}

let game_data = GameData {
word_list_menu: raw_game_data.word_list_menu,
word_lists: word_list_handles,
};
let game_data = GameData {
word_list_menu: raw_game_data.word_list_menu,
word_lists: word_list_handles,
};

Ok(game_data)
})
Ok(game_data)
}

fn extensions(&self) -> &[&str] {
Expand Down
7 changes: 5 additions & 2 deletions src/game_over.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use bevy::prelude::*;
use bevy::{
color::palettes::css::{RED, WHITE},
prelude::*,
};

use crate::{
enemy::AnimationState, loading::FontHandles, ui_color, wave::Waves, AfterUpdate, Currency,
Expand Down Expand Up @@ -93,7 +96,7 @@ fn spawn_game_over(
TextStyle {
font: font_handles.jptext.clone(),
font_size: FONT_SIZE,
color: if lost { Color::RED } else { Color::WHITE },
color: if lost { RED.into() } else { WHITE.into() },
},
)
.with_justify(JustifyText::Center),
Expand Down
Loading

0 comments on commit 767d076

Please sign in to comment.