From b983dc8e2376d6b5ddefca18e7402d6faa0b729d Mon Sep 17 00:00:00 2001 From: "Elijah C. Voigt" Date: Sun, 11 Feb 2024 22:39:37 -0800 Subject: [PATCH] Stub out intro animation --- assets/images/border.png | 3 ++ assets/martian.tweak.toml | 14 ++++- assets/models/Martian Chess.glb | 4 +- assets/untitled.glb | 3 ++ examples/gltf-inspector.rs | 78 ++++++++++++++------------- src/intro.rs | 95 +++++++++++++++++++++++++++++++++ src/main.rs | 3 ++ src/menu.rs | 4 +- 8 files changed, 161 insertions(+), 43 deletions(-) create mode 100644 assets/images/border.png create mode 100644 assets/untitled.glb create mode 100644 src/intro.rs diff --git a/assets/images/border.png b/assets/images/border.png new file mode 100644 index 0000000..7cdfd37 --- /dev/null +++ b/assets/images/border.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6aa0c5714784a5b3abfcd22a4b3f0a53f3016d88392f9eff771bd57d6687c988 +size 7607 diff --git a/assets/martian.tweak.toml b/assets/martian.tweak.toml index 34d82f5..8ecfaf3 100644 --- a/assets/martian.tweak.toml +++ b/assets/martian.tweak.toml @@ -29,6 +29,18 @@ Space Blanket Folds - https://www.textures.com/download/PBR0152/133187 Background 2D art by NASA: LINK HERE """ +[intro] +text = """ +At the intersection of humanity's wildest imaginations and the infinite of the cosmos, the lines between possible and real fall apart like dissolving paper. + +On Earth, a long tradition of combat and destruction amongst different groups has been upheld and respected; given a place in the social mind. As spacetime stretches ever on, the rhyme of the universe reveals itself, and even includes such traditions. + +And so, humanity came face to face with a curiosity. Looking to our martian analogues, we find a twin destructive tradition, but one which seems backwards. In their tradition, each victory is also a loss. Each battle is waged simultaneously with opponent and self, and a mutual pact of annihilation and tactics unfolds until one side lays barren, just as likely to be the victor. + +But Can you adapt? +Will you be a part of the universal rhyme, and if so, which side are you on? +""" + [resolution] x = 640 y = 480 @@ -171,7 +183,7 @@ tonemapping = "ReinhardLuminance" # https://docs.rs/bevy/0.11.3/bevy/render/view/struct.ColorGrading.html ### [display3d.color.grading] -exposure = 1.0 +exposure = 2.0 gamma = 1.0 pre_saturation = 1.0 post_saturation = 1.0 diff --git a/assets/models/Martian Chess.glb b/assets/models/Martian Chess.glb index 7487fd8..d40e64d 100644 --- a/assets/models/Martian Chess.glb +++ b/assets/models/Martian Chess.glb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a4a6207082a2a8a3802e7e1a645773e2cfb0d1975e972ebd366a7d8b2f33a411 -size 30084992 +oid sha256:f12f1d0da2a87e6324b24fce74fb9ac9f587ff79bf5b692c68f20de850091f1a +size 30092588 diff --git a/assets/untitled.glb b/assets/untitled.glb new file mode 100644 index 0000000..bad8c7c --- /dev/null +++ b/assets/untitled.glb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9bcb44ade7ce6f867eb86ddbedb980ac37e4f1603dbc663391da8c5b262c10bd +size 107092 diff --git a/examples/gltf-inspector.rs b/examples/gltf-inspector.rs index 8326548..b5c480e 100644 --- a/examples/gltf-inspector.rs +++ b/examples/gltf-inspector.rs @@ -3,55 +3,57 @@ use bevy::{gltf::Gltf, prelude::*}; fn main() { App::new() .add_plugins((DefaultPlugins,)) - .add_systems(Startup, startup) - .add_systems(Update, inspect) + .add_systems(Update, (inspect, load_gltf)) .run(); } -#[derive(Debug, Resource)] -struct AssetRegistry { - gltfs: Vec>, -} - -fn startup(server: Res, mut commands: Commands) { - commands.insert_resource(AssetRegistry { - gltfs: vec![server.load("gltf/Martian Chess.glb")], - }); - - commands.spawn(SpotLightBundle { - transform: Transform::from_xyz(0.0, 5.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }); - - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(1.0, 1.0, 1.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y), - ..default() - }); -} +#[derive(Debug, Component)] +struct InspectScene; fn inspect( - mut events: EventReader>, - gltfs: Res>, + mut events: EventReader>, + current: Query>, mut commands: Commands, ) { - events.iter().for_each(|event| match event { - AssetEvent::Created { handle } => { - let gltf = gltfs.get(handle).expect("Fetch GLTF data"); - commands.spawn(SceneBundle { - scene: gltf - .named_scenes - .get("Board") - .expect("Fetch board scene") - .clone(), - ..default() + events.read().for_each(|event| match event { + AssetEvent::LoadedWithDependencies { id } => { + // Cleanup existing scenes + current.iter().for_each(|e| { + commands.entity(e).despawn_recursive(); }); + + // Spawn default GLTF scene + commands.spawn(( + SceneBundle { + scene: Handle::Weak(id.clone()), + ..default() + }, + InspectScene, + )); } _ => (), }); } -fn track_named(events: Query<&Name, Added>) { - events.iter().for_each(|name| { - info!("named entity: {:?}", name); - }); +fn load_gltf( + mut events: EventReader, + server: Res, + mut handle: Local>, +) { + events.read().for_each(|event| match event { + FileDragAndDrop::DroppedFile { path_buf, .. } => { + let p = path_buf + .clone() + .into_os_string() + .into_string() + .unwrap() + .replace( + "D:\\Projects\\src\\gitea.elijah.run\\martian-chess\\assets\\", + "", + ); + info!("Loading {:?}", p); + *handle = server.load(p); + } + _ => warn!("ignored"), + }) } diff --git a/src/intro.rs b/src/intro.rs new file mode 100644 index 0000000..b18cc6a --- /dev/null +++ b/src/intro.rs @@ -0,0 +1,95 @@ +use crate::prelude::*; + +pub(crate) struct IntroPlugin; + +impl Plugin for IntroPlugin { + fn build(&self, app: &mut App) { + app.add_systems( + OnExit(GameState::Loading), + init_intro_text.run_if(resource_exists::()), + ) + .add_systems(OnEnter(GameState::Intro), activate::) + .add_systems(OnExit(GameState::Intro), deactivate::) + .add_systems(Update, play_intro + .run_if(in_state(GameState::())) + .run_if(not(resource_exists::())) + ) + // Continue to play state if the intro is done playing out + .add_systems( + Update, + continue_to_play + .run_if(|keys: Res>| -> bool { keys.just_pressed(KeyCode::Return) }) + .run_if(resource_exists::()), + ); + } +} + +#[derive(Debug, Component)] +struct Intro; + +#[derive(Debug, Resource)] +struct IntroPlayed; + +// Draw the intro text (invisible) on startup +// Requires the Tweakfile to be loaded +fn init_intro_text( + tweaks_file: Res, + tweaks: Res>, + mut commands: Commands, +) { + let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks"); + + let text = tweak.get::("intro_text").expect("Intro text"); + + commands + .spawn(( + Intro, + NodeBundle { + style: Style { + width: Val::Percent(100.0), + height: Val::Percent(100.0), + justify_content: JustifyContent::Center, + align_items: AlignItems::Center, + flex_direction: FlexDirection::Column, + position_type: PositionType::Absolute, + padding: UiRect::all(Val::Px(50.0)), + ..default() + }, + background_color: Color::NONE.into(), + visibility: Visibility::Hidden, + ..default() + }, + )) + .with_children(|parent| { + parent.spawn(( + Intro, + TextBundle::from_sections(text.chars().into_iter().map(|c| TextSection { + value: c.to_string(), + style: TextStyle { + font_size: 16.0, + color: Color::WHITE, + ..default() + }, + })) + .with_text_alignment(TextAlignment::Center), + )); + }); +} + +// Upon entering the Intro state, start the intro "animation" +fn play_intro( + mut text: Query<&mut Text, With>, + progress: Local, + mut commands: Commands, +) { + todo!("Play the intro animation, typing each character one at a time..."); + commands.insert_resource(IntroPlayed); +} +// Intro animation reveals one character every nth frame + +// Hit enter to skip the "animation" + +// Hit enter once the animation is complete to start the game +fn continue_to_play(mut next_state: ResMut>) { + next_state.set(GameState::Play) +} diff --git a/src/main.rs b/src/main.rs index f8d8a9a..054b6f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ mod debug; mod display3d; mod game; mod hit; +mod intro; mod loading; mod menu; mod prelude; @@ -63,6 +64,7 @@ fn main() { app.add_plugins(audio::AudioPlugin); app.add_plugins(ui::UiPlugin); app.add_plugins(tweak::TweakPlugin); + app.add_plugins(intro::IntroPlugin); app.run(); } @@ -72,6 +74,7 @@ pub enum GameState { Loading, Menu, Credits, + Intro, Play, Endgame, } diff --git a/src/menu.rs b/src/menu.rs index 598f224..8de026a 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -60,7 +60,7 @@ fn init_menu_ui(mut commands: Commands) { )); parent .spawn(( - GameState::Play, + GameState::Intro, ButtonBundle { style: Style { padding: UiRect::all(Val::Px(5.0)), @@ -73,7 +73,7 @@ fn init_menu_ui(mut commands: Commands) { )) .with_children(|parent| { parent.spawn(( - GameState::Play, + GameState::Intro, TextBundle::from_section( "Start", TextStyle {