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    VxAce,
13}
14
15impl GameKind {
16    /// Returns true if this is xp.
17    pub fn is_xp(self) -> bool {
18        matches!(self, Self::Xp)
19    }
20
21    /// Returns true if this is vx.
22    pub fn is_vx(self) -> bool {
23        matches!(self, Self::Vx)
24    }
25
26    /// Returns true if this is vx ace.
27    pub fn is_vx_ace(self) -> bool {
28        matches!(self, Self::VxAce)
29    }
30}
31
32impl FromStr for GameKind {
33    type Err = anyhow::Error;
34
35    fn from_str(input: &str) -> Result<Self, Self::Err> {
36        if input.eq_ignore_ascii_case("xp") || input.eq_ignore_ascii_case("rgssad") {
37            return Ok(Self::Xp);
38        }
39
40        if input.eq_ignore_ascii_case("vx") || input.eq_ignore_ascii_case("rgss2a") {
41            return Ok(Self::Vx);
42        }
43
44        if input.eq_ignore_ascii_case("vx-ace")
45            || input.eq_ignore_ascii_case("rgss3a")
46            || input.eq_ignore_ascii_case("ace")
47        {
48            return Ok(Self::Vx);
49        }
50
51        bail!("\"{input}\" is not a valid game kind");
52    }
53}
54
55#[derive(Debug, argh::FromArgs)]
56#[argh(description = "a cli tool to interact with rpgmaker xp and vx games")]
57struct Options {
58    #[argh(subcommand)]
59    subcommand: Subcommand,
60}
61
62#[derive(Debug, argh::FromArgs)]
63#[argh(subcommand)]
64enum Subcommand {
65    ExtractAssets(self::commands::extract_assets::Options),
66    CompileAssets(self::commands::compile_assets::Options),
67}
68
69fn main() -> anyhow::Result<()> {
70    let options: Options = argh::from_env();
71    match options.subcommand {
72        Subcommand::ExtractAssets(options) => self::commands::extract_assets::exec(options)?,
73        Subcommand::CompileAssets(options) => self::commands::compile_assets::exec(options)?,
74    }
75
76    Ok(())
77}