So close to getting it to compile...

Then the real fun begins...
main
Elijah Voigt 2 years ago
parent 13a2e9f0a0
commit eca7e95e10

1130
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -5,10 +5,12 @@ edition = "2021"
build = "build.rs"
[dependencies]
bevy_fmod = { version = "0.3", features = ["live-update"] }
bevy = { version = "0.11", features = ["jpeg", "hdr", "serialize"] }
bevy_fmod = { branch = "update-0.12", git = "https://github.com/Salzian/bevy_fmod", features = ["live-update"] }
bevy = { version = "0.12", features = ["jpeg", "hdr", "serialize"] }
serde = "1"
toml = { version = "0.8", features = ["parse"] }
anyhow = "*"
thiserror = "*"
[profile.dev]
opt-level = 3

@ -1,7 +1,8 @@
use std::str::Utf8Error;
use thiserror::Error;
use bevy::{
asset::{AssetLoader, LoadContext, LoadedAsset},
asset::{io::Reader, AssetLoader, LoadContext},
reflect::{TypePath, TypeUuid},
utils::BoxedFuture,
};
@ -12,8 +13,8 @@ pub(crate) struct CreditsPlugin;
impl Plugin for CreditsPlugin {
fn build(&self, app: &mut App) {
app.add_asset::<CreditsText>()
.init_asset_loader::<CreditsTextLoader>()
app.register_asset_loader(CreditsTextLoader)
.init_asset::<CreditsText>()
.add_systems(Startup, init_credits_ui)
.add_systems(
Update,
@ -27,25 +28,36 @@ impl Plugin for CreditsPlugin {
}
}
#[derive(Debug, TypeUuid, TypePath)]
#[derive(Debug, TypeUuid, TypePath, Asset)]
#[uuid = "43df4a09-b5f0-4619-9223-8cf67dc9e844"]
pub struct CreditsText {
sections: Vec<TextSection>,
}
#[derive(Debug, Error)]
enum CreditsError {
IO(#[from] std::io::Error),
Parse(#[from] Utf8Error),
}
#[derive(Default)]
struct CreditsTextLoader;
impl AssetLoader for CreditsTextLoader {
type Asset = CreditsText;
type Settings = ();
type Error = CreditsError;
fn load<'a>(
&'a self,
bytes: &'a [u8],
reader: &'a mut Reader,
settings: &'a Self::Settings,
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<(), bevy::asset::Error>> {
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let custom_asset = parse_credits(bytes)?;
load_context.set_default_asset(LoadedAsset::new(custom_asset));
Ok(())
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
parse_credits(bytes.as_slice())
})
}
@ -112,10 +124,12 @@ fn update_credits(
mut query: Query<(&mut Text, &Handle<CreditsText>)>,
) {
reader.iter().for_each(|event| match event {
AssetEvent::Created { handle } | AssetEvent::Modified { handle } => {
AssetEvent::Added { id }
| AssetEvent::LoadedWithDependencies { id }
| AssetEvent::Modified { id } => {
query
.iter_mut()
.filter(|(_, this_handle)| handle.clone() == (*this_handle).clone())
.filter(|(_, this_handle)| id == (*this_handle).id())
.for_each(|(mut text, this_handle)| {
if let Some(credits_text) = credits_texts.get(this_handle) {
text.sections = credits_text.sections.clone();

@ -1,5 +1,4 @@
use bevy::{
asset::diagnostic::AssetCountDiagnosticsPlugin,
diagnostic::{
DiagnosticsStore, EntityCountDiagnosticsPlugin, FrameTimeDiagnosticsPlugin,
SystemInformationDiagnosticsPlugin,
@ -17,10 +16,6 @@ impl Plugin for DebugPlugin {
app.add_plugins((
FrameTimeDiagnosticsPlugin,
EntityCountDiagnosticsPlugin::default(),
AssetCountDiagnosticsPlugin::<Gltf>::default(),
AssetCountDiagnosticsPlugin::<Image>::default(),
AssetCountDiagnosticsPlugin::<Scene>::default(),
AssetCountDiagnosticsPlugin::<Font>::default(),
SystemInformationDiagnosticsPlugin::default(),
))
.init_resource::<DebugInfo>()
@ -132,11 +127,9 @@ fn display_diagnostics(
});
}
fn camera_info(
mut debug_infos: ResMut<DebugInfo>,
cameras: Query<(&Camera, &Name)>,
) {
let camera_names = cameras.iter()
fn camera_info(mut debug_infos: ResMut<DebugInfo>, cameras: Query<(&Camera, &Name)>) {
let camera_names = cameras
.iter()
.filter(|(c, _)| c.is_active)
.map(|(_, n)| n.as_str())
.collect::<Vec<&str>>()

@ -57,40 +57,20 @@ fn loading(
tweakfile: Res<Assets<tweak::Tweakfile>>,
mut next_state: ResMut<NextState<GameState>>,
) {
let s_ids = sprites
.ids()
.filter(|&id| matches!(id, HandleId::AssetPathId(_)))
.collect::<Vec<HandleId>>();
let g_ids = gltfs
.ids()
.filter(|&id| matches!(id, HandleId::AssetPathId(_)))
.collect::<Vec<HandleId>>();
let t_ids = tweakfile
.ids()
.filter(|&id| matches!(id, HandleId::AssetPathId(_)))
.collect::<Vec<HandleId>>();
debug!(
"Sprite len: {:?} | GLTF len: {:?} | Tweakfile: {:?}",
s_ids.len(),
g_ids.len(),
t_ids.len(),
);
if s_ids.len() > 0 && g_ids.len() > 0 {
let s_ready = s_ids
let s = sprites.iter().len() > 0
&& sprites
.iter()
.all(|&id| server.get_load_state(id) == LoadState::Loaded);
let g_ready = g_ids
.all(|id| server.is_loaded_with_dependencies(id));
let g = gltfs.iter().len() > 0
&& gltfs
.iter()
.all(|&id| server.get_load_state(id) == LoadState::Loaded);
let t_ready = t_ids
.all(|id| server.is_loaded_with_dependencies(id));
let t = tweakfile.iter().len() > 0
&& tweakfile
.iter()
.all(|&id| server.get_load_state(id) == LoadState::Loaded);
if s_ready && g_ready && t_ready {
next_state.set(GameState::Menu)
}
.all(|id| server.is_loaded_with_dependencies(id));
if s && g && t {
next_state.set(GameState::Menu)
}
}

@ -16,10 +16,7 @@ mod ui;
use std::time::Duration;
use bevy::{
asset::{ChangeWatcher, HandleId},
input::ButtonState,
};
use bevy::input::ButtonState;
use crate::prelude::*;

@ -1,7 +1,6 @@
use bevy::{
app::AppExit,
input::{keyboard::KeyboardInput, ButtonState},
window::PrimaryWindow,
};
use crate::prelude::*;

@ -1,4 +1,3 @@
pub use crate::*;
pub use bevy::asset::LoadState;
pub use bevy::gltf::Gltf;
pub use bevy::prelude::*;

@ -1,10 +1,11 @@
use crate::prelude::*;
use bevy::{
asset::{AssetLoader, LoadContext, LoadedAsset},
asset::{io::Reader, AssetLoader, LoadContext},
reflect::{TypePath, TypeUuid},
utils::BoxedFuture,
};
use serde::Deserialize;
use thiserror::Error;
/// A Tweakfile is resource used to specify game customization like asset names,
/// and non-user customizations made to the game during development.
@ -28,7 +29,7 @@ fn load_tweakfile(server: Res<AssetServer>, mut commands: Commands) {
struct GameTweakfile(Handle<Tweakfile>);
/// Tweakfile contains tweaks made to other parts of the game
#[derive(Debug, Deserialize, TypeUuid, TypePath)]
#[derive(Debug, Deserialize, TypeUuid, TypePath, Asset)]
#[uuid = "e5768efe-edce-4267-bdf4-dd8f8ca613c7"]
pub(crate) struct Tweakfile {
#[serde(default)]
@ -42,17 +43,28 @@ pub(crate) struct Tweakfile {
#[derive(Default)]
pub struct TweakfileLoader;
#[derive(Debug, Error)]
enum TweakfileError {
IO(#[from] std::io::Error),
Parse(#[from] toml::de::Error),
}
impl AssetLoader for TweakfileLoader {
type Asset = Tweakfile;
type Settings = ();
type Error = TweakfileError;
fn load<'a>(
&'a self,
bytes: &'a [u8],
reader: &'a mut Reader,
settings: &'a Self::Settings,
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<(), bevy::asset::Error>> {
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let s = std::str::from_utf8(bytes)?;
let custom_asset = toml::from_str::<Tweakfile>(s)?;
load_context.set_default_asset(LoadedAsset::new(custom_asset));
Ok(())
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let s = std::str::from_utf8(bytes.as_slice())?;
toml::from_str::<Tweakfile>(s)?
})
}

Loading…
Cancel
Save