Skip to content

Commit

Permalink
fix(config): 🐛 fix config not saving properly
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Dec 3, 2023
1 parent eb03d71 commit 64418da
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 24 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bitflags.workspace = true
strum.workspace = true
serde.workspace = true
alox-48.workspace = true
ron.workspace = true

rand.workspace = true
getrandom.workspace = true
Expand Down
20 changes: 19 additions & 1 deletion crates/core/src/data_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,25 @@ impl Data {
maps.get_mut().iter().try_for_each(|(id, map)| {
write_data(map, filesystem, format!("Map{id:0>3}.rxdata"))
.with_context(|| format!("while saving map {id:0>3}"))
})
})?;

let pretty_config = ron::ser::PrettyConfig::new()
.struct_names(true)
.enumerate_arrays(true);

let project_config = ron::ser::to_string_pretty(&config.project, pretty_config.clone())?;
filesystem.write(".luminol/config", project_config)?;

let command_db = ron::ser::to_string_pretty(&config.command_db, pretty_config.clone())?;
filesystem.write(".luminol/commands", command_db)?;

let mut ini_file = filesystem.open_file(
"Game.ini",
luminol_filesystem::OpenFlags::Create
| luminol_filesystem::OpenFlags::Write
| luminol_filesystem::OpenFlags::Truncate,
)?;
config.game_ini.write_to(&mut ini_file).map_err(Into::into)
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/filesystem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ tracing.workspace = true

luminol-config.workspace = true

once_cell.workspace = true

[target.'cfg(windows)'.dependencies]
winreg = "0.51.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
once_cell.workspace = true
rand.workspace = true
slab.workspace = true

Expand Down
69 changes: 47 additions & 22 deletions crates/filesystem/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@ impl FileSystem {
self.create_dir(".luminol")?;
}

let game_ini = match self
.read_to_string("Game.ini")
.ok()
.and_then(|i| ini::Ini::load_from_str_noescape(&i).ok())
{
Some(i) => i,
None => {
let mut ini = ini::Ini::new();
ini.with_section(Some("Game"))
.set("Library", "RGSS104E.dll")
.set("Scripts", "Data/Scripts.rxdata")
.set("Title", "")
.set("RTP1", "")
.set("RTP2", "")
.set("RTP3", "");

let mut file = self.open_file(
"Game.ini",
OpenFlags::Write | OpenFlags::Create | OpenFlags::Truncate,
)?;
ini.write_to(&mut file)?;

ini
}
};

let pretty_config = ron::ser::PrettyConfig::new()
.struct_names(true)
.enumerate_arrays(true);

let project = match self
.read_to_string(".luminol/config")
.ok()
Expand All @@ -113,11 +143,22 @@ impl FileSystem {
let Some(editor_ver) = self.detect_rm_ver() else {
return Err(Error::UnableToDetectRMVer);
};

let project_name = game_ini
.general_section()
.get("Title")
.map(str::to_string)
.unwrap_or_default();
let config = luminol_config::project::Project {
editor_ver,
project_name,
..Default::default()
};
self.write(".luminol/config", ron::to_string(&config).unwrap())?;

self.write(
".luminol/config",
ron::ser::to_string_pretty(&config, pretty_config.clone()).unwrap(),
)?;
config
}
};
Expand All @@ -130,28 +171,12 @@ impl FileSystem {
Some(c) => c,
None => {
let command_db = luminol_config::command_db::CommandDB::new(project.editor_ver);
self.write(".luminol/commands", ron::to_string(&command_db).unwrap())?;
command_db
}
};

let game_ini = match self
.read_to_string("Game.ini")
.ok()
.and_then(|i| ini::Ini::load_from_str_noescape(&i).ok())
{
Some(i) => i,
None => {
let mut ini = ini::Ini::new();
ini.with_section(Some("Game"))
.set("Library", "RGSS104E.dll")
.set("Scripts", &project.scripts_path)
.set("Title", &project.project_name)
.set("RTP1", "")
.set("RTP2", "")
.set("RTP3", "");

ini
self.write(
".luminol/commands",
ron::ser::to_string_pretty(&command_db, pretty_config).unwrap(),
)?;
command_db
}
};

Expand Down

0 comments on commit 64418da

Please sign in to comment.