diff --git a/assets/martian-chess.credits.txt b/assets/martian-chess.credits.txt deleted file mode 100644 index ae3b1fd..0000000 --- a/assets/martian-chess.credits.txt +++ /dev/null @@ -1,27 +0,0 @@ -# Martian Chess - -An Icehouse game by Andrew Looney - -Art by Sam Hall - -Programming by Elijah Voigt - ---- - -# Third Party Tools - -Bevy Engine: bevyengine.org - -FMOD/FMOD Studio: fmod.com - ---- - -# Art Assets - -Image Textures retrieved from textures.com: - -Concrete Energy Pole - https://www.textures.com/download/PBR0340/136381 - -Space Blanket Folds - https://www.textures.com/download/PBR0152/133187 - -Background 2D art by NASA: LINK HERE \ No newline at end of file diff --git a/assets/martian.tweak.toml b/assets/martian.tweak.toml index 94c6522..75d0d03 100644 --- a/assets/martian.tweak.toml +++ b/assets/martian.tweak.toml @@ -1,3 +1,34 @@ +[credits] +text = """ +# Martian Chess + +An Icehouse game by Andrew Looney + +Art by Sam Hall + +Programming by Elijah Voigt + +--- + +# Third Party Tools + +Bevy Engine: bevyengine.org + +FMOD/FMOD Studio: fmod.com + +--- + +# Art Assets + +Image Textures retrieved from textures.com: + +Concrete Energy Pole - https://www.textures.com/download/PBR0340/136381 + +Space Blanket Folds - https://www.textures.com/download/PBR0152/133187 + +Background 2D art by NASA: LINK HERE +""" + ######################################################################### # Audio settings ######################################################################### @@ -139,4 +170,4 @@ tonemapping = "ReinhardLuminance" exposure = 1.0 gamma = 1.0 pre_saturation = 1.0 -post_saturation = 1.0 \ No newline at end of file +post_saturation = 1.0 diff --git a/src/credits.rs b/src/credits.rs index 2cd3bd1..992587b 100644 --- a/src/credits.rs +++ b/src/credits.rs @@ -1,93 +1,28 @@ -use bevy::asset::AsyncReadExt; -use std::str::Utf8Error; -use thiserror::Error; - -use bevy::{ - asset::{io::Reader, AssetLoader, LoadContext}, - reflect::{TypePath, TypeUuid}, - utils::BoxedFuture, -}; - use crate::prelude::*; pub(crate) struct CreditsPlugin; impl Plugin for CreditsPlugin { fn build(&self, app: &mut App) { - app.register_asset_loader(CreditsTextLoader) - .init_asset::() - .add_systems(Startup, init_credits_ui) + app.add_systems(Startup, init_credits_ui) .add_systems( Update, ( - update_credits.run_if(on_event::>()), menu::exit_to_menu.run_if(in_state(GameState::Credits)), ), ) - .add_systems(OnEnter(GameState::Credits), activate::) + .add_systems(OnEnter(GameState::Credits), ( + update_credits, + activate::.after(update_credits), + )) .add_systems(OnExit(GameState::Credits), deactivate::); } } -#[derive(Debug, TypeUuid, TypePath, Asset)] -#[uuid = "43df4a09-b5f0-4619-9223-8cf67dc9e844"] -pub struct CreditsText { - sections: Vec, -} - -#[derive(Debug, Error)] -enum CreditsError { - #[error("Failed to read file")] - IO(#[from] std::io::Error), - #[error("Failed to decode file")] - Decode(#[from] Utf8Error), -} - -#[derive(Default)] -struct CreditsTextLoader; - -impl AssetLoader for CreditsTextLoader { - type Asset = CreditsText; - type Settings = (); - type Error = CreditsError; - - fn load<'a>( - &'a self, - reader: &'a mut Reader, - _settings: &'a Self::Settings, - _load_context: &'a mut LoadContext, - ) -> BoxedFuture<'a, Result> { - Box::pin(async move { - let mut bytes = Vec::new(); - reader.read_to_end(&mut bytes).await?; - let result = parse_credits(bytes.as_slice())?; - Ok(result) - }) - } - - fn extensions(&self) -> &[&str] { - &["credits.txt"] - } -} - -fn parse_credits(bytes: &[u8]) -> Result { - let s = std::str::from_utf8(bytes)?; - let sections: Vec = s - .split('\n') - .filter(|l| l.len() > 0) - .map(|l| TextSection { - value: String::from(l), - ..default() - }) - .collect(); - - Ok(CreditsText { sections }) -} - #[derive(Debug, Component)] struct Credits; -fn init_credits_ui(mut commands: Commands, server: Res) { +fn init_credits_ui(mut commands: Commands) { commands .spawn(( Credits, @@ -105,10 +40,8 @@ fn init_credits_ui(mut commands: Commands, server: Res) { }, )) .with_children(|parent| { - let handle: Handle = server.load("martian-chess.credits.txt"); - parent.spawn(( - handle.clone(), + Credits, TextBundle { text: Text { alignment: TextAlignment::Center, @@ -123,25 +56,26 @@ fn init_credits_ui(mut commands: Commands, server: Res) { } fn update_credits( - mut reader: EventReader>, - credits_texts: Res>, - mut query: Query<(&mut Text, &Handle)>, + mut query: Query<&mut Text, With>, + tweaks: Res>, + tweaks_file: Res, ) { - reader.read().for_each(|event| match event { - AssetEvent::Added { id } - | AssetEvent::LoadedWithDependencies { id } - | AssetEvent::Modified { id } => { - query - .iter_mut() - .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(); + let tweak = tweaks + .get(tweaks_file.handle.clone()) + .expect("Load tweakfile"); + + query + .iter_mut() + .for_each(|mut text| { + let credits_text = tweak.get::("credits_text").unwrap(); + text.sections = { + credits_text.split('\n').map(|l| { + TextSection { + value: format!("{}\n", l), + style: TextStyle { ..default() }, } - }); - } - AssetEvent::Removed { .. } => { - warn!("Removed Credit resource... we don't handle that..."); - } - }) + }).collect() + }; + info!("Text sections: {:?}", text.sections); + }); }