ResourceIndex

Struct ResourceIndex 

Source
pub struct ResourceIndex {
    pub bookmarks: Vec<AssetBookmark>,
}
Expand description

A struct representing the elements contained within a resource index file

Fields§

§bookmarks: Vec<AssetBookmark>

Implementations§

Source§

impl ResourceIndex

Source

pub fn read<T: Read>(reader: T) -> Result<Self>

Examples found in repository?
examples/list_texts.rs (line 7)
5fn main() -> Result<()> {
6    let f = File::open("examples/regnum/data5.idx")?;
7    let index = ResourceIndex::read(f).unwrap();
8
9    let texts = index.filter_by_type(AssetType::Text);
10
11    for text in &texts {
12        println!(
13            "Resource #{}: {}",
14            text.resource_id.unwrap_or(0),
15            text.name.as_deref().unwrap_or("(unnamed)".into())
16        );
17    }
18
19    Ok(())
20}
More examples
Hide additional examples
examples/list_music.rs (line 7)
5fn main() -> Result<()> {
6    let f = File::open("examples/regnum/data2.idx")?;
7    let index = ResourceIndex::read(f).unwrap();
8
9    let sounds = index.filter_by_type(AssetType::Music);
10
11    for sound in &sounds {
12        println!(
13            "Resource #{}: {}",
14            sound.resource_id.unwrap_or(0),
15            sound.name.as_deref().unwrap_or("(unnamed)".into())
16        );
17    }
18
19    Ok(())
20}
examples/list_sounds.rs (line 7)
5fn main() -> Result<()> {
6    let f = File::open("examples/regnum/data2.idx")?;
7    let index = ResourceIndex::read(f).unwrap();
8
9    let sounds = index.filter_by_type(AssetType::Sound);
10
11    for sound in &sounds {
12        println!(
13            "Resource #{}: {}",
14            sound.resource_id.unwrap_or(0),
15            sound.name.as_deref().unwrap_or("(unnamed)".into())
16        );
17    }
18
19    Ok(())
20}
examples/list_images.rs (line 7)
5fn main() -> Result<()> {
6    let f = File::open("examples/regnum/data5.idx")?;
7    let index = ResourceIndex::read(f).unwrap();
8
9    let images = index.filter_by_type(AssetType::Image);
10
11    for image in &images {
12        println!(
13            "Resource #{}: {}",
14            image.resource_id.unwrap_or(0),
15            image.name.as_deref().unwrap_or("(unnamed)".into()),
16        );
17    }
18
19    Ok(())
20}
examples/list_textures.rs (line 7)
5fn main() -> Result<()> {
6    let f = File::open("examples/regnum/data6.idx")?;
7    let index = ResourceIndex::read(f).unwrap();
8
9    let textures = index.filter_by_type(AssetType::Texture);
10
11    for texture in &textures {
12        println!(
13            "Resource #{}: {}",
14            texture.resource_id.unwrap_or(0),
15            texture.name.as_deref().unwrap_or("(unnamed)".into()),
16        );
17    }
18
19    Ok(())
20}
examples/list_characters.rs (line 7)
5fn main() -> Result<()> {
6    let f = File::open("examples/regnum/live/characters.idx")?;
7    let index = ResourceIndex::read(f).unwrap();
8
9    println!("Found characters: {}", index.bookmarks.len());
10
11    for chara in index.bookmarks.iter() {
12        println!(
13            "Character #{}: {}",
14            chara.resource_id.unwrap_or(0),
15            chara.name.as_deref().unwrap_or("(unnamed)".into())
16        );
17    }
18
19    Ok(())
20}
Source

pub fn get_by_resource_id(&self, resource_id: u32) -> Option<AssetBookmark>

Retrieves an asset bookmark by its resource id

