add EntityList that will decode types and entities and manage them
This commit is contained in:
parent
9b151e509b
commit
28c5bf6989
5 changed files with 52 additions and 47 deletions
|
|
@ -1,5 +1,6 @@
|
|||
mod decoder;
|
||||
mod entity;
|
||||
mod entitylist;
|
||||
mod esh;
|
||||
mod fstring;
|
||||
mod raw;
|
||||
|
|
|
|||
|
|
@ -8,9 +8,8 @@ pub trait Decoder: Sized {
|
|||
fn get_enc_size(&self) -> usize;
|
||||
}
|
||||
|
||||
pub trait DecoderOpt: Sized {
|
||||
type Opt<'o>;
|
||||
fn decode(raw: &Raw, offset: usize, size: usize, opt: Option<Self::Opt<'_>>) -> Result<Self>;
|
||||
pub trait DecoderOpt<Opt>: Sized {
|
||||
fn decode(raw: &Raw, offset: usize, size: usize, opt: Opt) -> Result<Self>;
|
||||
fn encode(&self) -> Result<Raw>;
|
||||
fn get_enc_size(&self) -> usize;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,56 +1,23 @@
|
|||
use super::raw::Raw;
|
||||
use super::tag::Tag;
|
||||
use super::esh::ESH;
|
||||
use super::decoder::DecoderOpt;
|
||||
use super::entitylist::{EntityEncoding, EntityList};
|
||||
use super::esh::ESH;
|
||||
use super::fstring::FString;
|
||||
use super::raw::Raw;
|
||||
use super::stream::{ReadStream, WriteStream};
|
||||
use super::tag::Tag;
|
||||
use anyhow::anyhow;
|
||||
use anyhow::Result;
|
||||
|
||||
pub enum EntityEncoding {
|
||||
File,
|
||||
World
|
||||
}
|
||||
|
||||
pub struct EntityList {}
|
||||
|
||||
impl EntityList {
|
||||
fn get_entity_encoding(&self) -> EntityEncoding {
|
||||
todo!();
|
||||
}
|
||||
|
||||
fn get_entity_tag(&self) -> &Tag {
|
||||
todo!();
|
||||
}
|
||||
|
||||
fn add_new_type(&mut self, name: FString) -> usize {
|
||||
todo!();
|
||||
}
|
||||
|
||||
fn add_or_get_type(&mut self, name: FString) -> usize {
|
||||
todo!();
|
||||
}
|
||||
|
||||
fn get_type_name(&self, type_idx: usize) -> &FString {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Entity {
|
||||
pub flags: u32,
|
||||
pub type_idx: usize,
|
||||
pub esh: ESH,
|
||||
enc_size: usize
|
||||
enc_size: usize,
|
||||
}
|
||||
|
||||
impl DecoderOpt for Entity {
|
||||
type Opt<'o> = &'o EntityList;
|
||||
fn decode<'o>(raw: &Raw, offset: usize, _: usize, opt: Option<Self::Opt<'o>>) -> Result<Self> {
|
||||
let rd = ReadStream::new(raw, offset);
|
||||
let opt = match opt {
|
||||
Some(opt) => opt,
|
||||
None => return Err(anyhow!("no EntityOpt was provided!"))
|
||||
};
|
||||
impl DecoderOpt<&EntityList> for Entity {
|
||||
fn decode(raw: &Raw, offset: usize, _: usize, opt: &EntityList) -> Result<Self> {
|
||||
let mut rd = ReadStream::new(raw, offset);
|
||||
|
||||
todo!();
|
||||
}
|
||||
|
|
|
|||
38
src/fot/entitylist.rs
Normal file
38
src/fot/entitylist.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use super::decoder::DecoderOpt;
|
||||
use super::entity::Entity;
|
||||
use super::esh::ESH;
|
||||
use super::fstring::FString;
|
||||
use super::raw::Raw;
|
||||
use super::stream::{ReadStream, WriteStream};
|
||||
use super::tag::Tag;
|
||||
use anyhow::anyhow;
|
||||
use anyhow::Result;
|
||||
|
||||
pub enum EntityEncoding {
|
||||
File,
|
||||
World,
|
||||
}
|
||||
|
||||
pub struct EntityList {}
|
||||
|
||||
impl EntityList {
|
||||
fn get_entity_encoding(&self) -> EntityEncoding {
|
||||
todo!();
|
||||
}
|
||||
|
||||
fn get_entity_tag(&self) -> &Tag {
|
||||
todo!();
|
||||
}
|
||||
|
||||
fn add_new_type(&mut self, name: FString) -> usize {
|
||||
todo!();
|
||||
}
|
||||
|
||||
fn add_or_get_type(&mut self, name: FString) -> usize {
|
||||
todo!();
|
||||
}
|
||||
|
||||
fn get_type_name(&self, type_idx: usize) -> &FString {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
|
@ -46,8 +46,8 @@ impl<'a> ReadStream<'a> {
|
|||
|
||||
// read_opt - decode with optional paramters. required for complex structure
|
||||
// with different origins (save / entfile) like entities
|
||||
pub fn read_opt<'o, T: DecoderOpt>(&mut self, size: usize, opt: T::Opt<'o>) -> Result<T> {
|
||||
let val = T::decode(&self.raw, self.offset(), size, Some(opt))?;
|
||||
pub fn read_opt<T: DecoderOpt<Opt>, Opt>(&mut self, size: usize, opt: Opt) -> Result<T> {
|
||||
let val = T::decode(&self.raw, self.offset(), size, opt)?;
|
||||
self.skip(val.get_enc_size());
|
||||
Ok(val)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue