From e00e4240cbd584973fcf65dcea9b5d2a1eb6f5e2 Mon Sep 17 00:00:00 2001 From: Purdze <29306641+Purdze@users.noreply.github.com> Date: Wed, 18 Nov 2026 13:10:17 +0000 Subject: [PATCH 1/5] add a pomme settings page and move chunk detail, distant terrain and shader pack onto it --- pomme-client/src/ui/menu/mod.rs | 27 +++ pomme-client/src/ui/menu/options.rs | 233 +++++++++++++++++++--- tests/ingame/ui/chunk_detail.toml | 34 +++- tests/ingame/ui/chunk_fade.toml | 2 +- tests/ingame/ui/inactivity_fps_limit.toml | 2 +- tests/ingame/ui/options_scrollbar.toml | 2 +- tests/ingame/ui/pomme_settings.toml | 150 ++++++++++++++ 7 files changed, 406 insertions(+), 44 deletions(-) create mode 100644 tests/ingame/ui/pomme_settings.toml diff --git a/pomme-client/src/ui/menu/mod.rs b/pomme-client/src/ui/menu/mod.rs index dc633c642..774709181 100644 --- a/pomme-client/src/ui/menu/mod.rs +++ b/pomme-client/src/ui/menu/mod.rs @@ -629,6 +629,10 @@ enum Screen { Options, OptionsOnline, OptionsVideo, + /// Pomme's own settings and their category screens (Pomme-only). + OptionsPomme, + OptionsPommePerformance, + OptionsPommeShaders, OptionsSkinCustomization, OptionsMusicSounds, OptionsControls, @@ -654,6 +658,9 @@ impl Screen { Self::Options => Self::Options, Self::OptionsOnline => Self::OptionsOnline, Self::OptionsVideo => Self::OptionsVideo, + Self::OptionsPomme => Self::OptionsPomme, + Self::OptionsPommePerformance => Self::OptionsPommePerformance, + Self::OptionsPommeShaders => Self::OptionsPommeShaders, Self::OptionsSkinCustomization => Self::OptionsSkinCustomization, Self::OptionsMusicSounds => Self::OptionsMusicSounds, Self::OptionsControls => Self::OptionsControls, @@ -1422,6 +1429,9 @@ impl MainMenu { Screen::Options | Screen::OptionsOnline | Screen::OptionsVideo + | Screen::OptionsPomme + | Screen::OptionsPommePerformance + | Screen::OptionsPommeShaders | Screen::OptionsSkinCustomization | Screen::OptionsMusicSounds | Screen::OptionsControls @@ -1711,6 +1721,23 @@ impl MainMenu { Screen::OptionsVideo => { self.build_options_video(screen_w, screen_h, input, &text_width_fn, key_bindings) } + Screen::OptionsPomme => { + self.build_options_pomme(screen_w, screen_h, input, &text_width_fn, key_bindings) + } + Screen::OptionsPommePerformance => self.build_options_pomme_performance( + screen_w, + screen_h, + input, + &text_width_fn, + key_bindings, + ), + Screen::OptionsPommeShaders => self.build_options_pomme_shaders( + screen_w, + screen_h, + input, + &text_width_fn, + key_bindings, + ), Screen::OptionsSkinCustomization => { self.build_options_skin(screen_w, screen_h, input, &text_width_fn, key_bindings) } diff --git a/pomme-client/src/ui/menu/options.rs b/pomme-client/src/ui/menu/options.rs index 8986d5830..e8e9d95dd 100644 --- a/pomme-client/src/ui/menu/options.rs +++ b/pomme-client/src/ui/menu/options.rs @@ -18,6 +18,10 @@ pub(super) enum OptRow<'a> { Big(&'a str), Pair(&'a str, &'a str), PairLeft(&'a str), + /// One 150px widget centred on the screen. As the last row of a screen + /// without a header it hangs below the centred grid, which moves up only + /// when the row wouldn't clear Done. + Center(&'a str), } fn option_enabled(label: &str, disabled: &[&str]) -> bool { @@ -30,7 +34,7 @@ fn option_enabled(label: &str, disabled: &[&str]) -> bool { fn row_labels<'a>(row: &OptRow<'a>) -> Vec<&'a str> { match row { OptRow::Header(_) => Vec::new(), - OptRow::Big(a) | OptRow::PairLeft(a) => vec![*a], + OptRow::Big(a) | OptRow::PairLeft(a) | OptRow::Center(a) => vec![*a], OptRow::Pair(a, b) => vec![*a, *b], } } @@ -140,7 +144,9 @@ const CHAT_SCALE: &str = "Chat Text Size:"; const CHAT_LINE_SPACING: &str = "Line Spacing:"; const CHAT_DELAY: &str = "Chat Delay:"; const MENU_BACKGROUND_BLUR: &str = "Menu Background Blur:"; +const CHUNK_DETAIL: &str = "Chunk Detail:"; const DISTANT_TERRAIN: &str = "Distant Terrain:"; +const SHADER_PACK: &str = "Shader Pack:"; const CHUNK_FADE: &str = "Chunk Fade:"; const INACTIVITY_FPS_LIMIT: &str = "Reduce fps when:"; @@ -258,6 +264,9 @@ impl MainMenu { OptRow::Pair("Language...", "Chat Settings..."), OptRow::Pair("Resource Packs...", "Accessibility Settings..."), OptRow::Pair("Telemetry Data...", "Credits & Attribution..."), + // The one way into Pomme's own settings (Pomme-only), under the + // grid so its rows keep their order. + OptRow::Center("Pomme Settings..."), ]; let nav: &[(&str, Screen)] = &[ @@ -272,6 +281,7 @@ impl MainMenu { ("Accessibility Settings...", Screen::OptionsAccessibility), ("Telemetry Data...", Screen::OptionsTelemetry), ("Credits & Attribution...", Screen::OptionsCredits), + ("Pomme Settings...", Screen::OptionsPomme), ]; let fov_frac = (self.fov as f32 - 30.0) / 80.0; @@ -343,7 +353,7 @@ impl MainMenu { fn discrete_slider_span(&self, prefix: &str) -> Option { Some(match prefix { "Render Distance:" => self.render_distance_max() as f32 - 2.0, - "Chunk Detail:" => super::CHUNK_DETAIL_SPAN, + CHUNK_DETAIL => super::CHUNK_DETAIL_SPAN, DISTANT_TERRAIN => super::DISTANT_TERRAIN_STEPS as f32, "Simulation Distance:" => 27.0, "Max Framerate:" => 25.0, @@ -381,16 +391,6 @@ impl MainMenu { DisplayMode::Fullscreen => "Fullscreen: Exclusive", }; let rd = format!("Render Distance: {} chunks", self.render_distance); - let cd = if self.chunk_detail >= super::CHUNK_DETAIL_OFF { - "Chunk Detail: Off".to_string() - } else { - format!("Chunk Detail: {} chunks", self.chunk_detail) - }; - let dt = if self.distant_terrain == 0 { - format!("{DISTANT_TERRAIN} OFF") - } else { - format!("{DISTANT_TERRAIN} {} chunks", self.distant_terrain) - }; let sd = format!("Simulation Distance: {} chunks", self.simulation_distance); let mf = if self.max_framerate >= super::MAX_FRAMERATE_UNLIMITED { "Max Framerate: Unlimited".to_string() @@ -412,10 +412,6 @@ impl MainMenu { "{INACTIVITY_FPS_LIMIT} {}", self.inactivity_fps_limit.label() ); - let shader_label = format!( - "Shader Pack: {}", - self.shader_pack.as_deref().unwrap_or("OFF") - ); let attack_label = format!("Attack Indicator: {}", self.attack_indicator.label()); let vignette_label = if self.vignette { "Vignette: ON" @@ -448,13 +444,12 @@ impl MainMenu { // TODO: static stub, not wired (see mesher::enqueue). OptRow::Pair("Prioritize Chunk Updates: None", &sd), OptRow::Pair("Smooth Lighting: ON", &clouds_label), - OptRow::Pair(&cd, &dt), OptRow::Pair("Particles: All", "Mipmap Levels: 4"), OptRow::Pair(entity_shadows_label, "Entity Distance: 100%"), OptRow::Pair(&blur_label, "Cloud Range: 128"), OptRow::Pair("Cutout Leaves: Fancy", "Improved Transparency: OFF"), OptRow::Pair("Texture Filtering: None", "Max Anisotropy: 1"), - OptRow::Pair("Weather Radius: 10", &shader_label), + OptRow::PairLeft("Weather Radius: 10"), OptRow::Header("Preferences"), OptRow::Pair(autosave_label, vignette_label), OptRow::Pair(&attack_label, &fade_label), @@ -462,17 +457,10 @@ impl MainMenu { let rd_frac = ((self.render_distance as f32 - 2.0) / (self.render_distance_max() as f32 - 2.0)) .clamp(0.0, 1.0); - let cd_frac = (self.chunk_detail.saturating_sub(super::CHUNK_DETAIL_MIN) as f32 - / super::CHUNK_DETAIL_SPAN) - .clamp(0.0, 1.0); - let dt_frac = super::distant_terrain_step(self.distant_terrain) as f32 - / super::DISTANT_TERRAIN_STEPS as f32; let sd_frac = (self.simulation_distance as f32 - 5.0) / 27.0; let mf_frac = (self.max_framerate as f32 - 10.0) / 250.0; let sliders: &[(&str, f32)] = &[ ("Render Distance:", rd_frac), - ("Chunk Detail:", cd_frac), - (DISTANT_TERRAIN, dt_frac), ("Simulation Distance:", sd_frac), ("Max Framerate:", mf_frac), (BRIGHTNESS, self.brightness), @@ -522,6 +510,113 @@ impl MainMenu { ) } + /// Pomme's own settings (Pomme-only): everything the options screens + /// have no place for, one sub-screen per category as Options has one per + /// area. + pub(super) fn build_options_pomme( + &mut self, + sw: f32, + sh: f32, + input: &MenuInput, + text_width_fn: common::TextWidthFn, + key_bindings: &KeyBindings, + ) -> MainMenuResult { + let rows = [OptRow::Pair("Performance...", "Shaders...")]; + let nav: &[(&str, Screen)] = &[ + ("Performance...", Screen::OptionsPommePerformance), + ("Shaders...", Screen::OptionsPommeShaders), + ]; + self.build_options_grid( + sw, + sh, + input, + "Pomme Settings", + Screen::Options, + &rows, + nav, + &[], + &[], + false, + &[], + text_width_fn, + key_bindings, + ) + } + + /// Pomme Settings' Performance category (Pomme-only). + pub(super) fn build_options_pomme_performance( + &mut self, + sw: f32, + sh: f32, + input: &MenuInput, + text_width_fn: common::TextWidthFn, + key_bindings: &KeyBindings, + ) -> MainMenuResult { + let cd = if self.chunk_detail >= super::CHUNK_DETAIL_OFF { + format!("{CHUNK_DETAIL} Off") + } else { + format!("{CHUNK_DETAIL} {} chunks", self.chunk_detail) + }; + let dt = if self.distant_terrain == 0 { + format!("{DISTANT_TERRAIN} OFF") + } else { + format!("{DISTANT_TERRAIN} {} chunks", self.distant_terrain) + }; + let rows = [OptRow::Pair(&cd, &dt)]; + let cd_frac = (self.chunk_detail.saturating_sub(super::CHUNK_DETAIL_MIN) as f32 + / super::CHUNK_DETAIL_SPAN) + .clamp(0.0, 1.0); + let dt_frac = super::distant_terrain_step(self.distant_terrain) as f32 + / super::DISTANT_TERRAIN_STEPS as f32; + let sliders: &[(&str, f32)] = &[(CHUNK_DETAIL, cd_frac), (DISTANT_TERRAIN, dt_frac)]; + self.build_options_grid( + sw, + sh, + input, + "Performance", + Screen::OptionsPomme, + &rows, + &[], + sliders, + &[], + true, + &[], + text_width_fn, + key_bindings, + ) + } + + /// Pomme Settings' Shaders category (Pomme-only). + pub(super) fn build_options_pomme_shaders( + &mut self, + sw: f32, + sh: f32, + input: &MenuInput, + text_width_fn: common::TextWidthFn, + key_bindings: &KeyBindings, + ) -> MainMenuResult { + let shader_label = format!( + "{SHADER_PACK} {}", + self.shader_pack.as_deref().unwrap_or("OFF") + ); + let rows = [OptRow::PairLeft(&shader_label)]; + self.build_options_grid( + sw, + sh, + input, + "Shaders", + Screen::OptionsPomme, + &rows, + &[], + &[], + &[], + true, + &[], + text_width_fn, + key_bindings, + ) + } + pub(super) fn build_options_controls( &mut self, sw: f32, @@ -1391,6 +1486,10 @@ impl MainMenu { .enumerate() .map(|(i, row)| row_advance(i, row)) .sum(); + let hanging_h = match rows.last() { + Some(OptRow::Center(_)) if !header_footer => row_h, + _ => 0.0, + }; let content_h = content_bottom - content_top; let list_h = grid_h + content_pad; let scrollable = header_footer && list_h > content_h; @@ -1418,7 +1517,13 @@ impl MainMenu { let top_y = if header_footer { content_top + content_pad - scroll } else { - content_top + (content_h - grid_h) / 2.0 + let centred = content_top + (content_h - (grid_h - hanging_h)) / 2.0; + if hanging_h > 0.0 { + // Done keeps the gap the rows have between them. + centred.min(content_bottom - grid_h - btn_dy) + } else { + centred + } }; let mut slider_results: Vec<(&str, f32)> = Vec::new(); let label_scroll = common::LabelScroll { @@ -1472,6 +1577,7 @@ impl MainMenu { widgets.push((*b, right_x, small_w)); } OptRow::PairLeft(a) => widgets.push((*a, left_x, small_w)), + OptRow::Center(a) => widgets.push((*a, cx - small_w / 2.0, small_w)), } for (label, bx, bw) in widgets { let enabled = option_enabled(label, disabled); @@ -1578,7 +1684,7 @@ impl MainMenu { self.cloud_mode = self.cloud_mode.cycle(); self.save_settings(key_bindings); } - if label.starts_with("Shader Pack:") { + if label.starts_with(SHADER_PACK) { self.shader_pack = next_shader_pack(&self.shader_packs_dir, self.shader_pack.as_deref()); self.save_settings(key_bindings); @@ -1710,7 +1816,7 @@ impl MainMenu { let span = self.discrete_slider_span(prefix).unwrap_or(1.0); match *prefix { "Render Distance:" => self.render_distance = (2.0 + v * span).round() as u32, - "Chunk Detail:" => { + CHUNK_DETAIL => { self.chunk_detail = super::CHUNK_DETAIL_MIN + (v * span).round() as u32 } DISTANT_TERRAIN => { @@ -2569,7 +2675,8 @@ mod tests { struct Grid { menu: MainMenu, key_bindings: KeyBindings, - rows: [OptRow<'static>; 1], + rows: Vec>, + height: f32, nav: Vec<(&'static str, Screen)>, sliders: Vec<(&'static str, f32)>, disabled: Vec<&'static str>, @@ -2581,7 +2688,8 @@ mod tests { Self { menu: test_menu("pomme-options-focus-test", &mut key_bindings), key_bindings, - rows: [OptRow::Pair(left, right)], + rows: vec![OptRow::Pair(left, right)], + height: 600.0, nav: Vec::new(), sliders: Vec::new(), disabled: Vec::new(), @@ -2598,7 +2706,7 @@ mod tests { let text_width = |_: &str, _: f32| 0.0; self.menu.build_options_grid( 800.0, - 600.0, + self.height, input, "Test", Screen::Main, @@ -2619,8 +2727,12 @@ mod tests { } fn click(x: f32) -> MenuInput { + click_at(x, 300.0) + } + + fn click_at(x: f32, y: f32) -> MenuInput { MenuInput { - cursor: (x, 300.0), + cursor: (x, y), clicked: true, mouse_held: true, ..Default::default() @@ -2842,6 +2954,9 @@ mod tests { menu.build_options_mouse(sw, sh, &input, tw, &key_bindings); menu.build_options(sw, sh, &input, tw, &key_bindings); menu.build_options_video(sw, sh, &input, tw, &key_bindings); + menu.build_options_pomme(sw, sh, &input, tw, &key_bindings); + menu.build_options_pomme_performance(sw, sh, &input, tw, &key_bindings); + menu.build_options_pomme_shaders(sw, sh, &input, tw, &key_bindings); menu.build_options_controls(sw, sh, &input, tw, &key_bindings); menu.build_options_chat(sw, sh, &input, tw, &key_bindings); menu.build_options_accessibility(sw, sh, &input, tw, &key_bindings); @@ -2849,4 +2964,58 @@ mod tests { menu.build_options_skin(sw, sh, &input, tw, &key_bindings); menu.build_options_online(sw, sh, &input, tw, &key_bindings); } + + /// Every button frame `w` wide, as `(x, y)`, in build order. + fn frames(result: &MainMenuResult, w: f32) -> Vec<(f32, f32)> { + result + .elements + .iter() + .filter_map(|e| match e { + MenuElement::NineSlice { x, y, w: fw, .. } if *fw == w => Some((*x, *y)), + _ => None, + }) + .collect() + } + + #[test] + fn a_trailing_centre_row_lifts_the_grid_only_when_it_would_not_clear_done() { + let idle = MenuInput::default(); + let mut plain = Grid::new("First", "Second"); + let mut hanging = Grid::new("First", "Second"); + hanging.rows.push(OptRow::Center("Third")); + + // Room to spare: the grid stays put and the row sits one pitch below. + let before = frames(&plain.frame(&idle), 150.0); + let after = frames(&hanging.frame(&idle), 150.0); + assert_eq!(after[..2], before[..]); + assert_eq!(after[2], (325.0, before[0].1 + 25.0)); + + // Too short: the grid moves up until the row clears Done by the gap + // rows keep between them. + plain.height = 120.0; + hanging.height = 120.0; + let short = hanging.frame(&idle); + let done_y = frames(&short, 200.0)[0].1; + let rows = frames(&short, 150.0); + assert_eq!(rows[2].1 + BTN_H + 5.0, done_y); + assert_eq!(rows[0].1 + 25.0, rows[2].1); + assert!(rows[0].1 < frames(&plain.frame(&idle), 150.0)[0].1); + } + + #[test] + fn the_pomme_settings_button_opens_its_categories() { + let mut key_bindings = KeyBindings::default(); + let mut menu = test_menu("pomme-settings-entry-test", &mut key_bindings); + let text_width = |_: &str, _: f32| 0.0; + let tw: common::TextWidthFn = &text_width; + let idle = menu.build_options(800.0, 600.0, &MenuInput::default(), tw, &key_bindings); + // The only small widget centred on the screen. + let (x, y) = *frames(&idle, 150.0) + .iter() + .find(|(x, _)| *x == 325.0) + .expect("the centred row"); + let click = click_at(x + 75.0, y + BTN_H / 2.0); + menu.build_options(800.0, 600.0, &click, tw, &key_bindings); + assert!(matches!(menu.screen, Screen::OptionsPomme)); + } } diff --git a/tests/ingame/ui/chunk_detail.toml b/tests/ingame/ui/chunk_detail.toml index a57f1fa60..c313a78d0 100644 --- a/tests/ingame/ui/chunk_detail.toml +++ b/tests/ingame/ui/chunk_detail.toml @@ -1,5 +1,6 @@ -# The Chunk Detail slider defaults to Off at its right end and steps down to -# 8 chunks at its left. Ends back on Off, since the options save. +# Chunk Detail, in Pomme Settings' Performance category (Pomme-only): the +# slider defaults to Off at its right end and steps down to 8 chunks at its +# left. Ends back on Off, since the options save. [[step]] press = { action = "key.menu" } @@ -17,9 +18,9 @@ mouse_down = "left" [[step]] mouse_up = "left" -# Video Settings... +# Pomme Settings, then its Performance category. [[step]] -cursor = [133, 110] +cursor_to_button = "Pomme Settings..." [[step]] mouse_down = "left" @@ -28,10 +29,13 @@ mouse_down = "left" mouse_up = "left" [[step]] -cursor = [213, 120] +cursor_to_button = "Performance..." [[step]] -scroll = -10.0 +mouse_down = "left" + +[[step]] +mouse_up = "left" [[step]] wait_ms = 300 @@ -40,7 +44,7 @@ wait_ms = 300 screenshot = "off" [[step]] -cursor = [60, 118] +cursor = [60, 50] [[step]] mouse_down = "left" @@ -55,7 +59,17 @@ wait_ms = 300 screenshot = "eight" [[step]] -cursor = [207, 118] +cursor = [207, 50] + +[[step]] +mouse_down = "left" + +[[step]] +mouse_up = "left" + +# Done on Performance, on Pomme Settings, then on Options. +[[step]] +cursor = [213, 223] [[step]] mouse_down = "left" @@ -63,7 +77,9 @@ mouse_down = "left" [[step]] mouse_up = "left" -# Done, then Done again on Options. +[[step]] +wait_ms = 300 + [[step]] cursor = [213, 223] diff --git a/tests/ingame/ui/chunk_fade.toml b/tests/ingame/ui/chunk_fade.toml index b0877c38c..ef2a40c67 100644 --- a/tests/ingame/ui/chunk_fade.toml +++ b/tests/ingame/ui/chunk_fade.toml @@ -25,7 +25,7 @@ mouse_up = "left" # Video Settings... [[step]] -cursor = [133, 115] +cursor_to_button = "Video Settings..." [[step]] mouse_down = "left" diff --git a/tests/ingame/ui/inactivity_fps_limit.toml b/tests/ingame/ui/inactivity_fps_limit.toml index 6cccda439..8b9b4bdf1 100644 --- a/tests/ingame/ui/inactivity_fps_limit.toml +++ b/tests/ingame/ui/inactivity_fps_limit.toml @@ -26,7 +26,7 @@ mouse_up = "left" # Video Settings... [[step]] -cursor = [133, 115] +cursor_to_button = "Video Settings..." [[step]] mouse_down = "left" diff --git a/tests/ingame/ui/options_scrollbar.toml b/tests/ingame/ui/options_scrollbar.toml index 82b136e2c..8c4d63578 100644 --- a/tests/ingame/ui/options_scrollbar.toml +++ b/tests/ingame/ui/options_scrollbar.toml @@ -19,7 +19,7 @@ mouse_up = "left" # Video Settings... [[step]] -cursor = [133, 115] +cursor_to_button = "Video Settings..." [[step]] mouse_down = "left" diff --git a/tests/ingame/ui/pomme_settings.toml b/tests/ingame/ui/pomme_settings.toml new file mode 100644 index 000000000..87774ca10 --- /dev/null +++ b/tests/ingame/ui/pomme_settings.toml @@ -0,0 +1,150 @@ +# Pomme's own settings (Pomme-only): a button under the Options grid opens +# them, one screen per category. Performance holds Chunk Detail and Distant +# Terrain, Shaders holds Shader Pack. The other client has no such button, so +# the script fails there by design. + +[[step]] +press = { action = "key.menu" } + +[[step]] +expect = { menu = "pause" } + +# Options... +[[step]] +cursor = [161, 151] + +[[step]] +mouse_down = "left" + +[[step]] +mouse_up = "left" + +[[step]] +cursor = [213, 60] + +[[step]] +wait_ms = 300 + +[[step]] +screenshot = "options" + +[[step]] +cursor_to_button = "Pomme Settings..." + +[[step]] +wait_ms = 300 + +[[step]] +screenshot = "entry_hovered" + +[[step]] +mouse_down = "left" + +[[step]] +mouse_up = "left" + +[[step]] +cursor = [213, 200] + +[[step]] +wait_ms = 300 + +[[step]] +screenshot = "categories" + +[[step]] +cursor_to_button = "Performance..." + +[[step]] +mouse_down = "left" + +[[step]] +mouse_up = "left" + +[[step]] +wait_ms = 300 + +[[step]] +cursor = [213, 200] + +[[step]] +wait_ms = 300 + +[[step]] +screenshot = "performance" + +[[step]] +cursor_to_button = "Done" + +[[step]] +mouse_down = "left" + +[[step]] +mouse_up = "left" + +[[step]] +wait_ms = 300 + +[[step]] +cursor_to_button = "Shaders..." + +[[step]] +mouse_down = "left" + +[[step]] +mouse_up = "left" + +[[step]] +wait_ms = 300 + +[[step]] +cursor = [213, 200] + +[[step]] +wait_ms = 300 + +[[step]] +screenshot = "shaders" + +[[step]] +cursor_to_button = "Done" + +[[step]] +mouse_down = "left" + +[[step]] +mouse_up = "left" + +[[step]] +wait_ms = 300 + +# Back out of Pomme Settings, then Options. +[[step]] +cursor_to_button = "Done" + +[[step]] +mouse_down = "left" + +[[step]] +mouse_up = "left" + +[[step]] +wait_ms = 300 + +[[step]] +cursor_to_button = "Done" + +[[step]] +mouse_down = "left" + +[[step]] +mouse_up = "left" + +[[step]] +wait_ms = 300 + +[[step]] +press = { action = "key.menu" } + +[[step]] +expect = { menu = "none" } From b90df5741c33668bda18eb5066258ae31d907b12 Mon Sep 17 00:00:00 2001 From: Purdze <29306641+Purdze@users.noreply.github.com> Date: Wed, 18 Nov 2026 13:35:21 +0000 Subject: [PATCH 2/5] lay out the options screen by its header and footer, with pomme settings as a last grid row, and mark pomme-only scripts --- pomme-client/src/harness/script.rs | 4 + pomme-client/src/ui/menu/options.rs | 234 ++++++++++++++---------- tests/ingame/README.md | 4 + tests/ingame/ui/chunk_detail.toml | 2 + tests/ingame/ui/pomme_settings.toml | 5 +- tests/ingame/world/distant_terrain.toml | 5 +- 6 files changed, 157 insertions(+), 97 deletions(-) diff --git a/pomme-client/src/harness/script.rs b/pomme-client/src/harness/script.rs index e90ebb54f..cf19404f9 100644 --- a/pomme-client/src/harness/script.rs +++ b/pomme-client/src/harness/script.rs @@ -34,6 +34,10 @@ struct ScriptFile { _min_version: Option, #[serde(default, rename = "max_version")] _max_version: Option, + /// Marks a script about a Pomme extension, which the vanilla harness + /// skips. + #[serde(default, rename = "pomme_only")] + _pomme_only: bool, } /// One `[[step]]` table: exactly one action, plus an optional timeout. diff --git a/pomme-client/src/ui/menu/options.rs b/pomme-client/src/ui/menu/options.rs index e8e9d95dd..a8c2b04f3 100644 --- a/pomme-client/src/ui/menu/options.rs +++ b/pomme-client/src/ui/menu/options.rs @@ -12,18 +12,66 @@ use crate::ui::text::TextSpan; const COLLISION_STRIPE: [f32; 4] = common::rgb(0xffff00); /// A row in a vanilla-style options list: 25px pitch, a 310px `Big` widget, or -/// two 150px widgets per `Pair` (`PairLeft` for an odd trailing widget). +/// two 150px widgets per `Pair` (`PairLeft` for an odd trailing widget). On +/// the Options screen itself the first row is its header's and the rest are +/// its grid's (see [`RootLayout`]). pub(super) enum OptRow<'a> { Header(&'a str), Big(&'a str), Pair(&'a str, &'a str), PairLeft(&'a str), - /// One 150px widget centred on the screen. As the last row of a screen - /// without a header it hangs below the centred grid, which moves up only - /// when the row wouldn't clear Done. + /// One 150px widget centred on the screen. Center(&'a str), } +/// `OptionsScreen`'s `HeaderAndFooterLayout(61, 33)`, in GUI units: the title +/// and the first row stacked 8 apart and centred in the header, the other +/// rows a two-column grid of 150-wide cells padded 4 each side and below, +/// and Done centred in the footer. Vertical centring rounds half up, as +/// `AbstractChildWrapper.setY` does. +struct RootLayout { + title_y: f32, + header_row_y: f32, + grid_y: f32, + done_y: f32, +} + +impl RootLayout { + const HEADER_H: f32 = 61.0; + const HEADER_SPACING: f32 = 8.0; + /// A grid cell: the 150-wide button and its padding. + const CELL_W: f32 = 158.0; + /// Two buttons 8 apart, which the header row and the grid inside its + /// padding both are. + const ROW_W: f32 = 308.0; + const ROW_PITCH: f32 = 24.0; + + /// For a screen `height` GUI units tall with `grid_rows` rows under the + /// header's. + fn new(height: f32, grid_rows: usize) -> Self { + let line_h = common::LINE_HEIGHT as f32; + let stacked = line_h + Self::HEADER_SPACING + BTN_H; + let title_y = ((Self::HEADER_H - stacked) / 2.0).round(); + let footer_y = height - HEADER_FOOTER_H; + // `HeaderAndFooterLayout.arrangeElements`: 30 under the header, or + // higher where the grid wouldn't clear the footer. + let grid_h = Self::ROW_PITCH * grid_rows as f32; + Self { + title_y, + header_row_y: title_y + line_h + Self::HEADER_SPACING, + grid_y: (Self::HEADER_H + 30.0).min(footer_y - grid_h), + done_y: footer_y + ((HEADER_FOOTER_H - BTN_H) / 2.0).round(), + } + } + + fn row_y(&self, row: usize) -> f32 { + match row.checked_sub(1) { + None => self.header_row_y, + Some(grid_row) => self.grid_y + Self::ROW_PITCH * grid_row as f32, + } + } +} + fn option_enabled(label: &str, disabled: &[&str]) -> bool { !disabled.iter().any(|prefix| label.starts_with(prefix)) } @@ -255,8 +303,7 @@ impl MainMenu { } else { format!("FOV: {}", self.fov) }; - // FOV slider + Online lead the grid, above the categories (vanilla header - // sub-row). + // The first row is the header's (`RootLayout`). let rows: Vec = vec![ OptRow::Pair(&fov_label, "Online..."), OptRow::Pair("Skin Customization...", "Music & Sounds..."), @@ -264,8 +311,8 @@ impl MainMenu { OptRow::Pair("Language...", "Chat Settings..."), OptRow::Pair("Resource Packs...", "Accessibility Settings..."), OptRow::Pair("Telemetry Data...", "Credits & Attribution..."), - // The one way into Pomme's own settings (Pomme-only), under the - // grid so its rows keep their order. + // The one way into Pomme's own settings (Pomme-only), as a last + // grid row so the others keep their order. OptRow::Center("Pomme Settings..."), ]; @@ -511,8 +558,8 @@ impl MainMenu { } /// Pomme's own settings (Pomme-only): everything the options screens - /// have no place for, one sub-screen per category as Options has one per - /// area. + /// have no place for, one sub-screen per category, laid out as Controls + /// lays out its own. pub(super) fn build_options_pomme( &mut self, sw: f32, @@ -536,7 +583,7 @@ impl MainMenu { nav, &[], &[], - false, + true, &[], text_width_fn, key_bindings, @@ -1436,8 +1483,27 @@ impl MainMenu { let lh = 9.0 * gs; let btn_dy = (row_h - btn_h) / 2.0; let cx = sw / 2.0; - let left_x = cx - 155.0 * gs; - let right_x = left_x + 160.0 * gs; + let root = (!header_footer) + .then(|| RootLayout::new(common::gui_size(sh, gs), rows.len().saturating_sub(1))); + let done_w = 200.0 * gs; + let (left_x, right_x, center_x, done_x) = if root.is_some() { + let left_x = common::gui_aligned(sw, RootLayout::ROW_W, gs, 0.5); + let cell_w = RootLayout::CELL_W * gs; + ( + left_x, + left_x + cell_w, + left_x + cell_w / 2.0, + common::gui_aligned(sw, 200.0, gs, 0.5), + ) + } else { + let left_x = cx - 155.0 * gs; + ( + left_x, + left_x + 160.0 * gs, + cx - small_w / 2.0, + cx - done_w / 2.0, + ) + }; let cursor = input.cursor; let clicked = input.clicked; @@ -1447,28 +1513,26 @@ impl MainMenu { let (content_top, content_bottom, done_y); - if header_footer { - let chrome = push_screen_chrome(&mut elements, sw, sh, gs, title); - content_top = chrome.content_top; - content_bottom = chrome.content_bottom; - done_y = chrome.done_y; - } else { - let title_y = 15.0 * gs; - let done_pad = 8.0 * gs; - content_top = title_y + fs + 10.0 * gs; - done_y = sh - btn_h - done_pad; - content_bottom = done_y; + if let Some(root) = &root { + content_top = RootLayout::HEADER_H * gs; + content_bottom = sh - HEADER_FOOTER_H * gs; + done_y = root.done_y * gs; common::push_menu_background(&mut elements, sw, sh); elements.push(MenuElement::Text { - x: cx, - y: title_y, + x: common::gui_half_width(sw, gs), + y: root.title_y * gs, text: title.into(), scale: fs, color: WHITE, centered: true, }); + } else { + let chrome = push_screen_chrome(&mut elements, sw, sh, gs, title); + content_top = chrome.content_top; + content_bottom = chrome.content_bottom; + done_y = chrome.done_y; } let content_pad = if header_footer { 4.0 * gs } else { 0.0 }; @@ -1486,10 +1550,6 @@ impl MainMenu { .enumerate() .map(|(i, row)| row_advance(i, row)) .sum(); - let hanging_h = match rows.last() { - Some(OptRow::Center(_)) if !header_footer => row_h, - _ => 0.0, - }; let content_h = content_bottom - content_top; let list_h = grid_h + content_pad; let scrollable = header_footer && list_h > content_h; @@ -1514,17 +1574,7 @@ impl MainMenu { self.scroll_offset = 0.0; } let scroll = if scrollable { self.scroll_offset } else { 0.0 }; - let top_y = if header_footer { - content_top + content_pad - scroll - } else { - let centred = content_top + (content_h - (grid_h - hanging_h)) / 2.0; - if hanging_h > 0.0 { - // Done keeps the gap the rows have between them. - centred.min(content_bottom - grid_h - btn_dy) - } else { - centred - } - }; + let top_y = content_top + content_pad - scroll; let mut slider_results: Vec<(&str, f32)> = Vec::new(); let label_scroll = common::LabelScroll { text_width_fn, @@ -1557,7 +1607,10 @@ impl MainMenu { let mut y_cursor = top_y; for (i, row) in rows.iter().enumerate() { - let by = y_cursor + btn_dy; + let by = match &root { + Some(root) => root.row_y(i) * gs, + None => y_cursor + btn_dy, + }; let mut widgets: Vec<(&str, f32, f32)> = Vec::new(); match row { OptRow::Header(title) => { @@ -1577,7 +1630,7 @@ impl MainMenu { widgets.push((*b, right_x, small_w)); } OptRow::PairLeft(a) => widgets.push((*a, left_x, small_w)), - OptRow::Center(a) => widgets.push((*a, cx - small_w / 2.0, small_w)), + OptRow::Center(a) => widgets.push((*a, center_x, small_w)), } for (label, bx, bw) in widgets { let enabled = option_enabled(label, disabled); @@ -1876,22 +1929,14 @@ impl MainMenu { ); } - let done_w = 200.0 * gs; - let done_h = common::hit_test(cursor, [cx - done_w / 2.0, done_y, done_w, btn_h]); + let done_h = common::hit_test(cursor, [done_x, done_y, done_w, btn_h]); let done_focused = ctx.focused(true, done_h); - let done_cursor = helpers::focus_cursor( - done_focused, - done_h, - cx - done_w / 2.0, - done_y, - done_w, - btn_h, - cursor, - ); + let done_cursor = + helpers::focus_cursor(done_focused, done_h, done_x, done_y, done_w, btn_h, cursor); common::push_button_scrolling( &mut elements, done_cursor, - cx - done_w / 2.0, + done_x, done_y, done_w, btn_h, @@ -2670,13 +2715,14 @@ mod tests { assert!(key_bindings.is_default(Action::Jump)); } - /// A grid of one `Pair` row at 800x600: the left widget spans x 245..395 - /// and the right one 405..555, both at y 300. + /// An options list of one `Pair` row at 800x600: the left widget spans x + /// 245..395 and the right one 405..555, both across [`ROW_Y`]. + const ROW_Y: f32 = 50.0; + struct Grid { menu: MainMenu, key_bindings: KeyBindings, rows: Vec>, - height: f32, nav: Vec<(&'static str, Screen)>, sliders: Vec<(&'static str, f32)>, disabled: Vec<&'static str>, @@ -2689,7 +2735,6 @@ mod tests { menu: test_menu("pomme-options-focus-test", &mut key_bindings), key_bindings, rows: vec![OptRow::Pair(left, right)], - height: 600.0, nav: Vec::new(), sliders: Vec::new(), disabled: Vec::new(), @@ -2706,7 +2751,7 @@ mod tests { let text_width = |_: &str, _: f32| 0.0; self.menu.build_options_grid( 800.0, - self.height, + 600.0, input, "Test", Screen::Main, @@ -2714,7 +2759,7 @@ mod tests { &self.nav, &self.sliders, &self.disabled, - false, + true, &[], &text_width, &self.key_bindings, @@ -2727,7 +2772,7 @@ mod tests { } fn click(x: f32) -> MenuInput { - click_at(x, 300.0) + click_at(x, ROW_Y) } fn click_at(x: f32, y: f32) -> MenuInput { @@ -2798,7 +2843,7 @@ mod tests { assert_eq!(grid.menu.focus, Some(0)); let hover_second = MenuInput { - cursor: (450.0, 300.0), + cursor: (450.0, ROW_Y), ..Default::default() }; let result = grid.frame(&hover_second); @@ -2977,45 +3022,48 @@ mod tests { .collect() } - #[test] - fn a_trailing_centre_row_lifts_the_grid_only_when_it_would_not_clear_done() { + /// The Options screen's button frames `w` wide at 800 by `sh`. + fn options_frames(menu: &mut MainMenu, sh: f32, w: f32) -> Vec<(f32, f32)> { + let text_width = |_: &str, _: f32| 0.0; + let key_bindings = KeyBindings::default(); let idle = MenuInput::default(); - let mut plain = Grid::new("First", "Second"); - let mut hanging = Grid::new("First", "Second"); - hanging.rows.push(OptRow::Center("Third")); - - // Room to spare: the grid stays put and the row sits one pitch below. - let before = frames(&plain.frame(&idle), 150.0); - let after = frames(&hanging.frame(&idle), 150.0); - assert_eq!(after[..2], before[..]); - assert_eq!(after[2], (325.0, before[0].1 + 25.0)); - - // Too short: the grid moves up until the row clears Done by the gap - // rows keep between them. - plain.height = 120.0; - hanging.height = 120.0; - let short = hanging.frame(&idle); - let done_y = frames(&short, 200.0)[0].1; - let rows = frames(&short, 150.0); - assert_eq!(rows[2].1 + BTN_H + 5.0, done_y); - assert_eq!(rows[0].1 + 25.0, rows[2].1); - assert!(rows[0].1 < frames(&plain.frame(&idle), 150.0)[0].1); + frames( + &menu.build_options(800.0, sh, &idle, &text_width, &key_bindings), + w, + ) + } + + #[test] + fn options_lays_out_as_its_header_and_footer_layout_does() { + let mut key_bindings = KeyBindings::default(); + let mut menu = test_menu("pomme-options-layout-test", &mut key_bindings); + + let rows = options_frames(&mut menu, 600.0, 150.0); + // FOV and Online in the header, then the grid 30 under it. + assert_eq!(rows[..2], [(246.0, 29.0), (404.0, 29.0)]); + assert_eq!(rows[2..4], [(246.0, 91.0), (404.0, 91.0)]); + assert_eq!(rows[4].1, 115.0); + // Pomme's row, centred under the five of the grid. + assert_eq!(rows[12], (325.0, 211.0)); + assert_eq!(options_frames(&mut menu, 600.0, 200.0), [(300.0, 574.0)]); + + // Too short for that: the grid moves up until it clears the footer. + let rows = options_frames(&mut menu, 240.0, 150.0); + assert_eq!(rows[1].1, 29.0); + assert_eq!(rows[2].1, 63.0); + assert_eq!(rows[12].1, 183.0); + assert_eq!(options_frames(&mut menu, 240.0, 200.0), [(300.0, 214.0)]); } #[test] fn the_pomme_settings_button_opens_its_categories() { let mut key_bindings = KeyBindings::default(); let mut menu = test_menu("pomme-settings-entry-test", &mut key_bindings); - let text_width = |_: &str, _: f32| 0.0; - let tw: common::TextWidthFn = &text_width; - let idle = menu.build_options(800.0, 600.0, &MenuInput::default(), tw, &key_bindings); - // The only small widget centred on the screen. - let (x, y) = *frames(&idle, 150.0) - .iter() - .find(|(x, _)| *x == 325.0) + let (x, y) = *options_frames(&mut menu, 600.0, 150.0) + .last() .expect("the centred row"); let click = click_at(x + 75.0, y + BTN_H / 2.0); - menu.build_options(800.0, 600.0, &click, tw, &key_bindings); + menu.build_options(800.0, 600.0, &click, &|_, _| 0.0, &key_bindings); assert!(matches!(menu.screen, Screen::OptionsPomme)); } } diff --git a/tests/ingame/README.md b/tests/ingame/README.md index a7a763e76..c8aafbaf8 100644 --- a/tests/ingame/README.md +++ b/tests/ingame/README.md @@ -68,6 +68,10 @@ min_version = "1.20.5" that version. Gate only for what the server can't do; a script failing because of a client bug stays a failure. +A script about a Pomme extension, which vanilla has no screen or option for, +sets `pomme_only = true` the same way. The vanilla harness prints `SKIP` for +it instead of failing. + ## Wire fixtures `just wire-fixtures ...` runs `world/join` on each version with diff --git a/tests/ingame/ui/chunk_detail.toml b/tests/ingame/ui/chunk_detail.toml index c313a78d0..f52e36b80 100644 --- a/tests/ingame/ui/chunk_detail.toml +++ b/tests/ingame/ui/chunk_detail.toml @@ -2,6 +2,8 @@ # slider defaults to Off at its right end and steps down to 8 chunks at its # left. Ends back on Off, since the options save. +pomme_only = true + [[step]] press = { action = "key.menu" } diff --git a/tests/ingame/ui/pomme_settings.toml b/tests/ingame/ui/pomme_settings.toml index 87774ca10..1443ae68d 100644 --- a/tests/ingame/ui/pomme_settings.toml +++ b/tests/ingame/ui/pomme_settings.toml @@ -1,7 +1,8 @@ # Pomme's own settings (Pomme-only): a button under the Options grid opens # them, one screen per category. Performance holds Chunk Detail and Distant -# Terrain, Shaders holds Shader Pack. The other client has no such button, so -# the script fails there by design. +# Terrain, Shaders holds Shader Pack. + +pomme_only = true [[step]] press = { action = "key.menu" } diff --git a/tests/ingame/world/distant_terrain.toml b/tests/ingame/world/distant_terrain.toml index 8ec144e6e..1d7eb231b 100644 --- a/tests/ingame/world/distant_terrain.toml +++ b/tests/ingame/world/distant_terrain.toml @@ -1,8 +1,9 @@ # Distant Terrain keeps every chunk seen and draws them past the loaded # ones: a tower is kept as soon as its chunk is lit, still shows on the # horizon when left 200 blocks behind at Render Distance 2, comes back -# after leaving the view, and goes with the option. Pomme-only (the vanilla -# harness has no Distant Terrain), so it fails there by design. +# after leaving the view, and goes with the option. Pomme-only. + +pomme_only = true [[step]] wait_ms = 2000 From c0391eaeb12ad07551550ac0e7fd74cce083f60c Mon Sep 17 00:00:00 2001 From: Purdze <29306641+Purdze@users.noreply.github.com> Date: Wed, 18 Nov 2026 14:03:21 +0000 Subject: [PATCH 3/5] rename the options builder's header_footer flag to options_list --- pomme-client/src/ui/menu/options.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pomme-client/src/ui/menu/options.rs b/pomme-client/src/ui/menu/options.rs index a8c2b04f3..016249356 100644 --- a/pomme-client/src/ui/menu/options.rs +++ b/pomme-client/src/ui/menu/options.rs @@ -12,9 +12,7 @@ use crate::ui::text::TextSpan; const COLLISION_STRIPE: [f32; 4] = common::rgb(0xffff00); /// A row in a vanilla-style options list: 25px pitch, a 310px `Big` widget, or -/// two 150px widgets per `Pair` (`PairLeft` for an odd trailing widget). On -/// the Options screen itself the first row is its header's and the rest are -/// its grid's (see [`RootLayout`]). +/// two 150px widgets per `Pair` (`PairLeft` for an odd trailing widget). pub(super) enum OptRow<'a> { Header(&'a str), Big(&'a str), @@ -1452,6 +1450,10 @@ impl MainMenu { ) } + /// An options screen: `rows` under its title and over Done. With + /// `options_list` they scroll as an `OptionsList` between the shared + /// header and footer; without, they take the Options screen's own layout + /// ([`RootLayout`]), the first in its header and the rest in its grid. #[allow(clippy::too_many_arguments)] pub(super) fn build_options_grid( &mut self, @@ -1464,7 +1466,7 @@ impl MainMenu { nav: &[(&str, Screen)], sliders: &[(&'static str, f32)], disabled: &[&str], - header_footer: bool, + options_list: bool, tooltips: &[(&str, &str)], text_width_fn: common::TextWidthFn, key_bindings: &KeyBindings, @@ -1483,7 +1485,7 @@ impl MainMenu { let lh = 9.0 * gs; let btn_dy = (row_h - btn_h) / 2.0; let cx = sw / 2.0; - let root = (!header_footer) + let root = (!options_list) .then(|| RootLayout::new(common::gui_size(sh, gs), rows.len().saturating_sub(1))); let done_w = 200.0 * gs; let (left_x, right_x, center_x, done_x) = if root.is_some() { @@ -1535,7 +1537,7 @@ impl MainMenu { done_y = chrome.done_y; } - let content_pad = if header_footer { 4.0 * gs } else { 0.0 }; + let content_pad = if options_list { 4.0 * gs } else { 0.0 }; // Vertical advance per row (vanilla OptionsList: 25px pitch; headers pad // above). let header_pad_top = |i: usize| if i == 0 { 0.0 } else { 2.0 * lh }; @@ -1552,7 +1554,7 @@ impl MainMenu { .sum(); let content_h = content_bottom - content_top; let list_h = grid_h + content_pad; - let scrollable = header_footer && list_h > content_h; + let scrollable = options_list && list_h > content_h; // `AbstractSelectionList.scrollBarX`: 8 right of the 310-wide rows. let scrollbar_x = cx + 163.0 * gs; if scrollable { @@ -1581,7 +1583,7 @@ impl MainMenu { time_secs: self.created.elapsed().as_secs_f64(), }; - if header_footer { + if options_list { elements.push(MenuElement::ScissorPush { x: 0.0, y: content_top, @@ -1912,7 +1914,7 @@ impl MainMenu { self.settings_dirty = true; } - if header_footer { + if options_list { elements.push(MenuElement::ScissorPop); } From 3d3e54ca349762279b30adeaf70fe277a78c8a64 Mon Sep 17 00:00:00 2001 From: Purdze <29306641+Purdze@users.noreply.github.com> Date: Wed, 18 Nov 2026 14:27:44 +0000 Subject: [PATCH 4/5] add a nightly builds option that updates the client to the latest nightly build --- pomme-client/src/app/install.rs | 21 ++-- pomme-client/src/ui/menu/mod.rs | 27 +++++ pomme-client/src/ui/menu/options.rs | 84 +++++++++++-- pomme-client/src/update.rs | 30 +++-- pomme-install/src/client.rs | 181 +++++++++++++++++++++++----- tests/ingame/ui/pomme_settings.toml | 63 +++++++++- 6 files changed, 342 insertions(+), 64 deletions(-) diff --git a/pomme-client/src/app/install.rs b/pomme-client/src/app/install.rs index 704710690..04aabb84c 100644 --- a/pomme-client/src/app/install.rs +++ b/pomme-client/src/app/install.rs @@ -70,16 +70,19 @@ impl Install { let state = Arc::clone(&self.state); let report = move |progress| *state.lock().unwrap() = State::Running(progress); let job: Pin + Send>> = match self.job { - Job::Update => Box::pin(async move { - match crate::update::run(&report).await { - Ok(Some(exe)) => State::Updated(exe), - Ok(None) => State::Done, - Err(reason) => { - tracing::warn!("Skipping the update: {reason}"); - State::Done + Job::Update => { + let channel = core.menu.update_channel(); + Box::pin(async move { + match crate::update::run(channel, &report).await { + Ok(Some(exe)) => State::Updated(exe), + Ok(None) => State::Done, + Err(reason) => { + tracing::warn!("Skipping the update: {reason}"); + State::Done + } } - } - }), + }) + } Job::Assets => { let dirs = core.data_dirs.clone(); let version = core.version.clone(); diff --git a/pomme-client/src/ui/menu/mod.rs b/pomme-client/src/ui/menu/mod.rs index 774709181..5a7a0103d 100644 --- a/pomme-client/src/ui/menu/mod.rs +++ b/pomme-client/src/ui/menu/mod.rs @@ -16,6 +16,7 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use std::time::Instant; +use pomme_install::client::Channel; use serde::{Deserialize, Serialize}; use winit::keyboard::KeyCode; @@ -85,6 +86,8 @@ struct Settings { vignette: bool, #[serde(default = "default_true")] entity_shadows: bool, + #[serde(default)] + nightly_builds: bool, #[serde(default = "default_true")] show_autosave_indicator: bool, #[serde(default = "default_true")] @@ -336,6 +339,7 @@ impl Default for Settings { show_autosave_indicator: true, vignette: true, entity_shadows: true, + nightly_builds: false, vsync: true, max_framerate: 120, inactivity_fps_limit: InactivityFpsLimit::default(), @@ -633,6 +637,7 @@ enum Screen { OptionsPomme, OptionsPommePerformance, OptionsPommeShaders, + OptionsPommeUpdates, OptionsSkinCustomization, OptionsMusicSounds, OptionsControls, @@ -661,6 +666,7 @@ impl Screen { Self::OptionsPomme => Self::OptionsPomme, Self::OptionsPommePerformance => Self::OptionsPommePerformance, Self::OptionsPommeShaders => Self::OptionsPommeShaders, + Self::OptionsPommeUpdates => Self::OptionsPommeUpdates, Self::OptionsSkinCustomization => Self::OptionsSkinCustomization, Self::OptionsMusicSounds => Self::OptionsMusicSounds, Self::OptionsControls => Self::OptionsControls, @@ -857,6 +863,8 @@ pub struct MainMenu { pub show_autosave_indicator: bool, pub vignette: bool, pub entity_shadows: bool, + /// Whether updates follow master's nightly builds (Pomme-only). + nightly_builds: bool, pub vsync: bool, pub max_framerate: u32, pub inactivity_fps_limit: InactivityFpsLimit, @@ -1033,6 +1041,7 @@ impl MainMenu { show_autosave_indicator: settings.show_autosave_indicator, vignette: settings.vignette, entity_shadows: settings.entity_shadows, + nightly_builds: settings.nightly_builds, vsync: settings.vsync, max_framerate: settings.max_framerate, inactivity_fps_limit: settings.inactivity_fps_limit, @@ -1295,6 +1304,7 @@ impl MainMenu { show_autosave_indicator: self.show_autosave_indicator, vignette: self.vignette, entity_shadows: self.entity_shadows, + nightly_builds: self.nightly_builds, vsync: self.vsync, max_framerate: self.max_framerate, inactivity_fps_limit: self.inactivity_fps_limit, @@ -1406,6 +1416,15 @@ impl MainMenu { self.save_settings(key_bindings); } + /// The builds this client updates to at its next start. + pub fn update_channel(&self) -> Channel { + if self.nightly_builds { + Channel::Nightly + } else { + Channel::Stable + } + } + pub fn open_options(&mut self, key_bindings: &KeyBindings) { // Stale after a disconnect; the in-game path re-sets it every frame. self.server_render_distance = 0; @@ -1432,6 +1451,7 @@ impl MainMenu { | Screen::OptionsPomme | Screen::OptionsPommePerformance | Screen::OptionsPommeShaders + | Screen::OptionsPommeUpdates | Screen::OptionsSkinCustomization | Screen::OptionsMusicSounds | Screen::OptionsControls @@ -1738,6 +1758,13 @@ impl MainMenu { &text_width_fn, key_bindings, ), + Screen::OptionsPommeUpdates => self.build_options_pomme_updates( + screen_w, + screen_h, + input, + &text_width_fn, + key_bindings, + ), Screen::OptionsSkinCustomization => { self.build_options_skin(screen_w, screen_h, input, &text_width_fn, key_bindings) } diff --git a/pomme-client/src/ui/menu/options.rs b/pomme-client/src/ui/menu/options.rs index 016249356..31b0a60d8 100644 --- a/pomme-client/src/ui/menu/options.rs +++ b/pomme-client/src/ui/menu/options.rs @@ -193,6 +193,7 @@ const MENU_BACKGROUND_BLUR: &str = "Menu Background Blur:"; const CHUNK_DETAIL: &str = "Chunk Detail:"; const DISTANT_TERRAIN: &str = "Distant Terrain:"; const SHADER_PACK: &str = "Shader Pack:"; +const NIGHTLY_BUILDS: &str = "Nightly Builds:"; const CHUNK_FADE: &str = "Chunk Fade:"; const INACTIVITY_FPS_LIMIT: &str = "Reduce fps when:"; @@ -566,10 +567,15 @@ impl MainMenu { text_width_fn: common::TextWidthFn, key_bindings: &KeyBindings, ) -> MainMenuResult { - let rows = [OptRow::Pair("Performance...", "Shaders...")]; + let mut rows = vec![OptRow::Pair("Performance...", "Shaders...")]; + // Phones and tablets don't update themselves (`update::enabled`). + if cfg!(not(mobile)) { + rows.push(OptRow::PairLeft("Updates...")); + } let nav: &[(&str, Screen)] = &[ ("Performance...", Screen::OptionsPommePerformance), ("Shaders...", Screen::OptionsPommeShaders), + ("Updates...", Screen::OptionsPommeUpdates), ]; self.build_options_grid( sw, @@ -662,6 +668,39 @@ impl MainMenu { ) } + /// Pomme Settings' Updates category (Pomme-only). + pub(super) fn build_options_pomme_updates( + &mut self, + sw: f32, + sh: f32, + input: &MenuInput, + text_width_fn: common::TextWidthFn, + key_bindings: &KeyBindings, + ) -> MainMenuResult { + let nightly_label = format!("{NIGHTLY_BUILDS} {}", on_off(self.nightly_builds)); + let rows = [OptRow::PairLeft(&nightly_label)]; + let tooltips: &[(&str, &str)] = &[( + NIGHTLY_BUILDS, + "Updates to each night's build when the game starts, not only to releases. Nightly \ + builds are less tested.", + )]; + self.build_options_grid( + sw, + sh, + input, + "Updates", + Screen::OptionsPomme, + &rows, + &[], + &[], + &[], + true, + tooltips, + text_width_fn, + key_bindings, + ) + } + pub(super) fn build_options_controls( &mut self, sw: f32, @@ -1739,6 +1778,10 @@ impl MainMenu { self.cloud_mode = self.cloud_mode.cycle(); self.save_settings(key_bindings); } + if label.starts_with(NIGHTLY_BUILDS) { + self.nightly_builds = !self.nightly_builds; + self.save_settings(key_bindings); + } if label.starts_with(SHADER_PACK) { self.shader_pack = next_shader_pack(&self.shader_packs_dir, self.shader_pack.as_deref()); @@ -2808,16 +2851,26 @@ mod tests { } } - #[test] - fn entity_shadows_toggle_preserves_saved_key_bindings() { - let dir = - std::env::temp_dir().join(format!("pomme-entity-shadows-{}", uuid::Uuid::new_v4())); + /// A grid whose options save to a folder of its own, gone with the guard. + fn saving_grid(left: &'static str) -> (Grid, impl Drop) { + let dir = std::env::temp_dir().join(format!("pomme-options-{}", uuid::Uuid::new_v4())); std::fs::create_dir(&dir).unwrap(); - let _cleanup = scopeguard::guard((), |_| { + let mut grid = Grid::new(left, "Other"); + grid.menu.settings_dir = dir.clone(); + let cleanup = scopeguard::guard((), move |_| { let _ = std::fs::remove_dir_all(&dir); }); - let mut grid = Grid::new("Entity Shadows: ON", "Other"); - grid.menu.settings_dir = dir.clone(); + (grid, cleanup) + } + + fn saved_settings(grid: &Grid) -> Settings { + let saved = std::fs::read_to_string(grid.menu.settings_dir.join("options.json")).unwrap(); + serde_json::from_str(&saved).unwrap() + } + + #[test] + fn entity_shadows_toggle_preserves_saved_key_bindings() { + let (mut grid, _cleanup) = saving_grid("Entity Shadows: ON"); grid.menu.entity_shadows = true; grid.key_bindings .set(Action::Jump, vec![InputKey::Keyboard(KeyCode::KeyJ)]); @@ -2826,9 +2879,7 @@ mod tests { for enabled in [false, true] { assert!(grid.frame(&click(300.0)).clicked_button); assert_eq!(grid.menu.entity_shadows, enabled); - let saved: Settings = - serde_json::from_str(&std::fs::read_to_string(dir.join("options.json")).unwrap()) - .unwrap(); + let saved = saved_settings(&grid); assert_eq!(saved.entity_shadows, enabled); assert_eq!( serde_json::to_value(&saved.key_bindings).unwrap(), @@ -2837,6 +2888,16 @@ mod tests { } } + #[test] + fn the_nightly_builds_toggle_moves_the_update_channel_and_is_saved() { + let (mut grid, _cleanup) = saving_grid("Nightly Builds: OFF"); + assert_eq!(grid.menu.update_channel(), Channel::Stable); + + assert!(grid.frame(&click(300.0)).clicked_button); + assert_eq!(grid.menu.update_channel(), Channel::Nightly); + assert!(saved_settings(&grid).nightly_builds); + } + #[test] fn mouse_focus_persists_until_another_enabled_option_is_clicked() { let mut grid = Grid::new("First", "Second"); @@ -3004,6 +3065,7 @@ mod tests { menu.build_options_pomme(sw, sh, &input, tw, &key_bindings); menu.build_options_pomme_performance(sw, sh, &input, tw, &key_bindings); menu.build_options_pomme_shaders(sw, sh, &input, tw, &key_bindings); + menu.build_options_pomme_updates(sw, sh, &input, tw, &key_bindings); menu.build_options_controls(sw, sh, &input, tw, &key_bindings); menu.build_options_chat(sw, sh, &input, tw, &key_bindings); menu.build_options_accessibility(sw, sh, &input, tw, &key_bindings); diff --git a/pomme-client/src/update.rs b/pomme-client/src/update.rs index 13597159b..2101a96e0 100644 --- a/pomme-client/src/update.rs +++ b/pomme-client/src/update.rs @@ -1,14 +1,16 @@ -//! Keeps a release build current: before the menu, a newer `client-v*` -//! release replaces this build's files where they are, and the client +//! Keeps a published build current: before the menu, a newer build on its +//! channel replaces this build's files where they are, and the client //! relaunches into it. use std::path::{Path, PathBuf}; +use std::sync::OnceLock; use std::time::Duration; +use pomme_install::client::Channel; use pomme_install::{Progress, client}; -/// The release this binary was built as (`release-client.yml` sets it); dev -/// and local builds have none and never update. +/// The build this binary was published as (`release-client.yml` sets it); +/// dev and local builds have none and never update. const RELEASE: Option<&str> = option_env!("POMME_RELEASE"); /// Where a new release unpacks before its files move into place. const STAGING: &str = ".pomme-update"; @@ -18,9 +20,14 @@ const REPLACED: &str = "old"; /// Offline, the check gives up this soon rather than hold the menu back. const CHECK_TIMEOUT: Duration = Duration::from_secs(5); -/// This build's `x.y.z` for display, or "dev" for one that isn't a release. +/// This build's version for display, or "dev" for one that wasn't published. pub fn version() -> &'static str { - RELEASE.and_then(client::release_version).unwrap_or("dev") + static VERSION: OnceLock = OnceLock::new(); + VERSION.get_or_init(|| { + RELEASE + .and_then(client::Build::parse) + .map_or_else(|| "dev".to_owned(), |build| build.to_string()) + }) } /// Whether this launch checks for a newer release. Not when the old launcher @@ -37,22 +44,23 @@ pub fn enabled(args: &crate::LaunchArgs) -> bool { && args.chunk_bench.is_none() } -/// Installs a newer release over this one, returning the binary to relaunch, -/// or `None` when this build is current. +/// Installs `channel`'s newest build over this one if it is newer, returning +/// the binary to relaunch, or `None` when this build is current. pub async fn run( + channel: Channel, on_progress: &(dyn Fn(Progress) + Send + Sync), ) -> Result, String> { let Some(ours) = RELEASE else { return Ok(None); }; let http = crate::net::http::client(); - let release = tokio::time::timeout(CHECK_TIMEOUT, client::latest_release(http)) + let release = tokio::time::timeout(CHECK_TIMEOUT, client::latest_release(http, channel)) .await .map_err(|_| "timed out".to_owned())??; - if !client::is_newer(ours, &release.tag_name) { + if !client::is_newer(ours, release.id()) { return Ok(None); } - tracing::info!("Updating from {ours} to {}", release.tag_name); + tracing::info!("Updating from {ours} to {}", release.id()); if let Some(appimage) = appimage() { let file = client::download(http, &release, client::APPIMAGE, on_progress).await?; replace_appimage(&file, &appimage).await?; diff --git a/pomme-install/src/client.rs b/pomme-install/src/client.rs index 7d51841a4..eda188162 100644 --- a/pomme-install/src/client.rs +++ b/pomme-install/src/client.rs @@ -1,6 +1,7 @@ -//! The Pomme client's own builds, published as `client-v*` GitHub releases: -//! finding the newest, and downloading this platform's zip checked against the -//! release's `sha256sums.txt`. +//! The Pomme client's own builds, published as GitHub releases: a `client-v*` +//! one per release and a rolling `nightly` one for master's latest build. +//! Finding the newest on a channel, and downloading this platform's zip +//! checked against the release's `sha256sums.txt`. use std::path::Path; @@ -12,15 +13,83 @@ use crate::{Progress, get}; /// Newest first; listed rather than `/releases/latest`, which held the /// launcher's releases before the client's. const RELEASES_URL: &str = "https://api.github.com/repos/PommeMC/Client/releases?per_page=30"; -const TAG_PREFIX: &str = "client-v"; +const RELEASE_PREFIX: &str = "client-v"; +const NIGHTLY_PREFIX: &str = "nightly-"; +/// The tag of the one release each nightly build replaces. +const NIGHTLY_TAG: &str = "nightly"; const CHECKSUMS_ASSET: &str = "sha256sums.txt"; +/// Which builds a client updates to. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Channel { + /// Releases only. + Stable, + /// Master's latest build too, whichever is newer. + Nightly, +} + +/// A published build, ordered oldest first: release `x.y.z` from +/// `client-vx.y.z+`, or the `n`th build of master after it from +/// `nightly-x.y.z.n+`. A nightly is newer than the release it +/// follows and older than the next one, which is cut from a later master. +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub struct Build { + version: (u32, u32, u32), + /// 0 for a release. + nightly: u32, +} + +impl Build { + pub fn parse(id: &str) -> Option { + let (core, is_nightly) = match id.strip_prefix(RELEASE_PREFIX) { + Some(core) => (core, false), + None => (id.strip_prefix(NIGHTLY_PREFIX)?, true), + }; + let core = core.split_once('+').map_or(core, |(core, _)| core); + let mut parts = core.split('.').map(str::parse); + let version = ( + parts.next()?.ok()?, + parts.next()?.ok()?, + parts.next()?.ok()?, + ); + let nightly = if is_nightly { + parts.next()?.ok().filter(|n| *n > 0)? + } else { + 0 + }; + parts.next().is_none().then_some(Self { version, nightly }) + } +} + +impl std::fmt::Display for Build { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let (major, minor, patch) = self.version; + write!(f, "{major}.{minor}.{patch}")?; + if self.nightly > 0 { + write!(f, "-nightly.{}", self.nightly)?; + } + Ok(()) + } +} + #[derive(Deserialize)] pub struct Release { - pub tag_name: String, + tag_name: String, + name: Option, assets: Vec, } +impl Release { + /// What names the build: the tag, or under the rolling nightly tag the + /// release's name. + pub fn id(&self) -> &str { + match (self.tag_name.as_str(), &self.name) { + (NIGHTLY_TAG, Some(name)) => name, + (tag, _) => tag, + } + } +} + #[derive(Deserialize)] struct Asset { name: String, @@ -41,41 +110,32 @@ pub fn platform_zip() -> Result<&'static str, String> { } } -/// Whether release `theirs` is a later build than `ours`, by the `x.y.z` of -/// `client-vx.y.z+`; never for a tag that doesn't parse. +/// Whether `theirs` is a later build than `ours`; never for an id that +/// doesn't parse. pub fn is_newer(ours: &str, theirs: &str) -> bool { - match (release_core(ours), release_core(theirs)) { + match (Build::parse(ours), Build::parse(theirs)) { (Some(ours), Some(theirs)) => theirs > ours, _ => false, } } -/// The `x.y.z` of a `client-vx.y.z+` tag. -pub fn release_version(tag: &str) -> Option<&str> { - let core = tag.strip_prefix(TAG_PREFIX)?; - Some(core.split_once('+').map_or(core, |(core, _)| core)) -} - -fn release_core(tag: &str) -> Option<(u32, u32, u32)> { - let mut parts = release_version(tag)?.split('.').map(str::parse); - let version = ( - parts.next()?.ok()?, - parts.next()?.ok()?, - parts.next()?.ok()?, - ); - parts.next().is_none().then_some(version) -} - -pub async fn latest_release(http: &reqwest::Client) -> Result { +pub async fn latest_release(http: &reqwest::Client, channel: Channel) -> Result { let releases: Vec = get(http, RELEASES_URL) .await? .json() .await .map_err(|e| e.to_string())?; + newest(releases, channel).ok_or_else(|| "No client release found".to_owned()) +} + +/// The newest build among `releases` that `channel` takes. +fn newest(releases: Vec, channel: Channel) -> Option { releases .into_iter() - .find(|r| r.tag_name.starts_with(TAG_PREFIX)) - .ok_or_else(|| "No client release found".to_owned()) + .filter_map(|release| Some((Build::parse(release.id())?, release))) + .filter(|(build, _)| channel == Channel::Nightly || build.nightly == 0) + .max_by_key(|(build, _)| *build) + .map(|(_, release)| release) } /// File `name` of `release`, refused unless it matches the release's @@ -91,7 +151,7 @@ pub async fn download( .assets .iter() .find(|a| a.name == name) - .ok_or_else(|| format!("Release {} has no {name}", release.tag_name)) + .ok_or_else(|| format!("Release {} has no {name}", release.id())) }; let sums = get(http, &asset(CHECKSUMS_ASSET)?.browser_download_url) .await? @@ -179,10 +239,67 @@ mod tests { } #[test] - fn the_version_drops_the_minecraft_part() { - assert_eq!(release_version("client-v0.2.8+26.2"), Some("0.2.8")); - assert_eq!(release_version("client-v0.2.8"), Some("0.2.8")); - assert_eq!(release_version("launcher-v0.1.2"), None); + fn a_nightly_sits_between_the_release_it_follows_and_the_next() { + let (release, nightly) = ("client-v0.2.12+26.2", "nightly-0.2.12.345+26.2"); + assert!(is_newer(release, nightly)); + assert!(is_newer(nightly, "nightly-0.2.12.346+26.2")); + assert!(is_newer(nightly, "client-v0.2.13+26.2")); + assert!(!is_newer(nightly, release)); + assert!(!is_newer(nightly, nightly)); + // A nightly names the run that built it. + assert!(!is_newer(release, "nightly-0.2.12+26.2")); + assert!(!is_newer(release, "nightly-0.2.12.0+26.2")); + assert!(!is_newer(release, "nightly")); + } + + #[test] + fn a_build_shows_as_its_version() { + let shown = |id| Build::parse(id).map(|build| build.to_string()); + assert_eq!(shown("client-v0.2.8+26.2").as_deref(), Some("0.2.8")); + assert_eq!(shown("client-v0.2.8").as_deref(), Some("0.2.8")); + assert_eq!( + shown("nightly-0.2.8.345+26.2").as_deref(), + Some("0.2.8-nightly.345") + ); + assert_eq!(shown("launcher-v0.1.2"), None); + } + + fn releases(json: &str) -> Vec { + serde_json::from_str(json).unwrap() + } + + #[test] + fn a_channel_takes_its_newest_build() { + // As GitHub lists them: the rolling nightly, recreated each night, + // then the releases newest first. + let listed = r#"[ + {"tag_name": "nightly", "name": "nightly-0.2.12.345+26.2", "assets": []}, + {"tag_name": "client-v0.2.12+26.2", "name": "client-v0.2.12+26.2", "assets": []}, + {"tag_name": "client-v0.2.11+26.2", "name": null, "assets": []}, + {"tag_name": "launcher-v0.1.2", "name": null, "assets": []} + ]"#; + let id = |channel| newest(releases(listed), channel).map(|r| r.id().to_owned()); + assert_eq!(id(Channel::Stable).as_deref(), Some("client-v0.2.12+26.2")); + assert_eq!( + id(Channel::Nightly).as_deref(), + Some("nightly-0.2.12.345+26.2") + ); + } + + #[test] + fn the_nightly_channel_takes_a_release_newer_than_the_nightly() { + let listed = r#"[ + {"tag_name": "client-v0.2.13+26.2", "name": null, "assets": []}, + {"tag_name": "nightly", "name": "nightly-0.2.12.345+26.2", "assets": []} + ]"#; + let newest = newest(releases(listed), Channel::Nightly).unwrap(); + assert_eq!(newest.id(), "client-v0.2.13+26.2"); + } + + #[test] + fn no_release_is_no_build() { + let listed = r#"[{"tag_name": "launcher-v0.1.2", "name": null, "assets": []}]"#; + assert!(newest(releases(listed), Channel::Nightly).is_none()); } #[test] diff --git a/tests/ingame/ui/pomme_settings.toml b/tests/ingame/ui/pomme_settings.toml index 1443ae68d..39dcc03bd 100644 --- a/tests/ingame/ui/pomme_settings.toml +++ b/tests/ingame/ui/pomme_settings.toml @@ -1,6 +1,6 @@ # Pomme's own settings (Pomme-only): a button under the Options grid opens # them, one screen per category. Performance holds Chunk Detail and Distant -# Terrain, Shaders holds Shader Pack. +# Terrain, Shaders holds Shader Pack, Updates holds Nightly Builds. pomme_only = true @@ -119,6 +119,67 @@ mouse_up = "left" [[step]] wait_ms = 300 +[[step]] +cursor_to_button = "Updates..." + +[[step]] +mouse_down = "left" + +[[step]] +mouse_up = "left" + +[[step]] +wait_ms = 300 + +[[step]] +cursor_to_button = "Nightly Builds: OFF" + +[[step]] +wait_ms = 300 + +[[step]] +screenshot = "updates" + +[[step]] +mouse_down = "left" + +[[step]] +mouse_up = "left" + +[[step]] +cursor = [213, 200] + +[[step]] +wait_ms = 300 + +[[step]] +screenshot = "nightly_on" + +# Back off, since the options save. +[[step]] +cursor_to_button = "Nightly Builds: ON" + +[[step]] +mouse_down = "left" + +[[step]] +mouse_up = "left" + +[[step]] +wait_ms = 300 + +[[step]] +cursor_to_button = "Done" + +[[step]] +mouse_down = "left" + +[[step]] +mouse_up = "left" + +[[step]] +wait_ms = 300 + # Back out of Pomme Settings, then Options. [[step]] cursor_to_button = "Done" From f49b77f4272e4216a77c1fb682b35ba422968278 Mon Sep 17 00:00:00 2001 From: Purdze <29306641+Purdze@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:27:36 +0000 Subject: [PATCH 5/5] add a --no-update launch flag and pin the newest build to the highest version --- pomme-client/src/args.rs | 5 +++++ pomme-client/src/update.rs | 23 +++++++++++++++++------ pomme-install/src/client.rs | 34 ++++++++++++++++++++++++++-------- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/pomme-client/src/args.rs b/pomme-client/src/args.rs index 2b892d6b8..13d6a3e55 100644 --- a/pomme-client/src/args.rs +++ b/pomme-client/src/args.rs @@ -30,6 +30,11 @@ pub struct LaunchArgs { #[arg(long)] pub launch_token: Option, + /// Starts this build as it is, without updating it first: the way to the + /// Nightly Builds option when the newest build won't start. + #[arg(long)] + pub no_update: bool, + #[arg(long)] pub assets_dir: Option, diff --git a/pomme-client/src/update.rs b/pomme-client/src/update.rs index 2101a96e0..d7a9060d7 100644 --- a/pomme-client/src/update.rs +++ b/pomme-client/src/update.rs @@ -30,18 +30,20 @@ pub fn version() -> &'static str { }) } -/// Whether this launch checks for a newer release. Not when the old launcher -/// started it: that keeps its own copies under `launcher/clients`. +/// Whether this launch checks for a newer build: only a published one's. pub fn enabled(args: &crate::LaunchArgs) -> bool { + RELEASE.is_some() && cfg!(not(mobile)) && wanted(args) +} + +/// Whether `args` leave the update on. Not when the old launcher started the +/// client: that keeps its own copies under `launcher/clients`. +fn wanted(args: &crate::LaunchArgs) -> bool { #[cfg(feature = "test-harness")] if args.harness_script.is_some() { return false; } // A `--chunk-bench` run measures the binary it was started with. - RELEASE.is_some() - && cfg!(not(mobile)) - && args.launch_token.is_none() - && args.chunk_bench.is_none() + !args.no_update && args.launch_token.is_none() && args.chunk_bench.is_none() } /// Installs `channel`'s newest build over this one if it is newer, returning @@ -174,6 +176,15 @@ mod tests { use super::*; + #[test] + fn a_launch_can_turn_the_update_off() { + let wanted = |words| wanted(&crate::LaunchArgs::from_words(words).unwrap()); + assert!(wanted("")); + assert!(!wanted("--no-update")); + assert!(!wanted("--launch-token abc")); + assert!(!wanted("--chunk-bench 16")); + } + fn release_zip(files: &[(&str, &str)]) -> Vec { let mut zip = zip::ZipWriter::new(std::io::Cursor::new(Vec::new())); for (name, body) in files { diff --git a/pomme-install/src/client.rs b/pomme-install/src/client.rs index eda188162..32e7cece2 100644 --- a/pomme-install/src/client.rs +++ b/pomme-install/src/client.rs @@ -264,8 +264,10 @@ mod tests { assert_eq!(shown("launcher-v0.1.2"), None); } - fn releases(json: &str) -> Vec { - serde_json::from_str(json).unwrap() + /// The id of the newest build `channel` takes from GitHub's `listed`. + fn newest_id(listed: &str, channel: Channel) -> Option { + let releases: Vec = serde_json::from_str(listed).unwrap(); + newest(releases, channel).map(|release| release.id().to_owned()) } #[test] @@ -278,28 +280,44 @@ mod tests { {"tag_name": "client-v0.2.11+26.2", "name": null, "assets": []}, {"tag_name": "launcher-v0.1.2", "name": null, "assets": []} ]"#; - let id = |channel| newest(releases(listed), channel).map(|r| r.id().to_owned()); - assert_eq!(id(Channel::Stable).as_deref(), Some("client-v0.2.12+26.2")); assert_eq!( - id(Channel::Nightly).as_deref(), + newest_id(listed, Channel::Stable).as_deref(), + Some("client-v0.2.12+26.2") + ); + assert_eq!( + newest_id(listed, Channel::Nightly).as_deref(), Some("nightly-0.2.12.345+26.2") ); } + #[test] + fn the_newest_build_is_the_highest_however_they_are_listed() { + let listed = r#"[ + {"tag_name": "client-v0.2.11+26.2", "name": null, "assets": []}, + {"tag_name": "client-v0.2.12+26.2", "name": null, "assets": []} + ]"#; + assert_eq!( + newest_id(listed, Channel::Stable).as_deref(), + Some("client-v0.2.12+26.2") + ); + } + #[test] fn the_nightly_channel_takes_a_release_newer_than_the_nightly() { let listed = r#"[ {"tag_name": "client-v0.2.13+26.2", "name": null, "assets": []}, {"tag_name": "nightly", "name": "nightly-0.2.12.345+26.2", "assets": []} ]"#; - let newest = newest(releases(listed), Channel::Nightly).unwrap(); - assert_eq!(newest.id(), "client-v0.2.13+26.2"); + assert_eq!( + newest_id(listed, Channel::Nightly).as_deref(), + Some("client-v0.2.13+26.2") + ); } #[test] fn no_release_is_no_build() { let listed = r#"[{"tag_name": "launcher-v0.1.2", "name": null, "assets": []}]"#; - assert!(newest(releases(listed), Channel::Nightly).is_none()); + assert_eq!(newest_id(listed, Channel::Nightly), None); } #[test]