Skip to content

Commit

Permalink
update to bevy 0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-reinhart authored and kgv committed Jul 5, 2024
1 parent 158e21c commit b5829bc
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 42 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_fluent"
version = "0.9.0"
version = "0.10.0"
authors = ["g <[email protected]>"]
edition = "2021"
description = "Bevy plugin for localization using Fluent"
Expand All @@ -18,7 +18,7 @@ categories = [
exclude = [".github/**/*"]

[dependencies]
bevy = { version = "0.13.0", default-features = false, features = [
bevy = { version = "0.14", default-features = false, features = [
"bevy_asset",
] }
fluent = "0.16.0"
Expand All @@ -36,5 +36,5 @@ unic-langid = { version = "0.9.4", features = ["serde"] }
uuid = { version = "1.7.0", features = ["serde", "v4", "v5"] }

[dev-dependencies]
bevy = "0.13.0"
bevy = "0.14"
unic-langid = { version = "0.9.4", features = ["macros"] }
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

| bevy | bevy_fluent |
| ---- | ----------- |
| 0.14 | 0.10 |
| 0.13 | 0.9 |
| 0.12 | 0.8 |
| 0.11 | 0.7 |
Expand Down
16 changes: 8 additions & 8 deletions examples/ui/systems/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
to_sentence_case::ToSentenceCase,
GameState,
};
use bevy::prelude::*;
use bevy::{color::palettes::css, prelude::*};
use bevy_fluent::prelude::*;
use fluent_content::Content;

Expand Down Expand Up @@ -50,7 +50,7 @@ pub fn setup(
align_items: AlignItems::Center,
..default()
},
background_color: Color::DARK_GRAY.into(),
background_color: css::DARK_GRAY.into(),
..default()
})
.with_children(|parent| {
Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn setup(
align_items: AlignItems::Center,
..default()
},
background_color: Color::GRAY.into(),
background_color: css::GRAY.into(),
..default()
},
))
Expand Down Expand Up @@ -121,7 +121,7 @@ pub fn setup(
align_items: AlignItems::Center,
..default()
},
background_color: Color::GRAY.into(),
background_color: css::GRAY.into(),
..default()
})
.with_children(|parent| {
Expand Down Expand Up @@ -150,7 +150,7 @@ pub fn setup(
align_items: AlignItems::Center,
..default()
},
background_color: Color::GRAY.into(),
background_color: css::GRAY.into(),
..default()
},
))
Expand Down Expand Up @@ -182,9 +182,9 @@ pub fn interaction(
) {
for (interaction, mut color) in query.iter_mut() {
*color = match interaction {
Interaction::Pressed => Color::DARK_GRAY.into(),
Interaction::Hovered => Color::SILVER.into(),
Interaction::None => Color::GRAY.into(),
Interaction::Pressed => css::DARK_GRAY.into(),
Interaction::Hovered => css::SILVER.into(),
Interaction::None => css::GRAY.into(),
}
}
}
Expand Down
38 changes: 18 additions & 20 deletions src/assets/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy::{
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
prelude::*,
reflect::TypePath,
utils::{tracing::instrument, BoxedFuture},
utils::tracing::instrument,
};
use fluent::{bundle::FluentBundle, FluentResource};
use intl_memoizer::concurrent::IntlLangMemoizer;
Expand Down Expand Up @@ -37,26 +37,24 @@ impl AssetLoader for BundleAssetLoader {
type Settings = ();
type Error = Error;

fn load<'a>(
&self,
reader: &'a mut Reader,
async fn load<'a>(
&'a self,
reader: &'a mut Reader<'_>,
_: &'a Self::Settings,
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset>> {
Box::pin(async move {
let path = load_context.path();
let mut content = String::new();
reader.read_to_string(&mut content).await?;
match path.extension() {
Some(extension) if extension == "ron" => {
load(ron::de::from_str(&content)?, load_context).await
}
Some(extension) if extension == "yaml" || extension == "yml" => {
load(serde_yaml::from_str(&content)?, load_context).await
}
_ => unreachable!("We already check all the supported extensions."),
load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let path = load_context.path();
let mut content = String::new();
reader.read_to_string(&mut content).await?;
match path.extension() {
Some(extension) if extension == "ron" => {
load(ron::de::from_str(&content)?, load_context).await
}
})
Some(extension) if extension == "yaml" || extension == "yml" => {
load(serde_yaml::from_str(&content)?, load_context).await
}
_ => unreachable!("We already check all the supported extensions."),
}
}

fn extensions(&self) -> &[&str] {
Expand All @@ -81,7 +79,7 @@ async fn load(data: Data, load_context: &mut LoadContext<'_>) -> Result<BundleAs
path = parent.join(path);
}
}
let loaded = load_context.load_direct(path).await?;
let loaded = load_context.loader().direct().untyped().load(path).await?;
let resource = loaded.get::<ResourceAsset>().unwrap();
if let Err(errors) = bundle.add_resource(resource.0.clone()) {
warn_span!("add_resource").in_scope(|| {
Expand Down
20 changes: 9 additions & 11 deletions src/assets/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy::{
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
prelude::*,
reflect::TypePath,
utils::{tracing::instrument, BoxedFuture},
utils::tracing::instrument,
};
use fluent::FluentResource;
use std::{ops::Deref, str, sync::Arc};
Expand All @@ -32,17 +32,15 @@ impl AssetLoader for ResourceAssetLoader {
type Settings = ();
type Error = Error;

fn load<'a>(
&self,
reader: &'a mut Reader,
async fn load<'a>(
&'a self,
reader: &'a mut Reader<'_>,
_: &'a Self::Settings,
_: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset>> {
Box::pin(async move {
let mut content = String::new();
reader.read_to_string(&mut content).await?;
Ok(ResourceAsset(deserialize(content)))
})
_: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut content = String::new();
reader.read_to_string(&mut content).await?;
Ok(ResourceAsset(deserialize(content)))
}

fn extensions(&self) -> &[&str] {
Expand Down

0 comments on commit b5829bc

Please sign in to comment.