Use physical Ctrl state for stack dropping, not toggle sprint
This commit is contained in:
@@ -4170,7 +4170,8 @@ impl Game<'_> {
|
||||
(Some(n), _) => self.menu_click(Some(slot), n as i32, Input::Swap),
|
||||
(None, KeyCode::KeyF) => self.menu_click(Some(slot), 40, Input::Swap),
|
||||
(None, KeyCode::KeyQ) => {
|
||||
let all = self.keys.contains(&KeyCode::ControlLeft);
|
||||
let all = self.physical_keys.contains(&KeyCode::ControlLeft)
|
||||
|| self.physical_keys.contains(&KeyCode::ControlRight);
|
||||
self.menu_click(Some(slot), i32::from(all), Input::Throw)
|
||||
}
|
||||
_ => false,
|
||||
@@ -8001,7 +8002,8 @@ impl Game<'_> {
|
||||
self.using = None;
|
||||
}
|
||||
KeyCode::KeyQ if self.screen == Screen::Playing => {
|
||||
let all = self.keys.contains(&KeyCode::ControlLeft);
|
||||
let all = self.physical_keys.contains(&KeyCode::ControlLeft)
|
||||
|| self.physical_keys.contains(&KeyCode::ControlRight);
|
||||
self.drop_held(all);
|
||||
}
|
||||
KeyCode::Digit1
|
||||
|
||||
@@ -1232,14 +1232,7 @@ impl Game<'_> {
|
||||
self.playing()?;
|
||||
let all = a.pos.first() == Some(&"all");
|
||||
let before = self.held().map(|s| self.stack_value(s));
|
||||
if all {
|
||||
self.keys.insert(KeyCode::ControlLeft);
|
||||
}
|
||||
let result = self.key_pressed(KeyCode::KeyQ);
|
||||
if all {
|
||||
self.keys.remove(&KeyCode::ControlLeft);
|
||||
}
|
||||
result?;
|
||||
self.drop_held(all);
|
||||
ok(
|
||||
json!({ "ok": true, "dropped_from": before, "held": self.held().map(|s| self.stack_value(s)) }),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
"""Drop modifiers must come from physical Ctrl, not the sprint key mapping."""
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
class DropModifierPolicyTests(unittest.TestCase):
|
||||
@unittest.skipUnless(shutil.which("rustc"), "rustc is needed for the drop-policy probe")
|
||||
def test_playing_and_inventory_drop_ignore_latched_sprint(self):
|
||||
source = (ROOT / "crates/horizon-client/src/game.rs").read_text()
|
||||
inventory = source.split("fn inventory_hotkey(", 1)[1]
|
||||
playing = source.split("KeyCode::KeyQ if self.screen == Screen::Playing =>", 1)[1]
|
||||
expressions = [section.split("let all = ", 1)[1].split(";", 1)[0]
|
||||
for section in (inventory, playing)]
|
||||
program = """
|
||||
use std::collections::HashSet;
|
||||
#[derive(PartialEq, Eq, Hash)] enum KeyCode { ControlLeft, ControlRight }
|
||||
struct Game { keys: HashSet<KeyCode>, physical_keys: HashSet<KeyCode> }
|
||||
impl Game {
|
||||
fn inventory_drop_all(&self) -> bool { INVENTORY }
|
||||
fn playing_drop_all(&self) -> bool { PLAYING }
|
||||
}
|
||||
#[test]
|
||||
fn sprint_and_control_are_independent() {
|
||||
for sprint in [false, true] {
|
||||
for held in 0..4 {
|
||||
let ctrl = held != 0;
|
||||
let mut game = Game { keys: HashSet::new(), physical_keys: HashSet::new() };
|
||||
if held & 1 != 0 { game.physical_keys.insert(KeyCode::ControlLeft); }
|
||||
if held & 2 != 0 { game.physical_keys.insert(KeyCode::ControlRight); }
|
||||
if sprint { game.keys.insert(KeyCode::ControlLeft); }
|
||||
assert_eq!(game.inventory_drop_all(), ctrl, "inventory: sprint={sprint}, ctrl={ctrl}");
|
||||
assert_eq!(game.playing_drop_all(), ctrl, "playing: sprint={sprint}, ctrl={ctrl}");
|
||||
}
|
||||
}
|
||||
}
|
||||
""".replace("INVENTORY", expressions[0]).replace("PLAYING", expressions[1])
|
||||
with tempfile.TemporaryDirectory(prefix="horizon-drop-policy-") as directory:
|
||||
path = Path(directory)
|
||||
(path / "probe.rs").write_text(program)
|
||||
compiled = subprocess.run(
|
||||
["rustc", "--edition=2024", "--test", str(path / "probe.rs"), "-o", str(path / "probe")],
|
||||
capture_output=True, text=True, check=False,
|
||||
)
|
||||
self.assertEqual(compiled.returncode, 0, compiled.stderr)
|
||||
result = subprocess.run([str(path / "probe")], capture_output=True, text=True, check=False)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user