mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-24 06:51:30 +11:00
50018a52bf
This is my first time contributing here so I was pretty unfamiliar with the codebase and may have done some things incorrectly. ## Description - Added a sound extractor to extract sound event ids and identifiers - Added a `Sound` enum (with a build script) to represent sound effects - Added a `play_sound` method to `Instance` and `Client` - Re-implemented sound effects in the parkour example ## Test Plan I tested this using the sounds I added to the parkour example. #### Related Hopefully fixes #206
49 lines
1.2 KiB
Rust
49 lines
1.2 KiB
Rust
use std::path::Path;
|
|
use std::process::Command;
|
|
use std::{env, fs};
|
|
|
|
use anyhow::Context;
|
|
use proc_macro2::{Ident, Span};
|
|
|
|
mod block;
|
|
mod enchant;
|
|
mod item;
|
|
mod sound;
|
|
mod translation_key;
|
|
|
|
pub fn main() -> anyhow::Result<()> {
|
|
println!("cargo:rerun-if-changed=../../extracted/");
|
|
|
|
let generators = [
|
|
(block::build as fn() -> _, "block.rs"),
|
|
(enchant::build, "enchant.rs"),
|
|
(item::build, "item.rs"),
|
|
(sound::build, "sound.rs"),
|
|
(translation_key::build, "translation_key.rs"),
|
|
];
|
|
|
|
let out_dir = env::var_os("OUT_DIR").context("failed to get OUT_DIR env var")?;
|
|
|
|
for (gen, file_name) in generators {
|
|
let path = Path::new(&out_dir).join(file_name);
|
|
let code = gen()?.to_string();
|
|
fs::write(&path, code)?;
|
|
|
|
// Format the output for debugging purposes.
|
|
// Doesn't matter if rustfmt is unavailable.
|
|
let _ = Command::new("rustfmt").arg(path).output();
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn ident(s: impl AsRef<str>) -> Ident {
|
|
let s = s.as_ref().trim();
|
|
|
|
match s.as_bytes() {
|
|
// TODO: check for the other rust keywords.
|
|
[b'0'..=b'9', ..] | b"type" => Ident::new(&format!("_{s}"), Span::call_site()),
|
|
_ => Ident::new(s, Span::call_site()),
|
|
}
|
|
}
|