Skip to content

Commit

Permalink
Data conversion (Astrabit-ST#141)
Browse files Browse the repository at this point in the history
* Conversion that sort of works

* Refactor code to be more async

* Fix wasm compile error

* Oops

* Actually deserialize/serialize parameter type now

* Add pretty print support

* Flush files
  • Loading branch information
melody-rs authored and MolassesLover committed Jul 23, 2024
1 parent 99f1058 commit 0041bb1
Show file tree
Hide file tree
Showing 9 changed files with 538 additions and 135 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ pub enum DataFormat {
#[strum(to_string = "Ruby Marshal")]
Marshal,
#[strum(to_string = "RON")]
Ron,
Ron { pretty: bool },
#[strum(to_string = "JSON")]
Json,
Json { pretty: bool },
}

impl DataFormat {
pub fn extension(self) -> &'static str {
match self {
Self::Marshal => "rxdata",
Self::Ron => "ron",
Self::Json => "json",
Self::Ron { .. } => "ron",
Self::Json { .. } => "json",
}
}
}
Expand Down
90 changes: 0 additions & 90 deletions crates/core/src/data_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,96 +366,6 @@ impl Data {
}
Ok(())
}

pub fn convert_project(
&mut self,
filesystem: &impl luminol_filesystem::FileSystem,
config: &luminol_config::project::Config,
to: luminol_config::DataFormat,
) -> color_eyre::Result<()> {
let from_handler = data_formats::Handler::new(config.project.data_format);
let to_handler = data_formats::Handler::new(to);

let Self::Loaded {
actors,
animations,
armors,
classes,
common_events,
enemies,
items,
map_infos,
scripts,
skills,
states,
system,
tilesets,
troops,
weapons,
..
} = self
else {
panic!("project not loaded")
};

to_handler.write_nil_padded(&actors.get_mut().data, filesystem, "Actors")?;
from_handler.remove_file(filesystem, "Actors")?;

to_handler.write_nil_padded(&animations.get_mut().data, filesystem, "Animations")?;
from_handler.remove_file(filesystem, "Animations")?;

to_handler.write_nil_padded(&armors.get_mut().data, filesystem, "Armors")?;
from_handler.remove_file(filesystem, "Armors")?;

to_handler.write_nil_padded(&classes.get_mut().data, filesystem, "Classes")?;
from_handler.remove_file(filesystem, "Classes")?;

to_handler.write_nil_padded(&common_events.get_mut().data, filesystem, "CommonEvents")?;
from_handler.remove_file(filesystem, "CommonEvents")?;

to_handler.write_nil_padded(&enemies.get_mut().data, filesystem, "Enemies")?;
from_handler.remove_file(filesystem, "Enemies")?;

to_handler.write_nil_padded(&items.get_mut().data, filesystem, "Items")?;
from_handler.remove_file(filesystem, "Items")?;

to_handler.write_nil_padded(&skills.get_mut().data, filesystem, "Skills")?;
from_handler.remove_file(filesystem, "Skills")?;

to_handler.write_nil_padded(&states.get_mut().data, filesystem, "States")?;
from_handler.remove_file(filesystem, "States")?;

to_handler.write_nil_padded(&tilesets.get_mut().data, filesystem, "Tilesets")?;
from_handler.remove_file(filesystem, "Tilesets")?;

to_handler.write_nil_padded(&troops.get_mut().data, filesystem, "Troops")?;
from_handler.remove_file(filesystem, "Troops")?;

to_handler.write_nil_padded(&weapons.get_mut().data, filesystem, "Weapons")?;
from_handler.remove_file(filesystem, "Weapons")?;

// special handling
to_handler.write_data(
&scripts.get_mut().data,
filesystem,
&config.project.scripts_path,
)?;
from_handler.remove_file(filesystem, &config.project.scripts_path)?;

to_handler.write_data(&system.get_mut(), filesystem, "System")?;
from_handler.remove_file(filesystem, "System")?;

to_handler.write_data(&map_infos.get_mut().data, filesystem, "MapInfos")?;
from_handler.remove_file(filesystem, "MapInfos")?;

for id in map_infos.get_mut().data.keys() {
let map: rpg::Map = from_handler.read_data(filesystem, format!("Map{id:0>3}"))?;
to_handler.write_data(&map, filesystem, format!("Map{id:0>3}"))?;
from_handler.remove_file(filesystem, format!("Map{id:0>3}"))?;
}

Ok(())
}
}

macro_rules! nested_ref_getter {
Expand Down
Loading

0 comments on commit 0041bb1

Please sign in to comment.