diff --git a/docs/launcher-commands.md b/docs/launcher-commands.md index c88c38c6b..9efaa1f37 100644 --- a/docs/launcher-commands.md +++ b/docs/launcher-commands.md @@ -572,10 +572,12 @@ MCP: `modpack_remove`, needs `confirm: true`. ## `horizon-launcher mods list` -What the browser installed (the default). +What the browser installed in an instance (the default). horizon-launcher mods list +- `--instance`: The instance (default: the selected one) + MCP: `mods_list`. ## `horizon-launcher mods search` @@ -605,11 +607,12 @@ MCP: `mods_check`. ## `horizon-launcher mods install` -Install a pack and what it needs, by its id or slug (checksums checked); a Java mod is ported into horizon-mods and turned on; a modpack is imported. +Install a pack and what it needs into an instance, by its id or slug (checksums checked); a Java mod is ported into horizon-mods and turned on; a modpack is imported as an instance of its own. horizon-launcher mods install - `PROJECT` +- `--instance`: The instance (default: the selected one) - `--everything`: Allow a version made for another Minecraft version - `--source` (modrinth, curseforge, horizon) @@ -623,6 +626,7 @@ Update what the browser installed (or one pack). - `PROJECT` - `--check`: Only say what is newer +- `--instance`: The instance (default: the selected one) MCP: `mods_update`. @@ -633,6 +637,7 @@ Remove a pack the browser installed. horizon-launcher mods remove - `PROJECT` +- `--instance`: The instance (default: the selected one) MCP: `mods_remove`, needs `confirm: true`. @@ -643,6 +648,7 @@ Turn on a mod the browser installed (horizon-mods.txt, as the game's Options > M horizon-launcher mods enable - `PROJECT` +- `--instance`: The instance (default: the selected one) MCP: `mods_enable`. @@ -653,6 +659,7 @@ Turn off a mod the browser installed; it stays installed. horizon-launcher mods disable - `PROJECT` +- `--instance`: The instance (default: the selected one) MCP: `mods_disable`. diff --git a/docs/mod-browser.md b/docs/mod-browser.md index d4483cd4e..dac595d8e 100644 --- a/docs/mod-browser.md +++ b/docs/mod-browser.md @@ -18,6 +18,11 @@ yet (Modrinth has no `horizon` loader). | Modpacks (`.mrpack`, CurseForge zip) | the Modpacks page's import | **Partly**: Horizon runs the mods it can port, from the player's own downloads ([modpacks.md](modpacks.md)) | | Shader packs (`.hshader`, Horizon's registry only) | `shaderpacks/` beside `options.txt` | **Works** when made for 26.3: checked by the game's own check before install ([shaders.md](shaders.md)). The `shaders/`-format packs on Modrinth and CurseForge are not offered | +Mods, resource packs and shader packs go into the game folder of the instance selected in the sidebar, and the +Installed list, updates and Remove are that instance's: picking another instance reads its list. The page says which +instance it installs into when there is more than one. The CLI's `mods list|install|update|remove|enable|disable` take +`--instance ` (default: the selected one). A modpack becomes an instance of its own. + By default a search shows only what runs: Java mods made for 26.3, resource packs made for 26.3, and every modpack. **Show everything** lists the rest of the kind too, each marked with how well it runs; what doesn't run is never offered for install. diff --git a/launcher/src/cli.rs b/launcher/src/cli.rs index 852fde696..f05d32ad1 100644 --- a/launcher/src/cli.rs +++ b/launcher/src/cli.rs @@ -339,8 +339,12 @@ enum MultiplayerCmd { #[derive(Subcommand)] enum ModsCmd { - /// What the browser installed (the default) - List, + /// What the browser installed in an instance (the default) + List { + /// The instance (default: the selected one) + #[arg(long)] + instance: Option, + }, /// Search for packs Horizon loads Search { text: Vec, @@ -362,10 +366,14 @@ enum ModsCmd { #[arg(long, value_enum, default_value_t = SourceArg::Modrinth)] source: SourceArg, }, - /// Install a pack and what it needs, by its id or slug (checksums checked); a Java mod is - /// ported into horizon-mods and turned on; a modpack is imported + /// Install a pack and what it needs into an instance, by its id or slug (checksums + /// checked); a Java mod is ported into horizon-mods and turned on; a modpack is imported as + /// an instance of its own Install { project: String, + /// The instance (default: the selected one) + #[arg(long)] + instance: Option, /// Allow a version made for another Minecraft version #[arg(long)] everything: bool, @@ -378,13 +386,31 @@ enum ModsCmd { /// Only say what is newer #[arg(long)] check: bool, + /// The instance (default: the selected one) + #[arg(long)] + instance: Option, }, /// Remove a pack the browser installed - Remove { project: String }, + Remove { + project: String, + /// The instance (default: the selected one) + #[arg(long)] + instance: Option, + }, /// Turn on a mod the browser installed (horizon-mods.txt, as the game's Options > Mods does) - Enable { project: String }, + Enable { + project: String, + /// The instance (default: the selected one) + #[arg(long)] + instance: Option, + }, /// Turn off a mod the browser installed; it stays installed - Disable { project: String }, + Disable { + project: String, + /// The instance (default: the selected one) + #[arg(long)] + instance: Option, + }, } #[derive(Clone, Copy, clap::ValueEnum)] @@ -1035,7 +1061,7 @@ fn execute(command: Cmd, as_json: bool) -> Result<(), String> { )?, Cmd::Instance { action } => instance(action.unwrap_or(InstanceCmd::List), as_json)?, Cmd::Modpack { action } => modpack(action.unwrap_or(ModpackCmd::List), as_json)?, - Cmd::Mods { action } => mods(action.unwrap_or(ModsCmd::List), as_json)?, + Cmd::Mods { action } => mods(action.unwrap_or(ModsCmd::List { instance: None }), as_json)?, Cmd::Servers { action } => servers(action.unwrap_or(ServersCmd::List), as_json)?, Cmd::Mcp => unreachable!(), } @@ -1337,7 +1363,20 @@ fn servers(action: ServersCmd, as_json: bool) -> Result<(), String> { fn mods(action: ModsCmd, as_json: bool) -> Result<(), String> { use horizon_launcher::browser::{horizon, installed, Kind, Query, SourceId}; use horizon_launcher::modpacks; - let home = backend::game_home(); + // What the browser installs goes into an instance's game folder; Java mods' checks are kept + // in the default one, shared by all. + let home = match &action { + ModsCmd::List { instance } + | ModsCmd::Install { instance, .. } + | ModsCmd::Update { instance, .. } + | ModsCmd::Remove { instance, .. } + | ModsCmd::Enable { instance, .. } + | ModsCmd::Disable { instance, .. } => match instance { + Some(name) => instances::find(name)?.home, + None => instances::selected().home, + }, + ModsCmd::Search { .. } | ModsCmd::Check { .. } => backend::game_home(), + }; let entry_json = |e: &installed::Entry| serde_json::to_value(e).unwrap_or_default(); let line = |label: &str, f: f32| progress(label.to_string())(f); let from_registry = installed::Installed::load(&home) @@ -1353,7 +1392,7 @@ fn mods(action: ModsCmd, as_json: bool) -> Result<(), String> { } let on = matches!(action, ModsCmd::Enable { .. }); match action { - ModsCmd::List => { + ModsCmd::List { .. } => { let list = installed::Installed::load(&home).entries; if as_json { json(list.iter().map(entry_json).collect()); @@ -1476,6 +1515,7 @@ fn mods(action: ModsCmd, as_json: bool) -> Result<(), String> { project, everything, source, + .. } => { let source = source.get()?; let p = source.project(&project)?; @@ -1521,7 +1561,7 @@ fn mods(action: ModsCmd, as_json: bool) -> Result<(), String> { } } } - ModsCmd::Update { project, check } => { + ModsCmd::Update { project, check, .. } => { let list = installed::Installed::load(&home).entries; let chosen: Vec<_> = list .iter() @@ -1556,11 +1596,11 @@ fn mods(action: ModsCmd, as_json: bool) -> Result<(), String> { } } } - ModsCmd::Remove { project } => { + ModsCmd::Remove { project, .. } => { let e = installed::remove(&home, &project)?; println!("Removed {} ({}).", e.title, e.file); } - ModsCmd::Enable { project } | ModsCmd::Disable { project } => { + ModsCmd::Enable { project, .. } | ModsCmd::Disable { project, .. } => { let e = installed::Installed::load(&home) .lookup(&project) .cloned() @@ -2070,4 +2110,39 @@ mod tests { _ => panic!("expected game-args"), } } + + #[test] + fn mods_commands_name_their_instance() { + let parse = |args: &[&str]| { + let cli = Cli::try_parse_from([&["horizon-launcher", "mods"], args].concat()).unwrap(); + match cli.command { + Some(Cmd::Mods { action }) => action, + _ => panic!("expected mods"), + } + }; + match parse(&["install", "fresh-animations", "--instance", "Skyblock"]) { + Some(ModsCmd::Install { + project, instance, .. + }) => assert_eq!( + (project.as_str(), instance.as_deref()), + ("fresh-animations", Some("Skyblock")) + ), + _ => panic!("expected mods install"), + } + assert!(matches!( + parse(&["list"]), + Some(ModsCmd::List { instance: None }) + )); + assert!(parse(&[]).is_none()); + // Search and Check read no instance: checks are shared. + assert!(Cli::try_parse_from([ + "horizon-launcher", + "mods", + "search", + "x", + "--instance", + "A" + ]) + .is_err()); + } } diff --git a/launcher/src/mods_page.rs b/launcher/src/mods_page.rs index b98cfb654..9feed87e0 100644 --- a/launcher/src/mods_page.rs +++ b/launcher/src/mods_page.rs @@ -12,6 +12,7 @@ use horizon_launcher::browser::{ use horizon_launcher::modpacks; use horizon_port_pack::check::Check; use std::collections::HashMap; +use std::path::PathBuf; /// The kinds, as the Mods page's tabs: name and icon. const KINDS: [(PackKind, &str, &str); 4] = [ @@ -71,6 +72,8 @@ pub(super) struct Mods { error: Option, installed: Vec, loaded: bool, + /// The game folder the browser installs into and lists: the selected instance's. + home: Option, /// The project being installed, and the line and fraction of its download. pub(super) busy: Option<(String, String, f32)>, message: Option>, @@ -93,6 +96,11 @@ impl Mods { self.report_list.reset(); } + /// The game folder installs go into: the selected instance's, once the page has read it. + pub(super) fn home(&self) -> PathBuf { + self.home.clone().unwrap_or_else(backend::game_home) + } + /// Whether the Modpacks tab is open (the sidebar marks the pack shown there). pub(super) fn on_modpacks(&self) -> bool { self.kind == PackKind::Modpack @@ -130,6 +138,7 @@ impl Mods { error: None, installed: Vec::new(), loaded: false, + home: None, busy: None, message: None, updates: HashMap::new(), @@ -264,7 +273,7 @@ impl Launcher { Event::Done(result, modpack) => { m.busy = None; m.message = Some(result); - m.installed = installed::Installed::load(&backend::game_home()).entries; + m.installed = installed::Installed::load(&m.home()).entries; m.installed_list.reset(); if modpack { // The Modpacks page reads its list again. @@ -287,7 +296,7 @@ impl Launcher { } Event::TakenDown(lines) => { m.message = Some(Ok(lines.join("\n"))); - m.installed = installed::Installed::load(&backend::game_home()).entries; + m.installed = installed::Installed::load(&m.home()).entries; m.installed_list.reset(); } } @@ -363,11 +372,12 @@ impl Launcher { return; } let tx = self.mods.tx.clone(); + let home = self.mods.home(); std::thread::spawn(move || { let Ok(index) = horizon::index() else { return; }; - let lines = horizon::turn_off_revoked(&index, &backend::game_home()); + let lines = horizon::turn_off_revoked(&index, &home); if !lines.is_empty() { let _ = tx.send(Event::TakenDown(lines)); } @@ -376,7 +386,7 @@ impl Launcher { /// Turns a Horizon mod the browser installed on or off, as the game's Options > Mods does. fn mods_switch(&mut self, e: &installed::Entry) { - let home = backend::game_home(); + let home = self.mods.home(); let Some(id) = horizon::mod_id(e) else { return; }; @@ -418,6 +428,7 @@ impl Launcher { let tx = m.tx.clone(); let queue = std::sync::Mutex::new(todo.into_iter()); std::thread::spawn(move || { + // Checks are kept in the default game folder, shared by every instance. let home = backend::game_home(); std::thread::scope(|s| { for _ in 0..CHECKING { @@ -490,8 +501,8 @@ impl Launcher { self.mods.busy = Some(("all".into(), "Updating…".into(), 0.)); self.mods.updates.clear(); let tx = self.mods.tx.clone(); + let home = self.mods.home(); std::thread::spawn(move || { - let home = backend::game_home(); let count = todo.len(); let (mut done, mut failed) = (Vec::new(), Vec::new()); for (i, (source_id, id, title)) in todo.into_iter().enumerate() { @@ -548,6 +559,7 @@ impl Launcher { .filter(|tag| backend::is_prepared(tag)) .map(|tag| backend::resources(tag)); let tx = self.mods.tx.clone(); + let home = self.mods.home(); std::thread::spawn(move || { let last = std::cell::Cell::new(-1); let progress = |line: &str, f: f32| { @@ -587,7 +599,6 @@ impl Launcher { modpacks::outcome(&pack) )); } - let home = backend::game_home(); let done = installed::install(&*source, &p, everything, &home, &progress)?; let names: Vec = done .iter() @@ -690,12 +701,20 @@ impl Launcher { pub(super) fn mods_page(&mut self, cx: &mut Context) -> Div { let t = self.theme; - if !self.mods.loaded { - self.mods.loaded = true; - self.mods.installed = installed::Installed::load(&backend::game_home()).entries; + // Packs and mods go into the selected instance: picking another reads its list. + let home = self.selected_instance().map(|i| i.home.clone()); + if !self.mods.loaded || (home.is_some() && self.mods.home != home) { + self.mods.home = home; + self.mods.installed = installed::Installed::load(&self.mods.home()).entries; + self.mods.installed_list.reset(); + self.mods.updates.clear(); + self.mods.confirm_remove = None; self.mods_check_updates(); self.mods_taken_down(); - self.mods_search(0); + if !self.mods.loaded { + self.mods_search(0); + } + self.mods.loaded = true; } let header = page_header( "Mods", @@ -763,7 +782,8 @@ impl Launcher { .when(!registry, |d| d.child(toggle)), ) .child(source_note) - .children(filters); + .children(filters) + .children(self.mods_target_line()); // The kinds are inventory tabs on the panel that holds the open one. let body = blocks::panel(&t).flex().flex_col().gap(px(24.)).p(px(20.)); let page = |body: Div| { @@ -791,6 +811,23 @@ impl Launcher { page(body.child(self.mods_results(cx))) } + /// Which instance installs go into, when there is more than one to pick from. A modpack + /// becomes an instance of its own. + fn mods_target_line(&self) -> Option
{ + let instance = self.selected_instance()?; + if self.instances.list.len() < 2 || self.mods.kind == PackKind::Modpack { + return None; + } + Some( + text(theme::CAPTION) + .text_color(self.theme.muted) + .child(format!( + "Installs into {}: pick another instance on the left.", + instance.name + )), + ) + } + /// The install under way and the last install's answer. pub(super) fn mods_busy_plate(&self) -> Vec
{ let t = self.theme; @@ -885,7 +922,7 @@ impl Launcher { .when(confirming, |b| b.text_color(t.danger)) .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { if this.mods.confirm_remove.as_ref() == Some(&id) { - let home = backend::game_home(); + let home = this.mods.home(); this.mods.message = Some( installed::remove(&home, &id).map(|e| format!("Removed {}.", e.title)), ); @@ -898,8 +935,8 @@ impl Launcher { cx.notify(); })); if e.source == SourceId::Horizon && e.kind == PackKind::Mod { - let on = horizon::mod_id(e) - .is_some_and(|id| java::is_enabled(&backend::game_home(), id)); + let on = + horizon::mod_id(e).is_some_and(|id| java::is_enabled(&self.mods.home(), id)); let entry = e.clone(); right = right.child( div()