Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show gamedata #334

Merged
merged 1 commit into from
Jun 19, 2024
Merged
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
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ figment = { version = "0.10", features = ["toml", "env"] }
toml = "0.8.14"
is_executable = "1.0.1"
regex = { version = "1.10.5", features = [] }
vpin = { version = "0.15.2" }
vpin = { version = "0.15.3" }
rust-ini = "0.21.0"
edit = "0.1.5"

Expand Down
34 changes: 33 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::path::{Path, PathBuf};
use std::process::{exit, ExitCode};
use vpin::directb2s::read;
use vpin::vpx;
use vpin::vpx::jsonmodel::info_to_json;
use vpin::vpx::jsonmodel::{game_data_to_json, info_to_json};
use vpin::vpx::{expanded, extractvbs, importvbs, tableinfo, verify, ExtractResult, VerifyResult};

pub mod config;
Expand Down Expand Up @@ -66,6 +66,9 @@ const CMD_INFO_DIFF: &str = "diff";
const CMD_IMAGES: &str = "images";
const CMD_IMAGES_WEBP: &str = "webp";

const CMD_GAMEDATA: &str = "gamedata";
const CMD_GAMEDATA_SHOW: &str = "show";

pub struct ProgressBarProgress {
pb: ProgressBar,
}
Expand Down Expand Up @@ -659,6 +662,22 @@ fn handle_command(matches: ArgMatches) -> io::Result<ExitCode> {
}
_ => unreachable!(),
},
Some((CMD_GAMEDATA, sub_matches)) => match sub_matches.subcommand() {
Some((CMD_GAMEDATA_SHOW, sub_matches)) => {
let path = sub_matches
.get_one::<String>("VPXPATH")
.map(|s| s.as_str())
.unwrap_or_default();
let expanded_path = expand_path(path)?;
let mut vpx_file = vpx::open(expanded_path)?;
let game_data = vpx_file.read_gamedata()?;
let json = game_data_to_json(&game_data);
let pretty = serde_json::to_string_pretty(&json)?;
println!("{}", pretty)?;
Ok(ExitCode::SUCCESS)
}
_ => unreachable!(),
},
_ => unreachable!(), // If all subcommands are defined above, anything else is unreachable!()
}
}
Expand Down Expand Up @@ -924,6 +943,19 @@ fn build_command() -> Command {
),
),
)
.subcommand(
Command::new(CMD_GAMEDATA)
.subcommand_required(true)
.about("Vpx gamedata related commands")
.subcommand(
Command::new(CMD_GAMEDATA_SHOW)
.about("Show the gamedata for a vpx file")
.arg(
arg!(<VPXPATH> "The path to the vpx file")
.required(true),
),
),
)
}

fn open_or_fail(vbs_path: &Path, config: Option<&ResolvedConfig>) -> io::Result<ExitCode> {
Expand Down