Examples found in repository?
examples/export_image.rs (line 10)
6fn main() -> Result<()> {
7    let f = File::open("examples/regnum/data5.idx")?;
8    let index = ResourceIndex::read(f).unwrap();
9
10    let image = index.get_by_resource_id(75879).unwrap();
11
12    let f = File::open("examples/regnum/data5.sdb")?;
13    let asset = AssetData::read(&f, &image).unwrap();
14
15    match asset.content {
16        AssetContent::Image { bytes } => {
17            let filename = "out.jpeg";
18            println!("writing file to {}", filename);
19            let mut output = File::create(filename)?;
20            output.write_all(bytes.as_ref())?;
21            output.flush()?;
22        }
23        _ => {
24            println!("couuld not parse image asset")
25        }
26    }
27
28    Ok(())
29}
More examples
Hide additional examples
examples/export_music.rs (line 10)
6fn main() -> Result<()> {
7    let f = File::open("examples/regnum/data2.idx")?;
8    let index = ResourceIndex::read(f).unwrap();
9
10    let sound = index.get_by_resource_id(56934).unwrap();
11
12    let f = File::open("examples/regnum/data2.sdb")?;
13    let asset = AssetData::read(&f, &sound).unwrap();
14
15    match asset.content {
16        AssetContent::Sound {
17            filename,
18            bytes,
19            size,
20        } => {
21            println!("writing {} bytes file to {}", size, filename);
22            let mut output = File::create(filename)?;
23            output.write_all(bytes.as_ref())?;
24            output.flush()?;
25        }
26        _ => {
27            println!("couuld not parse music asset")
28        }
29    }
30
31    Ok(())
32}
examples/export_sound.rs (line 10)
6fn main() -> Result<()> {
7    let f = File::open("examples/regnum/data2.idx")?;
8    let index = ResourceIndex::read(f).unwrap();
9
10    let sound = index.get_by_resource_id(50677).unwrap();
11
12    let f = File::open("examples/regnum/data2.sdb")?;
13    let asset = AssetData::read(&f, &sound).unwrap();
14
15    match asset.content {
16        AssetContent::Sound {
17            filename,
18            bytes,
19            size,
20        } => {
21            println!("writing {} bytes file to {}", size, filename);
22            let mut output = File::create(filename)?;
23            output.write_all(bytes.as_ref())?;
24            output.flush()?;
25        }
26        _ => {
27            println!("couuld not parse sound asset")
28        }
29    }
30
31    Ok(())
32}
examples/export_texture.rs (line 10)
6fn main() -> Result<()> {
7    let f = File::open("examples/regnum/data6.idx")?;
8    let index = ResourceIndex::read(f).unwrap();
9
10    let texture = index.get_by_resource_id(85953).unwrap();
11
12    let f = File::open("examples/regnum/data6.sdb")?;
13    let asset = AssetData::read(&f, &texture).unwrap();
14
15    match asset.content {
16        AssetContent::Texture { width, height, dds } => {
17            println!(
18                "writing texture '{}' ({}x{}) to out.dds",
19                asset.asset_name, width, height
20            );
21
22            let mut file = File::create("out.dds")?;
23            dds.write(&mut file)?;
24            file.flush()?;
25        }
26
27        _ => {
28            println!("couuld not parse texture asset")
29        }
30    }
31
32    Ok(())
33}
examples/show_text.rs (line 9)
5fn main() -> Result<()> {
6    let f = File::open("examples/regnum/data5.idx")?;
7    let index = ResourceIndex::read(f).unwrap();
8
9    let text = index.get_by_resource_id(59847).unwrap();
10
11    let f = File::open("examples/regnum/data5.sdb")?;
12    let asset = AssetData::read(&f, &text).unwrap();
13
14    println!(
15        "showing content in {} [{}]",
16        asset.asset_name, asset.resource_id
17    );
18
19    match asset.content {
20        AssetContent::Text { contents } => {
21            for content in contents {
22                println!("refs: {:?}", content.refs);
23                for node in &content.nodes {
24                    println!("TEXT: {:?}", node);
25                }
26            }
27        }
28        _ => {
29            println!("this content is not supported")
30        }
31    }
32
33    Ok(())
34}
Source

pub fn filter_by_type(&self, asset_type: AssetType) -> Vec<AssetBookmark>

Retrieves a list of bookmarks by their asset type

Examples found in repository?
examples/list_texts.rs (line 9)
5fn main() -> Result<()> {
6    let f = File::open("examples/regnum/data5.idx")?;
7    let index = ResourceIndex::read(f).unwrap();
8
9    let texts = index.filter_by_type(AssetType::Text);
10
11    for text in &texts {
12        println!(
13            "Resource #{}: {}",
14            text.resource_id.unwrap_or(0),
15            text.name.as_deref().unwrap_or("(unnamed)".into())
16        );
17    }
18
19    Ok(())
20}
More examples
Hide additional examples
examples/list_music.rs (line 9)
5fn main() -> Result<()> {
6    let f = File::open("examples/regnum/data2.idx")?;
7    let index = ResourceIndex::read(f).unwrap();
8
9    let sounds = index.filter_by_type(AssetType::Music);
10
11    for sound in &sounds {
12        println!(
13            "Resource #{}: {}",
14            sound.resource_id.unwrap_or(0),
15            sound.name.as_deref().unwrap_or("(unnamed)".into())
16        );
17    }
18
19    Ok(())
20}
examples/list_sounds.rs (line 9)
5fn main() -> Result<()> {
6    let f = File::open("examples/regnum/data2.idx")?;
7    let index = ResourceIndex::read(f).unwrap();
8
9    let sounds = index.filter_by_type(AssetType::Sound);
10
11    for sound in &sounds {
12        println!(
13            "Resource #{}: {}",
14            sound.resource_id.unwrap_or(0),
15            sound.name.as_deref().unwrap_or("(unnamed)".into())
16        );
17    }
18
19    Ok(())
20}
examples/list_images.rs (line 9)
5fn main() -> Result<()> {
6    let f = File::open("examples/regnum/data5.idx")?;
7    let index = ResourceIndex::read(f).unwrap();
8
9    let images = index.filter_by_type(AssetType::Image);
10
11    for image in &images {
12        println!(
13            "Resource #{}: {}",
14            image.resource_id.unwrap_or(0),
15            image.name.as_deref().unwrap_or("(unnamed)".into()),
16        );
17    }
18
19    Ok(())
20}
examples/list_textures.rs (line 9)
5fn main() -> Result<()> {
6    let f = File::open("examples/regnum/data6.idx")?;
7    let index = ResourceIndex::read(f).unwrap();
8
9    let textures = index.filter_by_type(AssetType::Texture);
10
11    for texture in &textures {
12        println!(
13            "Resource #{}: {}",
14            texture.resource_id.unwrap_or(0),
15            texture.name.as_deref().unwrap_or("(unnamed)".into()),
16        );
17    }
18
19    Ok(())
20}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.