Skip to content

Commit

Permalink
Actually get data conversion to work
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Jul 11, 2024
1 parent cacda0e commit e62b2a2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
14 changes: 9 additions & 5 deletions crates/core/src/data_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ impl Data {
pub fn convert_project(
&mut self,
filesystem: &impl luminol_filesystem::FileSystem,
from: luminol_config::DataFormat,
config: &luminol_config::project::Config,
to: luminol_config::DataFormat,
) -> color_eyre::Result<()> {
let from_handler = data_formats::Handler::new(from);
let from_handler = data_formats::Handler::new(config.project.data_format);
let to_handler = data_formats::Handler::new(to);

let Self::Loaded {
Expand Down Expand Up @@ -413,9 +413,6 @@ impl Data {
to_handler.write_nil_padded(&items.get_mut().data, filesystem, "Items")?;
from_handler.remove_file(filesystem, "Items")?;

to_handler.write_nil_padded(&scripts.get_mut().data, filesystem, "Scripts")?;
from_handler.remove_file(filesystem, "Scripts")?;

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

Expand All @@ -432,6 +429,13 @@ impl Data {
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")?;

Expand Down
7 changes: 6 additions & 1 deletion crates/filesystem/src/path_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Cache {

#[derive(Debug)]
pub struct FileSystem<F> {
fs: F,
pub(crate) fs: F,
cache: parking_lot::RwLock<Cache>,
}

Expand Down Expand Up @@ -217,6 +217,11 @@ where
&self.fs
}

pub fn rebuild(&self) {
let mut cache = self.cache.write();
*cache = Default::default(); // FIXME we don't actually bother rebuilding anything, this is just a reset...
}

pub fn debug_ui(&self, ui: &mut egui::Ui) {
let cache = self.cache.read();

Expand Down
15 changes: 15 additions & 0 deletions crates/filesystem/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ impl FileSystem {
pub fn unload_project(&mut self) {
*self = FileSystem::Unloaded;
}

// gives access to the non-path cache'd filesystem, for when you need to do direct manipulation of the filesystem
// the path cache should be rebuilt after this!
pub fn raw_filesystem(&self) -> &impl crate::FileSystem {
match self {
FileSystem::Unloaded | FileSystem::HostLoaded(_) => panic!("not loaded"),
FileSystem::Loaded { filesystem, .. } => &filesystem.fs,
}
}

pub fn rebuild_path_cache(&self) {
if let Self::Loaded { filesystem, .. } = self {
filesystem.rebuild();
}
}
}

// Not platform specific
Expand Down
5 changes: 3 additions & 2 deletions crates/ui/src/windows/config_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ impl luminol_core::Window for Window {
update_state
.data
.convert_project(
update_state.filesystem,
config.project.data_format,
update_state.filesystem.raw_filesystem(),
config,
self.selected_data_format,
)
.unwrap(); // TODO handle
update_state.filesystem.rebuild_path_cache(); // I do not like this solution. A dedicated tool for this would be more appropriate.
config.project.data_format = self.selected_data_format;
}
}
Expand Down

0 comments on commit e62b2a2

Please sign in to comment.