Merge pull request #2797 from levzzz5154/fix/screen-cursor-centre
🤖 Agent: read the diff at 1d693cb3c: `MouseHandler.grabMouse`/`releaseMouse`: the cursor is centred only when the grab state changes; fixture test updated. verify green, parity green on this head (merged into main), merges cleanly.
This commit is contained in:
@@ -27,6 +27,17 @@ def method(source, name):
|
||||
return source[start:end]
|
||||
|
||||
|
||||
def function(source, name):
|
||||
start = source.index(f"pub fn {name}(")
|
||||
opening = source.index("{", start)
|
||||
depth = 1
|
||||
end = opening + 1
|
||||
while depth:
|
||||
depth += (source[end] == "{") - (source[end] == "}")
|
||||
end += 1
|
||||
return source[start:end]
|
||||
|
||||
|
||||
class WorldInputCaptureTests(unittest.TestCase):
|
||||
def test_loading_completion_wiring(self):
|
||||
game = (ROOT / "crates/horizon-client/src/game.rs").read_text(encoding="utf-8")
|
||||
@@ -44,6 +55,7 @@ class WorldInputCaptureTests(unittest.TestCase):
|
||||
@unittest.skipUnless(shutil.which("rustc"), "requires Rust")
|
||||
def test_capture_lifecycle(self):
|
||||
source = (ROOT / "crates/horizon-client/src/game.rs").read_text(encoding="utf-8")
|
||||
mouse = (ROOT / "crates/horizon-client-input/src/mouse.rs").read_text(encoding="utf-8")
|
||||
fixture = r'''
|
||||
use std::cell::Cell;
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
@@ -102,6 +114,7 @@ impl Default for Game {
|
||||
renderer: None, cursor: (0.0, 0.0), server_packs: ServerPacks::default() }
|
||||
}
|
||||
}
|
||||
HELPER
|
||||
impl Game {
|
||||
fn stop_mining(&mut self) { self.mining = false; }
|
||||
fn reset_inventory_clicks(&mut self) {}
|
||||
@@ -164,6 +177,7 @@ fn main() {
|
||||
assert!(!game.captured); // Focus alone does not resume gameplay.
|
||||
game.capture(true); // Click or resume action.
|
||||
assert!(game.captured);
|
||||
assert_eq!(game.cursor, (213.5, 120.0)); // The grab puts the mouse at the centre.
|
||||
}
|
||||
let mut game = Game::default();
|
||||
// On a server the chat is ChatScreen (#708): loading never grabs over it.
|
||||
@@ -197,7 +211,11 @@ fn main() {
|
||||
assert!(game.window.as_ref().unwrap().visible.get());
|
||||
}
|
||||
'''
|
||||
fixture = fixture.replace("METHODS", method(source, "capture") + "\n" +
|
||||
capture = method(source, "capture").replace(
|
||||
"horizon_client::mouse::mouse_position_after_grab_change",
|
||||
"mouse_position_after_grab_change")
|
||||
fixture = fixture.replace("HELPER", function(mouse, "mouse_position_after_grab_change"))
|
||||
fixture = fixture.replace("METHODS", capture + "\n" +
|
||||
method(source, "capture_loaded_world"))
|
||||
with tempfile.TemporaryDirectory(prefix="horizon-input-") as folder:
|
||||
folder = Path(folder)
|
||||
|
||||
Reference in New Issue
Block a user