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" build = "build.rs"
[dependencies] [dependencies]
bevy_fmod = { version = "0.3", features = ["live-update"] } bevy_fmod = { branch = "update-0.12", git = "https://github.com/Salzian/bevy_fmod", features = ["live-update"] }
bevy = { version = "0.11", features = ["jpeg", "hdr", "serialize"] } bevy = { version = "0.12", features = ["jpeg", "hdr", "serialize"] }
serde = "1" serde = "1"
toml = { version = "0.8", features = ["parse"] } toml = { version = "0.8", features = ["parse"] }
anyhow = "*"
thiserror = "*"
[profile.dev] [profile.dev]
opt-level = 3 opt-level = 3

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

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

@ -57,40 +57,20 @@ fn loading(
tweakfile: Res<Assets<tweak::Tweakfile>>, tweakfile: Res<Assets<tweak::Tweakfile>>,
mut next_state: ResMut<NextState<GameState>>, mut next_state: ResMut<NextState<GameState>>,
) { ) {
let s_ids = sprites let s = sprites.iter().len() > 0
.ids() && sprites
.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
.iter() .iter()
.all(|&id| server.get_load_state(id) == LoadState::Loaded); .all(|id| server.is_loaded_with_dependencies(id));
let g_ready = g_ids let g = gltfs.iter().len() > 0
&& gltfs
.iter() .iter()
.all(|&id| server.get_load_state(id) == LoadState::Loaded); .all(|id| server.is_loaded_with_dependencies(id));
let t_ready = t_ids let t = tweakfile.iter().len() > 0
&& tweakfile
.iter() .iter()
.all(|&id| server.get_load_state(id) == LoadState::Loaded); .all(|id| server.is_loaded_with_dependencies(id));
if s_ready && g_ready && t_ready {
if s && g && t {
next_state.set(GameState::Menu) next_state.set(GameState::Menu)
} }
}
} }

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

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

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

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

Loading…
Cancel
Save