rpgmxp_tool/
main.rs

1mod commands;
2mod util;
3
4use anyhow::bail;
5use std::str::FromStr;
6
7/// The game kind
8#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
9pub enum GameKind {
10    Xp,
11    Vx,
12}
13
14impl GameKind {
15    /// Returns true if this is xp.
16    pub fn is_xp(self) -> bool {
17        matches!(self, Self::Xp)
18    }
19
20    /// Returns true if this is vx.
21    pub fn is_vx(self) -> bool {
22        matches!(self, Self::Vx)
23    }
24}
25
26impl FromStr for GameKind {
27    type Err = anyhow::Error;
28
29    fn from_str(input: &str) -> Result<Self, Self::Err> {
30        if input.eq_ignore_ascii_case("xp") || input.eq_ignore_ascii_case("rgssad") {
31            return Ok(Self::Xp);
32        }
33
34        if input.eq_ignore_ascii_case("vx") || input.eq_ignore_ascii_case("rgss2a") {
35            return Ok(Self::Vx);
36        }
37
38        bail!("\"{input}\" is not a valid game kind");
39    }
40}
41
42#[derive(Debug, argh::FromArgs)]
43#[argh(description = "a cli tool to interact with rpgmaker xp and vx games")]
44struct Options {
45    #[argh(subcommand)]
46    subcommand: Subcommand,
47}
48
49#[derive(Debug, argh::FromArgs)]
50#[argh(subcommand)]
51enum Subcommand {
52    ExtractAssets(self::commands::extract_assets::Options),
53    CompileAssets(self::commands::compile_assets::Options),
54}
55
56fn main() -> anyhow::Result<()> {
57    let options: Options = argh::from_env();
58    match options.subcommand {
59        Subcommand::ExtractAssets(options) => self::commands::extract_assets::exec(options)?,
60        Subcommand::CompileAssets(options) => self::commands::compile_assets::exec(options)?,
61    }
62
63    Ok(())
64}