Skip to content

Commit

Permalink
feat(writer): Create a seperate writer
Browse files Browse the repository at this point in the history
Signed-off-by: dark0dave <dark0dave@mykolab.com>
  • Loading branch information
dark0dave committed Nov 2, 2024
1 parent 22e6b64 commit 09cc477
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 140 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
default_install_hook_types: [pre-commit, commit-msg]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
exclude: (?x)^([models/fixtures|docs])
Expand Down Expand Up @@ -29,7 +29,7 @@ repos:
stages: [pre-commit]

- repo: https://github.com/commitizen-tools/commitizen
rev: v3.27.0
rev: v3.30.0
hooks:
- id: commitizen
stages: [commit-msg]
Expand Down
83 changes: 79 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ edition = "2021"
[workspace]

[dependencies]
binrw = "0.14.0"
clap = { version = "4.0", features = ["derive"] }
binrw = "^0.14.1"
clap = { version = "^4.0", features = ["derive", "env"] }
env_logger = "^0.11.1"
erased-serde = "0.4"
log = "^0.4.22"
models = { path = "./models" }
serde_json = "1.0"
serde_json = "^1.0"
14 changes: 7 additions & 7 deletions models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
binrw = "0.14.0"
erased-serde = "0.4"
flate2 = { version = "1.0.17" }
serde = { version = "1.0.189", features = ["derive"] }
serde_json = "1.0.94"
binrw = "^0.14.1"
erased-serde = "^0.4"
flate2 = { version = "^1.0.17" }
serde = { version = "^1.0.189", features = ["derive"] }
serde_json = "^1.0.94"

[dev-dependencies]
pretty_assertions = "1.3.0"
tempfile = "3"
pretty_assertions = "^1.3.0"
tempfile = "^3"
12 changes: 12 additions & 0 deletions models/src/common/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(dead_code, unused_variables)]

use std::{error::Error, path::Path};

use binrw::{BinRead, BinWrite};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -106,6 +108,16 @@ impl std::fmt::Display for ResourceType {
}
}

impl TryFrom<&Path> for ResourceType {
type Error = Box<dyn Error>;
fn try_from(value: &Path) -> Result<Self, Self::Error> {
let extension = value.extension().ok_or("Path has no extension")?;
Ok(Self::from(
extension.to_str().ok_or("Could not convert to string")?,
))
}
}

impl From<&str> for ResourceType {
fn from(value: &str) -> Self {
match value.to_ascii_lowercase().as_str() {
Expand Down
41 changes: 33 additions & 8 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
use clap::{ArgAction, Parser};
use std::path::PathBuf;

use clap::{error::ErrorKind, ArgAction, Error, Parser};

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
pub struct Args {
/// Game lang
#[clap(long, value_parser, default_value = "en_US")]
#[clap(env, short = 'l', long, value_parser, default_value = "en_US")]
pub game_lang: String,
/// Flag to process tiles
#[clap(long, short, action=ArgAction::SetTrue)]
#[clap(env, long, short, action=ArgAction::SetTrue)]
pub tiles: bool,
/// Flag to tlk file
#[clap(long, short, action=ArgAction::SetFalse)]
#[clap(env, long, short, action=ArgAction::SetTrue)]
pub process_tlk: bool,
/// Json Output
#[clap(long, short, action=ArgAction::SetTrue)]
pub json: bool,
/// Output Format, expects json(j), binary(b), print(p), or none(empty value)
#[clap(env, long, short, value_parser=output_format_parser, default_value = "")]
pub output_format: String,
/// Filename or prefix to extract [WARNING: EXPERIMENTAL]
#[clap(env, long, short, default_value = "")]
pub extract: String,
/// Turn a json into an ie file type [WARNING: EXPERIMENTAL]
#[clap(env, short='i', long, action=ArgAction::SetTrue)]
pub to_ie_type: bool,
/// Read Save game
#[clap(env, long, short, action=ArgAction::SetTrue)]
pub save: bool,
/// Read Save game
#[clap(env, long, short, default_value = ".")]
pub destination: PathBuf,
/// The path to the file to read
pub resource_file_or_dir: std::path::PathBuf,
#[clap(env, long, short)]
pub resource_file_or_dir: PathBuf,
}

fn output_format_parser(input: &str) -> Result<String, clap::Error> {
match input.to_lowercase().as_str() {
"json" | "j" => Ok("json".to_string()),
"binary" | "bin" | "b" => Ok("binary".to_string()),
"" | "n" | "no" | "none" => Ok("".to_string()),
"p" | "print" => Ok("print".to_string()),
_ => Err(Error::new(ErrorKind::ValueValidation)),
}
}
Loading

0 comments on commit 09cc477

Please sign in to comment.