use yog_data::{Res, Schema};
pub const DIR: &str = yog_ids::kind::SOUND;
#[derive(Schema, Debug, Clone, PartialEq)]
pub struct SoundFile {
pub sounds: Vec<Variant>,
pub subtitle: Option<Res>,
#[data(default)]
pub replace: bool,
}
#[derive(Schema, Debug, Clone, PartialEq)]
pub struct Variant {
pub sound: Res,
pub volume: Option<f32>,
pub pitch: Option<f32>,
pub weight: Option<u32>,
#[data(default)]
pub stream: bool,
#[data(default)]
pub preload: bool,
pub attenuation_distance: Option<u32>,
}
#[must_use]
pub fn id_of(mod_id: &str, rel: &str) -> Option<String> {
let path = rel
.strip_suffix(yog_ids::Format::Sound.ext())?
.strip_suffix(yog_ids::sep::DOT)?
.strip_prefix(DIR)?
.strip_prefix(yog_ids::sep::PATH)?;
Some(yog_ids::join(mod_id, &path.replace(yog_ids::sep::PATH, yog_ids::sep::DOT)))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn an_event_is_named_by_its_path_under_sound() {
assert_eq!(
id_of("hex", "sound/casting/cast.ysound").as_deref(),
Some("hex:casting.cast")
);
assert_eq!(id_of("hex", "sound/abacus.ysound").as_deref(), Some("hex:abacus"));
assert_eq!(id_of("hex", "block/abacus.ysound"), None);
assert_eq!(id_of("hex", "sound/abacus.ytexture"), None);
}
}