Skip to content

Commit

Permalink
mod states stored based on branch
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Dec 27, 2023
1 parent ce7433b commit 9b731b5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
14 changes: 11 additions & 3 deletions src-tauri/src/app/app_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,20 @@ pub(crate) struct LauncherOptions {
pub preferred_build: Option<i32>,
#[serde(rename = "currentAccount")]
pub current_account: Option<MinecraftAccount>,
#[serde(rename = "modStates", default)]
pub mod_states: HashMap<String, bool>,
#[serde(rename = "branchOptions", default)]
pub branch_options: HashMap<String, BranchOptions>,
#[serde(rename = "concurrentDownloads", default = "default_concurrent_downloads")]
pub concurrent_downloads: i32
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub(crate) struct BranchOptions {
#[serde(rename = "modStates", default)]
pub mod_states: HashMap<String, bool>,
#[serde(rename = "customModStates", default)]
pub custom_mod_states: HashMap<String, bool>,
}

impl LauncherOptions {

pub async fn load(app_data: &Path) -> Result<Self> {
Expand Down Expand Up @@ -82,7 +90,7 @@ impl Default for LauncherOptions {
preferred_branch: None,
preferred_build: None,
current_account: None,
mod_states: HashMap::new(),
branch_options: HashMap::new(),
concurrent_downloads: 10
}
}
Expand Down
23 changes: 16 additions & 7 deletions src/lib/main/MainScreen.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,21 @@
})
.catch(e => console.error(e));
requestMods(b.mcVersion, b.subsystem);
requestMods(b.branch, b.mcVersion, b.subsystem);
}
/// Request mods from API server
function requestMods(mcVersion, subsystem) {
function requestMods(branch, mcVersion, subsystem) {
invoke("request_mods", { mcVersion, subsystem })
.then(result => {
mods = result;
mods.forEach(mod => {
mod.enabled = options.modStates[mod.name] ?? mod.enabled;
});
const branchOptions = options.branchOptions[branch];
if (branchOptions) {
mods.forEach(mod => {
mod.enabled = branchOptions.modStates[mod.name] ?? mod.enabled;
});
}
})
.catch(e => console.error(e));
}
Expand Down Expand Up @@ -206,12 +209,18 @@
});
function updateModStates() {
options.modStates = mods.reduce(function(map, mod) {
const branchOptions = options.branchOptions[options.preferredBranch] ?? {
modStates: {},
customModStates: {}
};
branchOptions.modStates = mods.reduce(function(map, mod) {
map[mod.name] = mod.enabled;
return map;
}, {});
console.debug("Updated mod states", options.modStates);
console.debug("Updated mod states", branchOptions.modStates);
options.branchOptions[options.preferredBranch] = branchOptions;
options.store();
}
Expand Down

0 comments on commit 9b731b5

Please sign in to comment.