Static World Gen and Display for the Overworld #5
1 changed files with 15 additions and 6 deletions
21
build.rs
21
build.rs
|
@ -47,12 +47,17 @@ impl AssetsWriter {
|
|||
let hash = hasher.finish();
|
||||
let const_name = format!("ASSET_{hash:X}");
|
||||
|
||||
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||
let out_dir: PathBuf = out_dir.into();
|
||||
png.save_png(out_dir.join(format!("{const_name}.png")))
|
||||
.expect("Failed to save png");
|
||||
|
||||
writeln!(self.file, "// {}", canonical_path.as_ref().display()).unwrap();
|
||||
write!(self.file, "const {const_name}: &'static [u8] = &[").unwrap();
|
||||
for byte in png.encode_png().expect("Failed to encode png") {
|
||||
write!(self.file, "{byte}, ").unwrap();
|
||||
}
|
||||
writeln!(self.file, "];").unwrap();
|
||||
writeln!(
|
||||
self.file,
|
||||
"const {const_name}: &[u8] = include_bytes!(\"{const_name}.png\");"
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
const_name
|
||||
}
|
||||
|
@ -183,7 +188,11 @@ fn process_svg<P: AsRef<Path> + Copy, Q: AsRef<Path>>(
|
|||
panic!("Cannot parse svg file {}: {err}", file.as_ref().display())
|
||||
});
|
||||
let mut pixmap = tiny_skia::Pixmap::new(TILE_SIZE, TILE_SIZE).unwrap();
|
||||
resvg::render(&tree, Default::default(), &mut pixmap.as_mut());
|
||||
let transform = tiny_skia::Transform::from_scale(
|
||||
TILE_SIZE as f32 / tree.size().width(),
|
||||
TILE_SIZE as f32 / tree.size().height()
|
||||
);
|
||||
resvg::render(&tree, transform, &mut pixmap.as_mut());
|
||||
|
||||
let const_name = writer.add_png(
|
||||
file.as_ref()
|
||||
|
|
Loading…
Reference in a new issue