gba-lsdpack-player/build.rs

35 lines
1.2 KiB
Rust
Raw Normal View History

2024-01-14 06:33:58 +00:00
use build_const::ConstWriter;
const SONG_SOURCE: &str = include_str!("lsdpack.s");
fn main() {
let mut consts = ConstWriter::for_build("lsdpack_bc")
.unwrap()
.finish_dependencies();
let bytes: Vec<u8> = SONG_SOURCE
.lines()
.map(|s| s.trim().strip_prefix("DB "))
.flatten() // filter to lines starting with DB
.map(|s| {
s.split_once(';')
.unwrap_or((s, ""))
.0 // remove comments
.chars()
.filter(|c| *c == ',' || c.is_ascii_hexdigit()) // remove spaces and dollars
.collect::<String>()
.split(',')
.map(|s| u8::from_str_radix(s, 16).unwrap())
.collect::<Vec<u8>>()
})
.flatten() // merge iterator of vectors
.collect();
let song_positions: Vec<usize> = SONG_SOURCE
.lines()
.map(|s| s.trim().strip_prefix("dw "))
.flatten() // filter to lines from SongLocations
.map(|s| usize::from_str_radix(s.split_once('$').unwrap().1, 16).unwrap() - 0x4000)
.collect();
consts.add_array("LSDPACK_DATA", "u8", &bytes);
consts.add_array("LSDPACK_SONG_POSITIONS", "usize", &song_positions);
}