Skip to content

Commit

Permalink
Restructure module layout so game-specific modules are at root-level
Browse files Browse the repository at this point in the history
  • Loading branch information
holly-hacker committed Oct 27, 2023
1 parent 54622a1 commit 4674304
Show file tree
Hide file tree
Showing 51 changed files with 75 additions and 140 deletions.
10 changes: 4 additions & 6 deletions data-prepper/src/extract/mod.rs → data-prepper/src/extract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
pub mod ryza3;
pub mod sophie;
mod util;

use std::{
fs::File,
path::{Path, PathBuf},
Expand Down Expand Up @@ -60,8 +56,10 @@ impl Args {

// extract data from game files
match game_version {
GameVersion::A17 => sophie::extract(pak_index, &output_directory),
GameVersion::A24 => ryza3::extract(&self.game_directory, pak_index, &output_directory),
GameVersion::A17 => super::sophie::extract(pak_index, &output_directory),
GameVersion::A24 => {
super::ryza3::extract(&self.game_directory, pak_index, &output_directory)
}
_ => bail!("Unsupported game version {:?}", game_version),
}
}
Expand Down
3 changes: 0 additions & 3 deletions data-prepper/src/extract/util/mod.rs

This file was deleted.

5 changes: 3 additions & 2 deletions data-prepper/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod extract;
mod extract_images;
pub mod ryza3;
pub mod sophie;
mod typedefs;
mod utils;

Expand All @@ -26,7 +27,7 @@ struct CliArgs {
#[argh(subcommand)]
enum Subcommand {
Extract(extract::Args),
ExtractImages(extract_images::Args),
ExtractImages(ryza3::extract_images::Args), // TODO: allow extracting images from other games
TypeDefs(typedefs::Args),
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
extract::util::{self, ElementReader},
utils::PakIndex,
};
use crate::utils::{self, ElementReader, PakIndex};

#[derive(Debug)]
pub struct EnemyData {
Expand All @@ -21,7 +18,7 @@ pub struct EnemyData {

impl EnemyData {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Vec<Self>> {
util::read_xml(pak_index, r"\saves\enemy\enemy_data.xml", |d| {
utils::read_xml(pak_index, r"\saves\enemy\enemy_data.xml", |d| {
Self::read_from_doc(d)
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
extract::util::{self, ElementReader},
utils::PakIndex,
};
use crate::utils::{self, ElementReader, PakIndex};

#[derive(Debug)]
pub struct DropData {
Expand Down Expand Up @@ -39,7 +36,7 @@ pub struct DropData {

impl DropData {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Vec<Self>> {
util::read_xml(pak_index, r"\saves\enemy\drop_data.xml", |d| {
utils::read_xml(pak_index, r"\saves\enemy\drop_data.xml", |d| {
Self::read_from_doc(d)
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
extract::util::{self, ElementReader},
utils::PakIndex,
};
use crate::utils::{self, ElementReader, PakIndex};

pub struct LibraryMonster {
pub monster_tag: String,
Expand All @@ -12,7 +9,7 @@ pub struct LibraryMonster {

impl LibraryMonster {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Vec<Self>> {
util::read_xml(pak_index, r"\saves\library\librarymonster.xml", |d| {
utils::read_xml(pak_index, r"\saves\library\librarymonster.xml", |d| {
Self::read_from_doc(d)
})
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
extract::util::{self, ElementReader},
utils::PakIndex,
};
use crate::utils::{self, ElementReader, PakIndex};

#[derive(Debug, Clone)]
pub struct EnemyStatus {
Expand Down Expand Up @@ -33,7 +30,7 @@ pub struct EnemyStatus {

impl EnemyStatus {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Vec<Self>> {
util::read_xml(pak_index, r"\saves\enemy\enemy_status.xml", |d| {
utils::read_xml(pak_index, r"\saves\enemy\enemy_status.xml", |d| {
Self::read_from_doc(d)
})
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! Data from `\saves\feeding\feedingspecies.xml`
use crate::{
extract::util::{self, ElementReader},
utils::PakIndex,
};
use crate::utils::{self, ElementReader, PakIndex};

pub struct Species {
pub no: usize,
Expand Down Expand Up @@ -35,7 +32,7 @@ pub struct Species {

impl Species {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Vec<Self>> {
util::read_xml(
utils::read_xml(
pak_index,
r"\saves\feeding\feedingspecies.xml",
Self::read_from_doc,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! Data from `\saves\feeding\feedinguniqueitemevent.xml`
use crate::{
extract::util::{self, ElementReader},
utils::PakIndex,
};
use crate::utils::{self, ElementReader, PakIndex};

pub struct FeedingUniqueItemEvent {
pub no: usize,
Expand All @@ -15,7 +12,7 @@ pub struct FeedingUniqueItemEvent {

impl FeedingUniqueItemEvent {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Vec<Self>> {
util::read_xml(
utils::read_xml(
pak_index,
r"\saves\feeding\feedinguniqueitemevent.xml",
Self::read_from_doc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use std::collections::BTreeMap;
use anyhow::Context;
use tracing::debug;

use crate::{
extract::util::{self, ElementReader},
utils::PakIndex,
};
use crate::utils::{self, ElementReader, PakIndex};

#[derive(Debug)]
pub struct GimmickProperty {
Expand Down Expand Up @@ -48,7 +45,7 @@ impl GimmickProperty {
let stripped = file_name.trim_start_matches(PREFIX);
debug_assert!(stripped.ends_with(".xml"));

let parsed = util::read_xml(pak_index, file_name, Self::read_from_doc)
let parsed = utils::read_xml(pak_index, file_name, Self::read_from_doc)
.with_context(|| format!("parse gimmick doc '{file_name}'"))?;

Ok((stripped.to_owned(), parsed))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use serde::Serialize;
use tracing::trace;
use typescript_type_def::TypeDef;

use crate::extract::ryza3::data::field_data::gimmick::GimmickProperty;
use crate::ryza3::data::field_data::gimmick::GimmickProperty;
use crate::utils::PakIndex;
pub use field_data_types::*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::extract::util::{self, ElementReader};
use crate::utils::PakIndex;
use crate::utils::{self, ElementReader, PakIndex};
use anyhow::Context;

pub struct FieldMapInfo {
Expand All @@ -18,7 +17,7 @@ pub struct FieldMapInfo {

impl FieldMapInfo {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Vec<Self>> {
util::read_xml(pak_index, r"\saves\fieldmap\info\fm_info.xml", |d| {
utils::read_xml(pak_index, r"\saves\fieldmap\info\fm_info.xml", |d| {
Self::read_from_doc(d)
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::extract::util::{self, ElementReader};
use crate::utils::PakIndex;
use crate::utils::{self, ElementReader, PakIndex};
use anyhow::Context;

pub struct FieldMapInfo2 {
Expand All @@ -16,7 +15,7 @@ pub struct FieldMapInfo2 {
impl FieldMapInfo2 {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Vec<Self>> {
// NOTE: reading as shift_jis
util::read_xml_shift_jis(pak_index, r"\saves\fieldmap\info\fm_info2.xml", |d| {
utils::read_xml_shift_jis(pak_index, r"\saves\fieldmap\info\fm_info2.xml", |d| {
Self::read_from_doc(d)
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::extract::ryza3::data::strings_table::StringsTable;
use crate::ryza3::data::strings_table::StringsTable;
use crate::utils::PakIndex;
use serde::Serialize;
use std::collections::BTreeMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::extract::util::{self, ElementReader};
use crate::utils::PakIndex;
use crate::utils::{self, ElementReader, PakIndex};
use anyhow::Context;

pub struct RegionMap {
Expand All @@ -12,7 +11,7 @@ pub struct RegionMap {

impl RegionMap {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Vec<Self>> {
util::read_xml(
utils::read_xml(
pak_index,
r"\saves\ui_cmn\a24_map\uil_a24_overall_map.xml",
Self::read_from_doc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::Context;
use serde::Serialize;
use typescript_type_def::TypeDef;

use crate::extract::ryza3::executable::Ryza3ExecutableData;
use crate::ryza3::executable::Ryza3ExecutableData;

use super::strings_table::StringsTable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use anyhow::Context;
use roxmltree::Node;

use crate::{
extract::util::{self, ElementReader},
utils::PakIndex,
};
use crate::utils::{self, ElementReader, PakIndex};

pub struct ItemEffect {
pub name_id: Option<String>,
Expand All @@ -23,7 +20,7 @@ pub struct ItemEffect {

impl ItemEffect {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Vec<Self>> {
util::read_xml(pak_index, r"\saves\item\item_effect.xml", |d| {
utils::read_xml(pak_index, r"\saves\item\item_effect.xml", |d| {
Self::read_from_doc(d)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::Serialize;
use tracing::debug;
use typescript_type_def::TypeDef;

use crate::{extract::ryza3::executable::Ryza3ExecutableData, utils::PakIndex};
use crate::{ryza3::executable::Ryza3ExecutableData, utils::PakIndex};

use super::strings_table::StringsTable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use tracing::trace;

use crate::{
extract::util::{self, ElementReader},
utils::PakIndex,
};
use crate::utils::{self, ElementReader, PakIndex};

pub struct ItemData {
pub name_id: Option<String>,
Expand Down Expand Up @@ -48,7 +45,7 @@ pub struct ItemData {

impl ItemData {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Vec<Self>> {
util::read_xml(pak_index, r"\saves\item\itemdata.xml", |d| {
utils::read_xml(pak_index, r"\saves\item\itemdata.xml", |d| {
Self::read_from_doc(d)
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
extract::util::{self, ElementReader},
utils::PakIndex,
};
use crate::utils::{self, ElementReader, PakIndex};

pub struct LibraryItem {
pub item_tag: String,
Expand All @@ -12,7 +9,7 @@ pub struct LibraryItem {

impl LibraryItem {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Vec<Self>> {
util::read_xml(pak_index, r"\saves\library\libraryitem.xml", |d| {
utils::read_xml(pak_index, r"\saves\library\libraryitem.xml", |d| {
Self::read_from_doc(d)
})
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
use anyhow::{bail, Context};

use crate::{
extract::util::{self, ElementReader},
utils::PakIndex,
};
use crate::utils::{self, ElementReader, PakIndex};

pub enum ItemRecipeData {
Header(RecipeHeader),
Expand Down Expand Up @@ -86,7 +83,7 @@ impl IngredientData {

impl ItemRecipeData {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Vec<Self>> {
util::read_xml(pak_index, r"\saves\item\itemrecipedata.xml", |d| {
utils::read_xml(pak_index, r"\saves\item\itemrecipedata.xml", |d| {
Self::read_from_doc(d)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use std::collections::HashMap;

use anyhow::{bail, Context};

use crate::{
extract::util::{self, ElementReader},
utils::PakIndex,
};
use crate::utils::{self, ElementReader, PakIndex};

/// A hash map of `tag` to `ExtendedFieldData`.
pub struct ExtendedFieldData(pub HashMap<String, Vec<Field>>);
Expand Down Expand Up @@ -74,7 +71,7 @@ pub struct RingParam {

impl ExtendedFieldData {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Self> {
util::read_xml(pak_index, r"\saves\mix\mixfielddata.xml", |d| {
utils::read_xml(pak_index, r"\saves\mix\mixfielddata.xml", |d| {
Self::read_from_doc(d)
})
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use std::collections::HashMap;

use anyhow::Context;

use crate::{
extract::util::{self, ElementReader},
utils::PakIndex,
};
use crate::utils::{self, ElementReader, PakIndex};

pub struct StringsTable {
pub id_lookup: HashMap<String, String>,
Expand All @@ -14,7 +11,7 @@ pub struct StringsTable {

impl StringsTable {
pub fn read(pak_index: &mut PakIndex) -> anyhow::Result<Self> {
util::read_xml(
utils::read_xml(
pak_index,
r"\saves\text_en\strcombineall.xml",
Self::read_from_doc,
Expand Down
File renamed without changes.
Loading

0 comments on commit 4674304

Please sign in to comment.