diff --git a/ashen/src/asset/color_map.rs b/ashen/src/asset/color_map.rs index 30795b3..aa7dde6 100644 --- a/ashen/src/asset/color_map.rs +++ b/ashen/src/asset/color_map.rs @@ -1,6 +1,6 @@ use std::ops::Deref; -use super::AssetParser; +use super::Parser; use crate::{error, utils::nom::*}; const COLORS_COUNT: usize = 256; @@ -35,7 +35,7 @@ impl Color { } } -impl AssetParser for Color { +impl Parser for Color { type Output = Self; type Context<'ctx> = (); @@ -55,7 +55,7 @@ pub struct ColorMap { pub shades: Box<[[Color; COLORS_COUNT]; SHADES_COUNT]>, } -impl AssetParser for ColorMap { +impl Parser for ColorMap { type Output = Self; type Context<'ctx> = (); @@ -155,7 +155,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, color_map) = ::parser(())(&COLOR_MAP_DATA)?; + let (_, color_map) = ColorMap::parser(())(&COLOR_MAP_DATA)?; output_file( parsed_file_path!("color-map/monsters.png"), diff --git a/ashen/src/asset/gamma_table.rs b/ashen/src/asset/gamma_table.rs index 96d82d5..7b22ab6 100644 --- a/ashen/src/asset/gamma_table.rs +++ b/ashen/src/asset/gamma_table.rs @@ -1,6 +1,6 @@ use std::mem; -use super::AssetParser; +use super::Parser; use crate::{error, utils::nom::*}; const ROWS_COUNT: usize = 256; @@ -12,7 +12,7 @@ pub struct GammaTable { pub lookups: Box<[[u8; ROWS_COUNT]; COLS_COUNT]>, } -impl AssetParser for GammaTable { +impl Parser for GammaTable { type Output = Self; type Context<'ctx> = (); @@ -61,7 +61,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, gamma_table) = ::parser(())(&GAMMA_TABLE_DATA)?; + let (_, gamma_table) = GammaTable::parser(())(&GAMMA_TABLE_DATA)?; let gamma_table = gamma_table .lookups diff --git a/ashen/src/asset/mod.rs b/ashen/src/asset/mod.rs index a3dede5..3925edf 100644 --- a/ashen/src/asset/mod.rs +++ b/ashen/src/asset/mod.rs @@ -2,7 +2,7 @@ pub mod color_map; pub mod gamma_table; pub mod model; pub mod pack_file; -mod pack_info; +pub mod pack_info; pub mod skybox; pub mod sound; pub mod string_table; @@ -10,7 +10,7 @@ pub mod texture; use crate::utils::nom::{Input, Result}; -pub trait AssetParser +pub trait Parser where Self: Sized, { diff --git a/ashen/src/asset/model/dat/frame.rs b/ashen/src/asset/model/dat/frame.rs index 8460051..bcc1e63 100644 --- a/ashen/src/asset/model/dat/frame.rs +++ b/ashen/src/asset/model/dat/frame.rs @@ -1,4 +1,4 @@ -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; // TODO(nenikitov): Should probably be a fancy utility class // With generics for data type and dimension @@ -9,7 +9,7 @@ pub struct Vec3 { pub z: f32, } -impl AssetParser for Vec3 { +impl Parser for Vec3 { type Output = Self; type Context<'ctx> = (); @@ -49,7 +49,7 @@ pub struct VertexTransform { origin: Vec3, } -impl AssetParser for ModelVertex { +impl Parser for ModelVertex { type Output = Self; type Context<'ctx> = VertexTransform; @@ -94,7 +94,7 @@ pub struct ModelSpecs { pub frame_size: u32, } -impl AssetParser for ModelFrame { +impl Parser for ModelFrame { type Output = Self; type Context<'ctx> = ModelSpecs; diff --git a/ashen/src/asset/model/dat/header.rs b/ashen/src/asset/model/dat/header.rs index 7f5f8dc..2395cc7 100644 --- a/ashen/src/asset/model/dat/header.rs +++ b/ashen/src/asset/model/dat/header.rs @@ -1,4 +1,4 @@ -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; pub struct ModelHeader { pub triangle_count: u32, @@ -15,7 +15,7 @@ pub struct ModelHeader { pub locator_nodes: [u8; 16], } -impl AssetParser for ModelHeader { +impl Parser for ModelHeader { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/model/dat/sequence.rs b/ashen/src/asset/model/dat/sequence.rs index f603e40..8b1f1e0 100644 --- a/ashen/src/asset/model/dat/sequence.rs +++ b/ashen/src/asset/model/dat/sequence.rs @@ -1,10 +1,10 @@ -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; pub struct ModelSequence { pub frames: Vec, } -impl AssetParser for ModelSequence { +impl Parser for ModelSequence { type Output = Self; // TODO(nenikitov): Maybe refactor it to not accept full input. diff --git a/ashen/src/asset/model/dat/triangle.rs b/ashen/src/asset/model/dat/triangle.rs index f6e636f..f708f0a 100644 --- a/ashen/src/asset/model/dat/triangle.rs +++ b/ashen/src/asset/model/dat/triangle.rs @@ -1,4 +1,4 @@ -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; pub struct ModelPoint { pub vertex_index: u16, @@ -11,7 +11,7 @@ pub struct TextureDimensions { pub height: u32, } -impl AssetParser for ModelPoint { +impl Parser for ModelPoint { type Output = Self; type Context<'ctx> = &'ctx TextureDimensions; @@ -36,7 +36,7 @@ pub struct ModelTriangle { pub points: [ModelPoint; 3], } -impl AssetParser for ModelTriangle { +impl Parser for ModelTriangle { type Output = Self; type Context<'ctx> = TextureDimensions; diff --git a/ashen/src/asset/model/mod.rs b/ashen/src/asset/model/mod.rs index b9dc44f..d63ed6b 100644 --- a/ashen/src/asset/model/mod.rs +++ b/ashen/src/asset/model/mod.rs @@ -9,7 +9,7 @@ use dat::{ use super::{ texture::{Texture, TextureSize}, - AssetParser, + Parser, }; use crate::utils::nom::*; @@ -20,7 +20,7 @@ pub struct Model { pub frames: Vec, } -impl AssetParser for Model { +impl Parser for Model { type Output = Self; type Context<'ctx> = (); @@ -94,9 +94,9 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, model) = ::parser(())(&MODEL_DATA)?; + let (_, model) = Model::parser(())(&MODEL_DATA)?; let palette = { - let (_, color_map) = ::parser(())(&COLOR_MAP_DATA)?; + let (_, color_map) = ColorMap::parser(())(&COLOR_MAP_DATA)?; color_map.shades[15] }; diff --git a/ashen/src/asset/pack_info.rs b/ashen/src/asset/pack_info.rs index 44b26b1..805fa81 100644 --- a/ashen/src/asset/pack_info.rs +++ b/ashen/src/asset/pack_info.rs @@ -1,6 +1,6 @@ use std::ops::Index; -use super::AssetParser; +use super::Parser; use crate::utils::nom::*; #[derive(Debug)] @@ -9,7 +9,7 @@ pub struct PackInfo { pub size: u32, } -impl AssetParser for PackInfo { +impl Parser for PackInfo { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/skybox.rs b/ashen/src/asset/skybox.rs index ee776c8..0e1f451 100644 --- a/ashen/src/asset/skybox.rs +++ b/ashen/src/asset/skybox.rs @@ -1,6 +1,6 @@ use super::{ texture::{Texture, TextureSize}, - AssetParser, + Parser, }; use crate::{asset::color_map::Color, utils::nom::*}; @@ -11,7 +11,7 @@ pub struct Skybox { pub texture: Texture, } -impl AssetParser for Skybox { +impl Parser for Skybox { type Output = Self; type Context<'ctx> = (); @@ -50,7 +50,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, skybox) = ::parser(())(&SKYBOX_DATA)?; + let (_, skybox) = Skybox::parser(())(&SKYBOX_DATA)?; output_file( parsed_file_path!("skyboxes/level-1.png"), diff --git a/ashen/src/asset/sound/dat/asset_header.rs b/ashen/src/asset/sound/dat/asset_header.rs index a5d03a4..9a1b1fe 100644 --- a/ashen/src/asset/sound/dat/asset_header.rs +++ b/ashen/src/asset/sound/dat/asset_header.rs @@ -1,5 +1,5 @@ use crate::{ - asset::{pack_info::PackInfo, AssetParser}, + asset::{pack_info::PackInfo, Parser}, utils::nom::*, }; @@ -14,7 +14,7 @@ impl SoundAssetHeader { const HEADER: &'static str = "TSND"; } -impl AssetParser for SoundAssetHeader { +impl Parser for SoundAssetHeader { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/dat/chunk_header.rs b/ashen/src/asset/sound/dat/chunk_header.rs index 3b7cbbf..c964d67 100644 --- a/ashen/src/asset/sound/dat/chunk_header.rs +++ b/ashen/src/asset/sound/dat/chunk_header.rs @@ -1,5 +1,5 @@ use crate::{ - asset::{pack_info::PackInfo, AssetParser}, + asset::{pack_info::PackInfo, Parser}, utils::nom::*, }; @@ -7,7 +7,7 @@ pub struct SoundChunkHeader { pub infos: Vec, } -impl AssetParser for SoundChunkHeader { +impl Parser for SoundChunkHeader { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/dat/pattern_effect.rs b/ashen/src/asset/sound/dat/pattern_effect.rs index 1d1cfe4..b036aa2 100644 --- a/ashen/src/asset/sound/dat/pattern_effect.rs +++ b/ashen/src/asset/sound/dat/pattern_effect.rs @@ -1,5 +1,5 @@ use super::{convert_volume, finetune::FineTune}; -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; #[derive(Debug, Clone, Copy)] pub enum Speed { @@ -127,7 +127,7 @@ impl PatternEffect { } } -impl AssetParser for Option { +impl Parser for Option { type Output = Self; type Context<'ctx> = bool; diff --git a/ashen/src/asset/sound/dat/pattern_event.rs b/ashen/src/asset/sound/dat/pattern_event.rs index 1edeb04..991622b 100644 --- a/ashen/src/asset/sound/dat/pattern_event.rs +++ b/ashen/src/asset/sound/dat/pattern_event.rs @@ -3,7 +3,7 @@ use std::rc::Rc; use bitflags::bitflags; use super::{convert_volume, finetune::FineTune, pattern_effect::PatternEffect, t_instrument::*}; -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; #[derive(Default, PartialEq, Clone, Copy, Debug)] pub enum PatternEventNote { @@ -12,7 +12,7 @@ pub enum PatternEventNote { On(FineTune), } -impl AssetParser for Option { +impl Parser for Option { type Output = Self; type Context<'ctx> = bool; @@ -48,7 +48,7 @@ bitflags! { } } -impl AssetParser for PatternEventFlags { +impl Parser for PatternEventFlags { type Output = Self; type Context<'ctx> = (); @@ -68,7 +68,7 @@ impl AssetParser for PatternEventFlags { } } -impl AssetParser for Option { +impl Parser for Option { type Output = Self; type Context<'ctx> = (bool, &'ctx [Rc]); @@ -102,7 +102,7 @@ impl Default for PatternEventVolume { } } -impl AssetParser for Option { +impl Parser for Option { type Output = Self; type Context<'ctx> = bool; @@ -149,7 +149,7 @@ impl PatternEvent { } } -impl AssetParser for PatternEvent { +impl Parser for PatternEvent { type Output = Self; type Context<'ctx> = &'ctx [Rc]; diff --git a/ashen/src/asset/sound/dat/t_effect.rs b/ashen/src/asset/sound/dat/t_effect.rs index 5ccdf45..df24438 100644 --- a/ashen/src/asset/sound/dat/t_effect.rs +++ b/ashen/src/asset/sound/dat/t_effect.rs @@ -5,7 +5,7 @@ use super::{ uncompress, }; use crate::{ - asset::{sound::sample::AudioBuffer, AssetParser}, + asset::{sound::sample::AudioBuffer, Parser}, utils::nom::*, }; @@ -20,7 +20,7 @@ impl TEffect { } } -impl AssetParser for TEffect { +impl Parser for TEffect { type Output = Self; type Context<'ctx> = (); @@ -50,7 +50,7 @@ struct TEffectPointers { sample_data: u32, } -impl AssetParser for TEffectPointers { +impl Parser for TEffectPointers { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/dat/t_instrument.rs b/ashen/src/asset/sound/dat/t_instrument.rs index f37cb01..192419c 100644 --- a/ashen/src/asset/sound/dat/t_instrument.rs +++ b/ashen/src/asset/sound/dat/t_instrument.rs @@ -4,7 +4,7 @@ use bitflags::bitflags; use super::{convert_volume, finetune::FineTune}; use crate::{ - asset::{sound::sample::AudioBuffer, AssetParser}, + asset::{sound::sample::AudioBuffer, Parser}, utils::{iterator::CollectArray, nom::*}, }; @@ -16,7 +16,7 @@ bitflags! { } } -impl AssetParser for TInstrumentFlags { +impl Parser for TInstrumentFlags { type Output = Self; type Context<'ctx> = (); @@ -68,7 +68,7 @@ impl TInstrumentVolumeEnvelope { } } -impl AssetParser for Option { +impl Parser for Option { type Output = Self; type Context<'ctx> = bool; @@ -129,7 +129,7 @@ impl TInstrument { const ENVELOPE_SIZE: usize = 325; } -impl AssetParser for TInstrument { +impl Parser for TInstrument { type Output = Self; type Context<'ctx> = &'ctx [Rc]; @@ -214,7 +214,7 @@ pub struct TSample { pub buffer: AudioBuffer, } -impl AssetParser for TSample { +impl Parser for TSample { type Output = Self; type Context<'ctx> = &'ctx [i16]; diff --git a/ashen/src/asset/sound/dat/t_song.rs b/ashen/src/asset/sound/dat/t_song.rs index aaac9e0..a055294 100644 --- a/ashen/src/asset/sound/dat/t_song.rs +++ b/ashen/src/asset/sound/dat/t_song.rs @@ -3,7 +3,7 @@ use std::rc::Rc; use itertools::Itertools; use super::{pattern_event::*, t_instrument::*, uncompress}; -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; pub type PatternRow = Vec; pub type Pattern = Vec; @@ -90,7 +90,7 @@ impl std::fmt::Debug for TSong { } } -impl AssetParser for TSong { +impl Parser for TSong { type Output = Self; type Context<'ctx> = (); @@ -185,7 +185,7 @@ struct TSongHeader { bpm: u8, } -impl AssetParser for TSongHeader { +impl Parser for TSongHeader { type Output = Self; type Context<'ctx> = (); @@ -229,7 +229,7 @@ struct TSongPointers { sample_data: u32, } -impl AssetParser for TSongPointers { +impl Parser for TSongPointers { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/mod.rs b/ashen/src/asset/sound/mod.rs index f0bc1d9..3202cf8 100644 --- a/ashen/src/asset/sound/mod.rs +++ b/ashen/src/asset/sound/mod.rs @@ -2,7 +2,7 @@ mod dat; pub(crate) mod sample; use self::{dat::mixer::TSongMixer, sample::AudioBuffer}; -use super::AssetParser; +use super::Parser; use crate::{ asset::sound::dat::{ asset_header::SoundAssetHeader, chunk_header::SoundChunkHeader, t_effect::TEffect, @@ -32,7 +32,7 @@ impl SoundCollection { pub const CHANNEL_COUNT: usize = 1; } -impl AssetParser for SoundCollection { +impl Parser for SoundCollection { type Output = Vec; type Context<'ctx> = (); @@ -78,7 +78,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, sounds) = ::parser(())(&SOUND_DATA)?; + let (_, sounds) = SoundCollection::parser(())(&SOUND_DATA)?; let output_dir = PathBuf::from(parsed_file_path!("sounds/songs/")); diff --git a/ashen/src/asset/string_table.rs b/ashen/src/asset/string_table.rs index e4f1d6d..b5f3a03 100644 --- a/ashen/src/asset/string_table.rs +++ b/ashen/src/asset/string_table.rs @@ -1,4 +1,4 @@ -use super::AssetParser; +use super::Parser; use crate::utils::nom::*; pub struct StringTable { @@ -14,7 +14,7 @@ fn utf_16_string(input: &[u8]) -> Result { }) } -impl AssetParser for StringTable { +impl Parser for StringTable { type Output = Self; type Context<'ctx> = (); @@ -42,7 +42,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, string_table) = ::parser(())(&STRING_TABLE_DATA)?; + let (_, string_table) = StringTable::parser(())(&STRING_TABLE_DATA)?; output_file( parsed_file_path!("strings/english-uk.txt"), diff --git a/ashen/src/asset/texture/dat/offset.rs b/ashen/src/asset/texture/dat/offset.rs index fc1075c..fdd8806 100644 --- a/ashen/src/asset/texture/dat/offset.rs +++ b/ashen/src/asset/texture/dat/offset.rs @@ -1,4 +1,4 @@ -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; pub struct TextureOffset { pub width: u16, @@ -10,7 +10,7 @@ pub struct TextureOffset { pub next_animation_texture_id: u32, } -impl AssetParser for TextureOffset { +impl Parser for TextureOffset { type Context<'ctx> = (); type Output = Self; diff --git a/ashen/src/asset/texture/dat/texture.rs b/ashen/src/asset/texture/dat/texture.rs index 62479fc..bc12452 100644 --- a/ashen/src/asset/texture/dat/texture.rs +++ b/ashen/src/asset/texture/dat/texture.rs @@ -4,7 +4,7 @@ use super::size::TextureSize; use crate::{ asset::{ color_map::{Color, PaletteTexture}, - AssetParser, + Parser, }, utils::nom::*, }; @@ -15,7 +15,7 @@ pub struct Texture { pub colors: Vec>, } -impl AssetParser for Texture { +impl Parser for Texture { type Output = Self; type Context<'ctx> = TextureSize; @@ -51,7 +51,7 @@ pub struct MippedTexture { pub mips: [Texture; 4], } -impl AssetParser for MippedTexture { +impl Parser for MippedTexture { type Output = Self; type Context<'ctx> = TextureSize; diff --git a/ashen/src/asset/texture/mod.rs b/ashen/src/asset/texture/mod.rs index cd6a83a..d669250 100644 --- a/ashen/src/asset/texture/mod.rs +++ b/ashen/src/asset/texture/mod.rs @@ -3,7 +3,7 @@ mod dat; use dat::{offset::TextureOffset, texture::MippedTexture}; pub use dat::{size::TextureSize, texture::Texture}; -use super::AssetParser; +use super::Parser; use crate::utils::{compression::decompress, nom::*}; pub enum TextureMipKind { @@ -18,7 +18,7 @@ pub enum TextureAnimationKind { pub struct TextureOffsetCollection; -impl AssetParser for TextureOffsetCollection { +impl Parser for TextureOffsetCollection { type Output = Vec; type Context<'ctx> = (); @@ -34,7 +34,7 @@ impl AssetParser for TextureOffsetCollection { pub struct MippedTextureCollection; -impl AssetParser for MippedTextureCollection { +impl Parser for MippedTextureCollection { type Output = Vec; type Context<'ctx> = &'ctx [TextureOffset]; @@ -99,12 +99,12 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, color_map) = ::parser(())(&COLOR_MAP_DATA)?; + let (_, color_map) = ColorMap::parser(())(&COLOR_MAP_DATA)?; let color_map = &color_map.shades[15]; let (_, offsets) = - ::parser(())(&TEXTURE_INFO_DATA)?; + TextureOffsetCollection::parser(())(&TEXTURE_INFO_DATA)?; let (_, textures) = - ::parser(&offsets)(&TEXTURE_DATA)?; + MippedTextureCollection::parser(&offsets)(&TEXTURE_DATA)?; let output_dir = PathBuf::from(parsed_file_path!("textures/"));