mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-10 00:51:34 +11:00
Remove unneeded stuff from image-converter
This commit is contained in:
parent
f53cd9b25a
commit
875a0fbb65
|
@ -12,8 +12,6 @@ proc-macro = true
|
|||
|
||||
[dependencies]
|
||||
image = { version = "0.23", default-features = false, features = [ "png", "bmp" ] }
|
||||
toml = "0.7"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
syn = { version = "2", features = ["full"] }
|
||||
proc-macro2 = "1"
|
||||
quote = "1"
|
||||
|
|
|
@ -1,25 +1,7 @@
|
|||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
|
||||
use crate::{Colour, Colours, TileSize};
|
||||
|
||||
pub(crate) fn parse(filename: &str) -> Box<dyn Config> {
|
||||
let config_toml =
|
||||
fs::read_to_string(filename).unwrap_or_else(|_| panic!("Failed to read file {filename}"));
|
||||
|
||||
let config: ConfigV1 = toml::from_str(&config_toml).expect("Failed to parse file");
|
||||
|
||||
if config.version != "1.0" {
|
||||
panic!(
|
||||
"Expected version of {} to be 1.0, got {}",
|
||||
filename, config.version
|
||||
);
|
||||
}
|
||||
|
||||
Box::new(config)
|
||||
}
|
||||
|
||||
pub(crate) trait Config {
|
||||
fn crate_prefix(&self) -> String;
|
||||
fn images(&self) -> HashMap<String, &dyn Image>;
|
||||
|
@ -31,96 +13,3 @@ pub(crate) trait Image {
|
|||
fn tile_size(&self) -> TileSize;
|
||||
fn colours(&self) -> Colours;
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ConfigV1 {
|
||||
version: String,
|
||||
crate_prefix: Option<String>,
|
||||
transparent_colour: Option<String>,
|
||||
|
||||
image: HashMap<String, ImageV1>,
|
||||
}
|
||||
|
||||
impl Config for ConfigV1 {
|
||||
fn crate_prefix(&self) -> String {
|
||||
self.crate_prefix
|
||||
.clone()
|
||||
.unwrap_or_else(|| "agb".to_owned())
|
||||
}
|
||||
|
||||
fn images(&self) -> HashMap<String, &dyn Image> {
|
||||
self.image
|
||||
.iter()
|
||||
.map(|(filename, image)| (filename.clone(), image as &dyn Image))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn transparent_colour(&self) -> Option<Colour> {
|
||||
if let Some(colour) = &self
|
||||
.transparent_colour
|
||||
.as_ref()
|
||||
.map(|colour| colour.parse().unwrap())
|
||||
{
|
||||
return Some(*colour);
|
||||
}
|
||||
|
||||
self.image
|
||||
.values()
|
||||
.flat_map(|image| image.transparent_colour())
|
||||
.next()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ImageV1 {
|
||||
filename: String,
|
||||
transparent_colour: Option<String>,
|
||||
tile_size: TileSizeV1,
|
||||
colours: Option<u32>,
|
||||
}
|
||||
|
||||
impl Image for ImageV1 {
|
||||
fn filename(&self) -> String {
|
||||
self.filename.clone()
|
||||
}
|
||||
|
||||
fn tile_size(&self) -> TileSize {
|
||||
self.tile_size.into()
|
||||
}
|
||||
|
||||
fn colours(&self) -> Colours {
|
||||
match self.colours {
|
||||
None | Some(16) => Colours::Colours16,
|
||||
Some(256) => Colours::Colours256,
|
||||
_ => panic!("colours must either not be set or 16 or 256"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ImageV1 {
|
||||
fn transparent_colour(&self) -> Option<Colour> {
|
||||
self.transparent_colour
|
||||
.as_ref()
|
||||
.map(|colour| colour.parse().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone, Copy)]
|
||||
pub enum TileSizeV1 {
|
||||
#[serde(rename = "8x8")]
|
||||
Tile8,
|
||||
#[serde(rename = "16x16")]
|
||||
Tile16,
|
||||
#[serde(rename = "32x32")]
|
||||
Tile32,
|
||||
}
|
||||
|
||||
impl From<TileSizeV1> for TileSize {
|
||||
fn from(item: TileSizeV1) -> Self {
|
||||
match item {
|
||||
TileSizeV1::Tile8 => TileSize::Tile8,
|
||||
TileSizeV1::Tile16 => TileSize::Tile16,
|
||||
TileSizeV1::Tile32 => TileSize::Tile32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,6 @@ use colour::Colour;
|
|||
#[derive(Debug, Clone, Copy)]
|
||||
pub(crate) enum TileSize {
|
||||
Tile8,
|
||||
Tile16,
|
||||
Tile32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
@ -43,8 +41,6 @@ impl TileSize {
|
|||
fn to_size(self) -> usize {
|
||||
match self {
|
||||
TileSize::Tile8 => 8,
|
||||
TileSize::Tile16 => 16,
|
||||
TileSize::Tile32 => 32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,31 +172,6 @@ pub fn include_background_gfx(input: TokenStream) -> TokenStream {
|
|||
include_gfx_from_config(config, module_name, Path::new(&root))
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn include_gfx(input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as syn::LitStr);
|
||||
|
||||
let filename = input.value();
|
||||
|
||||
let root = std::env::var("CARGO_MANIFEST_DIR").expect("Failed to get cargo manifest dir");
|
||||
let path = Path::new(&root).join(&*filename);
|
||||
|
||||
let config = config::parse(&path.to_string_lossy());
|
||||
|
||||
let parent = path
|
||||
.parent()
|
||||
.expect("Expected a parent directory for the path");
|
||||
|
||||
let module_name = format_ident!(
|
||||
"{}",
|
||||
path.file_stem()
|
||||
.expect("Expected a file stem")
|
||||
.to_string_lossy()
|
||||
);
|
||||
|
||||
include_gfx_from_config(config, module_name, parent)
|
||||
}
|
||||
|
||||
fn include_gfx_from_config(
|
||||
config: Box<dyn config::Config>,
|
||||
module_name: syn::Ident,
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
version = "1.0"
|
||||
transparent_colour = "121105"
|
||||
|
||||
[image.stars]
|
||||
filename = "stars.png"
|
||||
tile_size = "8x8"
|
||||
|
||||
[image.title]
|
||||
filename = "title-screen.png"
|
||||
tile_size = "8x8"
|
||||
|
||||
[image.help]
|
||||
filename = "help-text.png"
|
||||
tile_size = "8x8"
|
||||
|
||||
[image.descriptions1]
|
||||
filename = "descriptions1.png"
|
||||
tile_size = "8x8"
|
||||
|
||||
[image.descriptions2]
|
||||
filename = "descriptions2.png"
|
||||
tile_size = "8x8"
|
|
@ -1,11 +1,17 @@
|
|||
use agb::{
|
||||
display::tiled::{RegularMap, TileFormat, TileSet, TileSetting, TiledMap, VRamManager},
|
||||
include_gfx, rng,
|
||||
include_background_gfx, rng,
|
||||
};
|
||||
|
||||
use crate::sfx::Sfx;
|
||||
|
||||
include_gfx!("gfx/backgrounds.toml");
|
||||
include_background_gfx!(backgrounds, "121105",
|
||||
stars => "gfx/stars.png",
|
||||
title => "gfx/title-screen.png",
|
||||
help => "gfx/help-text.png",
|
||||
descriptions1 => "gfx/descriptions1.png",
|
||||
descriptions2 => "gfx/descriptions2.png",
|
||||
);
|
||||
|
||||
pub fn load_palettes(vram: &mut VRamManager) {
|
||||
vram.set_background_palettes(backgrounds::PALETTES);
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
version = "1.0"
|
||||
|
||||
transparent_colour = "2ce8f4"
|
||||
|
||||
[image.thanks_for_playing]
|
||||
filename = "thanks_for_playing.png"
|
||||
tile_size = "8x8"
|
||||
|
||||
[image.splash]
|
||||
filename = "splash.png"
|
||||
tile_size = "8x8"
|
|
@ -1,7 +0,0 @@
|
|||
version = "1.0"
|
||||
|
||||
transparent_colour = "2ce8f4"
|
||||
|
||||
[image.background]
|
||||
filename = "tile_sheet.png"
|
||||
tile_size = "8x8"
|
|
@ -101,7 +101,7 @@ mod map_tiles {
|
|||
}
|
||||
}
|
||||
|
||||
agb::include_gfx!("gfx/tile_sheet.toml");
|
||||
agb::include_background_gfx!(tile_sheet, "2ce8f4", background => "gfx/tile_sheet.png");
|
||||
|
||||
const GRAPHICS: &Graphics = agb::include_aseprite!("gfx/sprites.aseprite");
|
||||
const TAG_MAP: &TagMap = GRAPHICS.tags();
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use super::sfx::SfxPlayer;
|
||||
use agb::display::tiled::{RegularMap, TileFormat, TileSet, TileSetting, TiledMap, VRamManager};
|
||||
|
||||
agb::include_gfx!("gfx/splash_screens.toml");
|
||||
agb::include_background_gfx!(splash_screens,
|
||||
splash => "gfx/splash.png",
|
||||
thanks_for_playing => "gfx/thanks_for_playing.png",
|
||||
);
|
||||
|
||||
pub enum SplashScreen {
|
||||
Start,
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
version = "1.0"
|
||||
|
||||
transparent_colour = "53269a"
|
||||
|
||||
[image.background]
|
||||
filename = "background.png"
|
||||
tile_size = "8x8"
|
|
@ -57,7 +57,7 @@ const SWORDLESS_JUMP: &Tag = TAG_MAP.get("jump swordless");
|
|||
const SWORDLESS_ATTACK: &Tag = KNIFE_ATTACK;
|
||||
const SWORDLESS_JUMP_ATTACK: &Tag = KNIFE_JUMP_ATTACK;
|
||||
|
||||
agb::include_gfx!("gfx/background.toml");
|
||||
agb::include_background_gfx!(background, "53269a", background => "gfx/background.png");
|
||||
|
||||
type Number = FixedNum<8>;
|
||||
|
||||
|
|
Loading…
Reference in a new issue