Credits!
They are very rough, but easy enough to improve with some simple parsing.selection-refactor
parent
8a9b47be6b
commit
2c17ecb1cd
@ -0,0 +1,27 @@
|
||||
# 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
|
||||
@ -0,0 +1,152 @@
|
||||
use std::str::Utf8Error;
|
||||
|
||||
use bevy::{
|
||||
asset::{AssetLoader, LoadContext, LoadedAsset},
|
||||
reflect::{TypePath, TypeUuid},
|
||||
utils::BoxedFuture,
|
||||
};
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
pub(crate) struct CreditsPlugin;
|
||||
|
||||
impl Plugin for CreditsPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_asset::<CreditsText>()
|
||||
.init_asset_loader::<CreditsTextLoader>()
|
||||
.add_systems(Startup, init_credits_ui)
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
update_credits.run_if(on_event::<AssetEvent<CreditsText>>()),
|
||||
menu::exit_to_menu.run_if(in_state(GameState::Credits)),
|
||||
),
|
||||
)
|
||||
.add_systems(
|
||||
OnEnter(GameState::Credits),
|
||||
activate::<Credits, CreditsCamera>,
|
||||
)
|
||||
.add_systems(
|
||||
OnExit(GameState::Credits),
|
||||
deactivate::<Credits, CreditsCamera>,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, TypeUuid, TypePath)]
|
||||
#[uuid = "43df4a09-b5f0-4619-9223-8cf67dc9e844"]
|
||||
pub struct CreditsText {
|
||||
sections: Vec<TextSection>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct CreditsTextLoader;
|
||||
|
||||
impl AssetLoader for CreditsTextLoader {
|
||||
fn load<'a>(
|
||||
&'a self,
|
||||
bytes: &'a [u8],
|
||||
load_context: &'a mut LoadContext,
|
||||
) -> BoxedFuture<'a, Result<(), bevy::asset::Error>> {
|
||||
Box::pin(async move {
|
||||
let custom_asset = parse_credits(bytes)?;
|
||||
load_context.set_default_asset(LoadedAsset::new(custom_asset));
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
fn extensions(&self) -> &[&str] {
|
||||
&["credits.txt"]
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_credits(bytes: &[u8]) -> Result<CreditsText, Utf8Error> {
|
||||
let s = std::str::from_utf8(bytes)?;
|
||||
let sections: Vec<TextSection> = s
|
||||
.split('\n')
|
||||
.filter(|l| l.len() > 0)
|
||||
.map(|l| TextSection {
|
||||
value: String::from(l),
|
||||
..default()
|
||||
})
|
||||
.collect();
|
||||
|
||||
info!("Split lines: {:?}", s);
|
||||
|
||||
Ok(CreditsText { sections })
|
||||
}
|
||||
|
||||
#[derive(Debug, Component)]
|
||||
struct Credits;
|
||||
|
||||
#[derive(Debug, Component)]
|
||||
struct CreditsCamera;
|
||||
|
||||
fn init_credits_ui(mut commands: Commands, server: Res<AssetServer>) {
|
||||
commands.spawn((
|
||||
CreditsCamera,
|
||||
Camera2dBundle {
|
||||
camera: Camera {
|
||||
is_active: false,
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
},
|
||||
UiCameraConfig { show_ui: true },
|
||||
));
|
||||
|
||||
commands
|
||||
.spawn((
|
||||
Credits,
|
||||
NodeBundle {
|
||||
style: Style {
|
||||
width: Val::Percent(100.0),
|
||||
height: Val::Percent(100.0),
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
position_type: PositionType::Absolute,
|
||||
..default()
|
||||
},
|
||||
visibility: Visibility::Hidden,
|
||||
..default()
|
||||
},
|
||||
))
|
||||
.with_children(|parent| {
|
||||
let handle: Handle<CreditsText> = server.load("marian-chess.credits.txt");
|
||||
|
||||
parent.spawn((
|
||||
handle.clone(),
|
||||
TextBundle {
|
||||
text: Text {
|
||||
alignment: TextAlignment::Center,
|
||||
sections: vec![],
|
||||
..default()
|
||||
},
|
||||
background_color: Color::BLACK.with_a(0.5).into(),
|
||||
..default()
|
||||
},
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
fn update_credits(
|
||||
mut reader: EventReader<AssetEvent<CreditsText>>,
|
||||
credits_texts: Res<Assets<CreditsText>>,
|
||||
mut query: Query<(&mut Text, &Handle<CreditsText>)>,
|
||||
) {
|
||||
reader.iter().for_each(|event| match event {
|
||||
AssetEvent::Created { handle } | AssetEvent::Modified { handle } => {
|
||||
query
|
||||
.iter_mut()
|
||||
.filter(|(_, this_handle)| handle.clone() == (*this_handle).clone())
|
||||
.for_each(|(mut text, this_handle)| {
|
||||
if let Some(credits_text) = credits_texts.get(this_handle) {
|
||||
text.sections = credits_text.sections.clone();
|
||||
}
|
||||
});
|
||||
}
|
||||
AssetEvent::Removed { .. } => {
|
||||
info!("Removed Credit resource... we don't handle that...");
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
Reference in New Issue