diff --git a/assets/music/Galactic_Rap.mp3 b/assets/music/Galactic_Rap.mp3 deleted file mode 100644 index 41e09d9..0000000 Binary files a/assets/music/Galactic_Rap.mp3 and /dev/null differ diff --git a/assets/music/Galactic_Rap.ogg b/assets/music/Galactic_Rap.ogg new file mode 100644 index 0000000..3a0f56d Binary files /dev/null and b/assets/music/Galactic_Rap.ogg differ diff --git a/assets/music/Galactic_Rap_Destroyed.mp3 b/assets/music/Galactic_Rap_Destroyed.mp3 deleted file mode 100644 index 6d44bad..0000000 Binary files a/assets/music/Galactic_Rap_Destroyed.mp3 and /dev/null differ diff --git a/assets/music/Galactic_Rap_Destroyed.ogg b/assets/music/Galactic_Rap_Destroyed.ogg new file mode 100644 index 0000000..df5329a Binary files /dev/null and b/assets/music/Galactic_Rap_Destroyed.ogg differ diff --git a/assets/music/Galactic_Rap_Speedup.mp3 b/assets/music/Galactic_Rap_Speedup.mp3 deleted file mode 100644 index 01a2606..0000000 Binary files a/assets/music/Galactic_Rap_Speedup.mp3 and /dev/null differ diff --git a/assets/music/Galactic_Rap_Speedup.ogg b/assets/music/Galactic_Rap_Speedup.ogg new file mode 100644 index 0000000..34d2da0 Binary files /dev/null and b/assets/music/Galactic_Rap_Speedup.ogg differ diff --git a/assets/music/Mesmerizing_Galaxy_Broken.mp3 b/assets/music/Mesmerizing_Galaxy_Broken.mp3 deleted file mode 100644 index 8d0320b..0000000 Binary files a/assets/music/Mesmerizing_Galaxy_Broken.mp3 and /dev/null differ diff --git a/assets/music/Mesmerizing_Galaxy_Broken.ogg b/assets/music/Mesmerizing_Galaxy_Broken.ogg new file mode 100644 index 0000000..69c9cee Binary files /dev/null and b/assets/music/Mesmerizing_Galaxy_Broken.ogg differ diff --git a/assets/music/Mesmerizing_Galaxy_Loop.mp3 b/assets/music/Mesmerizing_Galaxy_Loop.mp3 deleted file mode 100644 index 0f6bba3..0000000 Binary files a/assets/music/Mesmerizing_Galaxy_Loop.mp3 and /dev/null differ diff --git a/assets/music/Mesmerizing_Galaxy_Loop.ogg b/assets/music/Mesmerizing_Galaxy_Loop.ogg new file mode 100644 index 0000000..923d690 Binary files /dev/null and b/assets/music/Mesmerizing_Galaxy_Loop.ogg differ diff --git a/assets/sounds/bzz.mp3 b/assets/sounds/bzz.mp3 deleted file mode 100644 index bde2f73..0000000 Binary files a/assets/sounds/bzz.mp3 and /dev/null differ diff --git a/assets/sounds/bzz.ogg b/assets/sounds/bzz.ogg new file mode 100644 index 0000000..029f567 Binary files /dev/null and b/assets/sounds/bzz.ogg differ diff --git a/build.rs b/build.rs index b218bb6..11082bd 100644 --- a/build.rs +++ b/build.rs @@ -17,6 +17,9 @@ struct Assets { /// of the constant storing their png. assets: BTreeMap, + /// Sound assets. + sound_assets: BTreeMap, + /// Asset groups contained within this asset group, mapping their name to the assets /// that group contains. groups: BTreeMap> @@ -37,15 +40,19 @@ impl AssetsWriter { } } - fn add_png>( + fn asset_name>(canonical_path: P) -> String { + let mut hasher = DefaultHasher::new(); + canonical_path.as_ref().hash(&mut hasher); + let hash = hasher.finish(); + format!("ASSET_{hash:X}") + } + + fn add_png + Copy>( &mut self, canonical_path: P, png: tiny_skia::Pixmap ) -> String { - let mut hasher = DefaultHasher::new(); - canonical_path.as_ref().hash(&mut hasher); - let hash = hasher.finish(); - let const_name = format!("ASSET_{hash:X}"); + let const_name = Self::asset_name(canonical_path); let out_dir = env::var_os("OUT_DIR").unwrap(); let out_dir: PathBuf = out_dir.into(); @@ -62,6 +69,18 @@ impl AssetsWriter { const_name } + fn add_ogg + Copy>(&mut self, canonical_path: P) -> String { + let const_name = Self::asset_name(canonical_path); + writeln!(self.file, "// {}", canonical_path.as_ref().display()).unwrap(); + writeln!( + self.file, + "const {const_name}: &[u8] = include_bytes!(\"{}\");", + canonical_path.as_ref().display() + ) + .unwrap(); + const_name + } + fn finish(mut self) { fn write_assets_struct( file: &mut File, @@ -85,6 +104,13 @@ impl AssetsWriter { asset_name.to_snake_case() )?; } + for asset_name in root.sound_assets.keys() { + writeln!( + file, + "{indent}\tpub {}: comfy::Sound,", + asset_name.to_snake_case() + )?; + } for group_name in root.groups.keys() { writeln!( file, @@ -101,6 +127,9 @@ impl AssetsWriter { for asset_const_name in root.assets.values() { writeln!(file, "{indent}\t\tc.load_texture_from_bytes({asset_const_name:?}, {asset_const_name});")?; } + for asset_const_name in root.sound_assets.values() { + writeln!(file, "{indent}\t\tcomfy::load_sound_from_bytes({asset_const_name:?}, {asset_const_name}, Default::default());")?; + } for group_name in root.groups.keys() { writeln!(file, "{indent}\t\t{group_name}::Assets::load(c);")?; } @@ -118,6 +147,13 @@ impl AssetsWriter { asset_name.to_snake_case() )?; } + for (asset_name, asset_const_name) in &root.sound_assets { + writeln!( + file, + "{indent}\t{}: comfy::sound_id({asset_const_name:?}),", + asset_name.to_snake_case() + )?; + } for group_name in root.groups.keys() { writeln!( file, @@ -170,6 +206,8 @@ fn process_dir + Copy>( groups.pop(); } else if path.extension().map(|ext| ext == "svg").unwrap_or(false) { process_svg(&path, dir, writer, groups); + } else if path.extension().map(|ext| ext == "ogg").unwrap_or(false) { + process_ogg(&path, dir, writer, groups); } } } @@ -196,7 +234,8 @@ fn process_svg + Copy, Q: AsRef>( resvg::render(&tree, transform, &mut pixmap.as_mut()); let const_name = writer.add_png( - file.as_ref() + &file + .as_ref() .canonicalize() .expect("Failed to canonicalize"), pixmap @@ -218,3 +257,33 @@ fn process_svg + Copy, Q: AsRef>( const_name ); } + +fn process_ogg + Copy, Q: AsRef>( + file: P, + dir: Q, + writer: &mut AssetsWriter, + groups: &[String] +) { + let const_name = writer.add_ogg( + &file + .as_ref() + .canonicalize() + .expect("Failed to canonicalize") + ); + let mut group = &mut writer.root; + for group_name in groups { + if !group.groups.contains_key(group_name) { + group.groups.insert(group_name.to_owned(), Box::default()); + } + group = group.groups.get_mut(group_name).unwrap(); + } + group.sound_assets.insert( + file.as_ref() + .file_stem() + .expect("File doesn't have a stem") + .to_str() + .expect("Non-UTF8 file names aren't allowed") + .into(), + const_name + ); +}