Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ name = "projtest"

[[example]]
name = "projload"

[[example]]
name = "animtest"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ Rust library and tool for opening various graphics-related Nintendo DS files
## Credits
* Contributors: me! (patataofcourse)
* Documentation on file formats:
- [This](https://www.romhacking.net/documents/%5b469%5dnds_formats.htm) document in romhacking.net
- [This](https://www.romhacking.net/documents/469/) document in romhacking.net
- [Tinke](https://www.github.com/pleonex/tinke) source code
- [NitroPaint](https://github.com/Garhoogin/NitroPaint) source code
- [gbatek](https://problemkaputt.de/gbatek.htm)
* ThePurpleAnon for the very cool name idea
14 changes: 14 additions & 0 deletions examples/animtest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::{fs::File, io::Read};

use nuclear::{img::ncer::NCER, ndsfile::NDSFileType};

pub fn main() -> nuclear::Result<()> {
let mut ncer = <NCER as NDSFileType>::from_file(
"test_files/rocker.NCER",
&mut File::open("test_files/rocker.NCER")?,
)?;

println!("{:?}", ncer);

Ok(())
}
15 changes: 5 additions & 10 deletions examples/projtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,23 @@ fn main() -> nuclear::error::Result<()> {
)?;

let mut f = File::open("test_files/rocker_bg.NCLR")?;
let nds = nuclear::ndsfile::NDSFile::from_file("rocker_bg.NCLR", &mut f)?;
let clr = nuclear::img::NCLR::from_ndsfile(&nds)?;
let clr = nuclear::img::NCLR::from_file("rocker_bg.NCLR", &mut f)?;

let mut f = File::open("test_files/rocker_bg.NCGR")?;
let nds = nuclear::ndsfile::NDSFile::from_file("rocker_bg.NCGR", &mut f)?;
let cgr = nuclear::img::NCGR::from_ndsfile(&nds)?;
let cgr = nuclear::img::NCGR::from_file("rocker_bg.NCGR", &mut f)?;

let mut f = File::open("test_files/rocker_bg.NSCR")?;
let nds = nuclear::ndsfile::NDSFile::from_file("rocker_bg.NSCR", &mut f)?;
let scr = nuclear::img::NSCR::from_ndsfile(&nds)?;
let scr = nuclear::img::NSCR::from_file("rocker_bg.NSCR", &mut f)?;

proj.insert_nclr("rocker_bg", &clr)?;
proj.insert_ncgr("rocker_bg", &cgr)?;
proj.insert_nscr("rocker_bg", &scr)?;

let mut f = File::open("test_files/rocker.NCLR")?;
let nds = nuclear::ndsfile::NDSFile::from_file("rocker.NCLR", &mut f)?;
let clr = nuclear::img::NCLR::from_ndsfile(&nds)?;
let clr = nuclear::img::NCLR::from_file("rocker.NCLR", &mut f)?;

let mut f = File::open("test_files/rocker.NCBR")?;
let nds = nuclear::ndsfile::NDSFile::from_file("rocker.NCBR", &mut f)?;
let cgr = nuclear::img::NCGR::from_ndsfile(&nds)?;
let cgr = nuclear::img::NCGR::from_file("rocker.NCBR", &mut f)?;

proj.insert_nclr("rocker", &clr)?;
proj.insert_ncgr("rocker", &cgr)?;
Expand Down
16 changes: 6 additions & 10 deletions examples/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,36 @@ use bytestream::ByteOrder;
use nuclear::ndsfile::NDSFileType;
use std::fs::File;

const FOLDER_NAME: &str = "ver2";
const FOLDER_NAME: &str = ".";
const NAME: &str = "rocker";
const TILES_EXTENSION: &str = "NCBR";
const NSCR: bool = false;

fn main() -> nuclear::error::Result<()> {
// Open NCLR file
let mut f = File::open(format!("test_files/{}/{}.NCLR", FOLDER_NAME, NAME))?;
let nds = nuclear::ndsfile::NDSFile::from_file(&format!("{}.NCLR", NAME), &mut f)?;

// Export NCLR to palette set
let clr = nuclear::img::nclr::NCLR::from_ndsfile(&nds)?;
let clr = nuclear::img::nclr::NCLR::from_file(&format!("{}.NCLR", NAME), &mut f)?;
nuclear::img::export::export_palettes(
&clr,
format!("test_files/out/{}/{}_pal", FOLDER_NAME, NAME).into(),
)?;

// Re-export NCLR file
let nds = clr.to_ndsfile(format!("{}.NCLR", NAME), ByteOrder::LittleEndian)?;
let mut f_w = File::create(format!("test_files/out/{}/{}.NCLR", FOLDER_NAME, NAME))?;
nds.to_file(&mut f_w)?;
clr.to_file(&mut f_w, format!("{}.NCLR", NAME), ByteOrder::LittleEndian)?;

// Open NCGR/NCBR file
let mut f = File::open(format!(
"test_files/{}/{}.{}",
FOLDER_NAME, NAME, TILES_EXTENSION
))?;
let nds =
nuclear::ndsfile::NDSFile::from_file(&format!("{}.{}", NAME, TILES_EXTENSION), &mut f)?;

// Export NCGR to tilesheet
let f_w = &mut File::create(format!("test_files/out/{}/{}.tiles.png", FOLDER_NAME, NAME))?;
let cgr = nuclear::img::ncgr::NCGR::from_ndsfile(&nds)?;
let cgr =
nuclear::img::ncgr::NCGR::from_file(&format!("{}.{}", NAME, TILES_EXTENSION), &mut f)?;
nuclear::img::export::export_tilesheet(f_w, &clr.palettes[&0], &cgr, 32, false)?;

// Re-export NCGR file
Expand All @@ -51,10 +48,9 @@ fn main() -> nuclear::error::Result<()> {
if NSCR {
// Open NSCR file
let mut f = File::open(format!("test_files/{}/{}.NSCR", FOLDER_NAME, NAME))?;
let nds = nuclear::ndsfile::NDSFile::from_file(&format!("{}.NSCR", NAME), &mut f)?;
let scr = nuclear::img::nscr::NSCR::from_file(&format!("{}.NSCR", NAME), &mut f)?;
// Export NSCR to image
let f_w = &mut File::create(format!("test_files/out/{}/{}.png", FOLDER_NAME, NAME))?;
let scr = nuclear::img::nscr::NSCR::from_ndsfile(&nds)?;
nuclear::img::export::export_tilemap(f_w, &clr, &cgr, &scr)?;
// Re-export NSCR file
let nds = scr.to_ndsfile(format!("{}.NSCR", NAME), ByteOrder::LittleEndian)?;
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ pub enum Error {
#[error("Error when reading {0}: {1}")]
FileFormatWrong(PathBuf, String),

/// Unimplemented feature
#[error("Unimplemented feature: {0}")]
UnimplementedFeature(String),

//
// Wrappers
//
Expand Down
4 changes: 2 additions & 2 deletions src/img/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pub mod ncgr;
pub mod nclr;
pub mod nscr;

//pub mod nanr;
//pub mod ncer;
pub mod nanr;
pub mod ncer;

/// Only kept for the examples, renders different formats to .png
pub mod export;
Expand Down
Loading