aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/startup_intro.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-03 12:19:38 +0300
committerValentin Popov <valentin@popov.link>2026-12-03 12:19:38 +0300
commite9ba4a3e0a039715fdf1c169edd7f56faa8570b1 (patch)
treea424ebdfd05a9bbe4e77f828b0e70933aa03166e /apps/fparkan-game/src/startup_intro.rs
parent3522319c1728e715741ac4b149c6e712fd900e73 (diff)
downloadfparkan-e9ba4a3e0a039715fdf1c169edd7f56faa8570b1.tar.xz
fparkan-e9ba4a3e0a039715fdf1c169edd7f56faa8570b1.zip
feat(ui): play the installed startup movies before the menu
Diffstat (limited to 'apps/fparkan-game/src/startup_intro.rs')
-rw-r--r--apps/fparkan-game/src/startup_intro.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/apps/fparkan-game/src/startup_intro.rs b/apps/fparkan-game/src/startup_intro.rs
new file mode 100644
index 00000000..d5fa80ef
--- /dev/null
+++ b/apps/fparkan-game/src/startup_intro.rs
@@ -0,0 +1,67 @@
+//! Startup movie sequence shown before the mission menu.
+
+use fparkan_assets::startup_movies::movie_paths;
+use fparkan_platform_winit::{intro_video::IntroVideo, startup_window};
+use fparkan_vfs::DirectoryVfs;
+use std::{
+ collections::VecDeque,
+ path::{Path, PathBuf},
+};
+use winit::window::Window;
+
+pub(super) struct StartupIntro {
+ waiting: VecDeque<PathBuf>,
+ playing: Option<IntroVideo>,
+}
+
+impl StartupIntro {
+ pub(super) fn open(root: &Path) -> Option<Self> {
+ let paths = match movie_paths(&DirectoryVfs::new(root)) {
+ Ok(paths) => paths,
+ Err(error) => {
+ eprintln!("startup movies: {error}");
+ return None;
+ }
+ };
+ if paths.is_empty() {
+ return None;
+ }
+ Some(Self {
+ waiting: paths.iter().map(|path| root.join(path.as_str())).collect(),
+ playing: None,
+ })
+ }
+
+ /// Returns whether a movie is still playing.
+ pub(super) fn update(&mut self, window: &Window) -> bool {
+ if let Some(movie) = &self.playing {
+ match movie.finished() {
+ Ok(false) => return true,
+ Ok(true) => {}
+ Err(error) => eprintln!("startup playback: {error}"),
+ }
+ }
+ self.playing = None;
+ while let Some(path) = self.waiting.pop_front() {
+ if let Err(error) = startup_window::paint(window, [1, 1], &[0]) {
+ eprintln!("startup movie background: {error}");
+ }
+ match IntroVideo::play(window, &path) {
+ Ok(movie) => {
+ self.playing = Some(movie);
+ return true;
+ }
+ Err(error) => eprintln!("startup movie {}: {error}", path.display()),
+ }
+ }
+ false
+ }
+
+ pub(super) fn resize(&self, window: &Window) {
+ if let Some(movie) = &self.playing {
+ if let Err(error) = movie.resize(window) {
+ eprintln!("startup movie resize: {error}");
+ }
+ }
+ }
+}