MCPcopy Create free account
hub / github.com/aspizu/goboscript / sound

Method sound

src/codegen/sb3.rs:878–901  ·  view source on GitHub ↗
(&mut self, input: &Path, sound: &Sound, d: D)

Source from the content-addressed store, hash-verified

876 }
877
878 pub fn sound(&mut self, input: &Path, sound: &Sound, d: D) -> io::Result<()> {
879 let path = input.join(&*sound.path);
880 let hash = self
881 .costumes
882 .get(&sound.path)
883 .cloned()
884 .map(Ok::<_, io::Error>)
885 .unwrap_or_else(|| {
886 let mut file = match File::open(&path) {
887 Ok(file) => file,
888 Err(error) => {
889 d.report(DiagnosticKind::IOError(error), &sound.span);
890 return Ok(Default::default());
891 }
892 };
893 let mut hasher = Md5::new();
894 io::copy(&mut file, &mut hasher)?;
895 let hash: SmolStr = format!("{:x}", hasher.finalize()).into();
896 self.costumes.insert(sound.path.clone(), hash.clone());
897 Ok(hash)
898 })?;
899 let (_, extension) = sound.path.rsplit_once('.').unwrap_or_default();
900 self.sound_entry(&sound.name, &hash, extension)
901 }
902
903 pub fn sound_entry(&mut self, name: &str, hash: &str, extension: &str) -> io::Result<()> {
904 write!(self, "{{")?;

Callers 1

spriteMethod · 0.80

Calls 3

newFunction · 0.85
reportMethod · 0.80
sound_entryMethod · 0.80

Tested by

no test coverage detected