-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod offset; | ||
pub mod size; | ||
pub mod texture; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use crate::{ | ||
asset::{extension::*, AssetParser}, | ||
utils::nom::*, | ||
}; | ||
|
||
pub struct TextureOffset { | ||
pub width: u16, | ||
pub height: u16, | ||
pub offset: u32, | ||
pub size_compressed: u32, | ||
pub size_decompressed: u32, | ||
pub animation_frames: u32, | ||
pub next_animation_texture_id: u32, | ||
} | ||
|
||
impl AssetParser<Wildcard> for TextureOffset { | ||
type Context<'ctx> = (); | ||
|
||
type Output = Self; | ||
|
||
fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result<Self::Output> { | ||
move |input| { | ||
let (input, width) = number::le_u16(input)?; | ||
let (input, height) = number::le_u16(input)?; | ||
let (input, offset) = number::le_u32(input)?; | ||
let (input, size_compressed) = number::le_u32(input)?; | ||
let (input, size_decompressed) = number::le_u32(input)?; | ||
let (input, animation_frames) = number::le_u32(input)?; | ||
let (input, next_animation_texture_id) = number::le_u32(input)?; | ||
|
||
Ok(( | ||
input, | ||
Self { | ||
width, | ||
height, | ||
offset, | ||
size_compressed, | ||
size_decompressed, | ||
animation_frames, | ||
next_animation_texture_id, | ||
}, | ||
)) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::ops::Div; | ||
|
||
pub struct TextureSize { | ||
pub width: u16, | ||
pub height: u16, | ||
} | ||
|
||
impl Div<u16> for TextureSize { | ||
type Output = Self; | ||
|
||
fn div(self, rhs: u16) -> Self::Output { | ||
&self / rhs | ||
} | ||
} | ||
|
||
impl Div<u16> for &TextureSize { | ||
type Output = TextureSize; | ||
|
||
fn div(self, rhs: u16) -> Self::Output { | ||
TextureSize { | ||
width: self.width / rhs, | ||
height: self.height / rhs, | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use super::size::TextureSize; | ||
use crate::{ | ||
asset::{extension::*, AssetParser}, | ||
utils::nom::*, | ||
}; | ||
use itertools::Itertools; | ||
|
||
pub struct Texture { | ||
pub colors: Vec<Vec<u8>>, | ||
} | ||
|
||
impl AssetParser<Wildcard> for Texture { | ||
type Output = Self; | ||
|
||
type Context<'ctx> = &'ctx TextureSize; | ||
|
||
fn parser(size: Self::Context<'_>) -> impl Fn(Input) -> Result<Self::Output> { | ||
let width = size.width as usize; | ||
let height = size.height as usize; | ||
|
||
move |input| { | ||
let (input, colors) = multi::count!(number::le_u8, width * height)(input)?; | ||
|
||
let colors = colors | ||
.into_iter() | ||
.chunks(width) | ||
.into_iter() | ||
.map(Iterator::collect) | ||
.collect(); | ||
|
||
Ok((input, Self { colors })) | ||
} | ||
} | ||
} | ||
|
||
pub struct MippedTexture { | ||
pub mips: [Texture; 4], | ||
} | ||
|
||
impl AssetParser<Wildcard> for MippedTexture { | ||
type Output = Self; | ||
|
||
type Context<'ctx> = TextureSize; | ||
|
||
fn parser(size: Self::Context<'_>) -> impl Fn(Input) -> Result<Self::Output> { | ||
move |input| { | ||
let (input, mip_1) = Texture::parser(&size)(&input)?; | ||
Check warning on line 47 in engine/src/asset/texture/dat/texture.rs GitHub Actions / clippythis expression creates a reference which is immediately dereferenced by the compiler
|
||
let (input, mip_2) = Texture::parser(&(&size / 2))(&input)?; | ||
Check warning on line 48 in engine/src/asset/texture/dat/texture.rs GitHub Actions / clippythis expression creates a reference which is immediately dereferenced by the compiler
|
||
let (input, mip_3) = Texture::parser(&(&size / 4))(&input)?; | ||
Check warning on line 49 in engine/src/asset/texture/dat/texture.rs GitHub Actions / clippythis expression creates a reference which is immediately dereferenced by the compiler
|
||
let (input, mip_4) = Texture::parser(&(&size / 8))(&input)?; | ||
Check warning on line 50 in engine/src/asset/texture/dat/texture.rs GitHub Actions / clippythis expression creates a reference which is immediately dereferenced by the compiler
|
||
|
||
Ok(( | ||
&[], | ||
Self { | ||
mips: [mip_1, mip_2, mip_3, mip_4], | ||
}, | ||
)) | ||
} | ||
} | ||
} |