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 hash = hasher.finish();
|
||||||
let const_name = format!("ASSET_{hash:X}");
|
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();
|
writeln!(self.file, "// {}", canonical_path.as_ref().display()).unwrap();
|
||||||
write!(self.file, "const {const_name}: &'static [u8] = &[").unwrap();
|
writeln!(
|
||||||
for byte in png.encode_png().expect("Failed to encode png") {
|
self.file,
|
||||||
write!(self.file, "{byte}, ").unwrap();
|
"const {const_name}: &[u8] = include_bytes!(\"{const_name}.png\");"
|
||||||
}
|
)
|
||||||
writeln!(self.file, "];").unwrap();
|
.unwrap();
|
||||||
|
|
||||||
const_name
|
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())
|
panic!("Cannot parse svg file {}: {err}", file.as_ref().display())
|
||||||
});
|
});
|
||||||
let mut pixmap = tiny_skia::Pixmap::new(TILE_SIZE, TILE_SIZE).unwrap();
|
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(
|
let const_name = writer.add_png(
|
||||||
file.as_ref()
|
file.as_ref()
|
||||||
|
|
Loading…
Reference in a new issue