Skip to content

Commit 09e1f69

Browse files
authored
Better format and static type Mouse Capture (#770)
1 parent 6068662 commit 09e1f69

File tree

1 file changed

+37
-25
lines changed

1 file changed

+37
-25
lines changed

addons/godot-xr-tools/desktop-support/mouse_capture.gd

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,58 @@ extends XRToolsMovementProvider
55
## XR Tools Mouse Capture
66
##
77
## This script provides support for desktop mouse capture. This script works
8-
## with the PlayerBody attached to the players XROrigin3D.
9-
8+
## with the PlayerBody attached to the player's [XROrigin3D].
109

1110
## Movement provider order
12-
@export var order : int = 1
11+
@export var order: int = 1
1312

1413
## Our directional input
15-
@export var escape_action : String = "ui_cancel"
14+
@export var escape_action: String = "ui_cancel"
1615

17-
#Last mouse capture status and should it be auto captured
18-
@export var capture : bool = true
16+
## Last mouse capture status and should it be auto captured
17+
@export var capture: bool = true
1918

2019

21-
# XRStart node
22-
@onready var xr_start_node = XRTools.find_xr_child(
23-
XRTools.find_xr_ancestor(self,
24-
"*Staging",
25-
"XRToolsStaging"),"StartXR","Node")
20+
## XRStart node
21+
@onready var xr_start_node: XRToolsStartXR = XRTools.find_xr_child(
22+
XRTools.find_xr_ancestor(
23+
self,
24+
"*Staging",
25+
"XRToolsStaging",
26+
),
27+
"StartXR",
28+
"Node",
29+
)
2630

2731

28-
# Add support for is_xr_class on XRTools classes
29-
func is_xr_class(xr_name: String) -> bool:
32+
## Add support for is_xr_class on XRTools classes
33+
func is_xr_class(xr_name: String) -> bool:
3034
return xr_name == "XRToolsDesktopMouseCapture" or super(xr_name)
3135

3236

33-
# Perform jump movement
34-
func physics_movement(_delta: float, player_body: XRToolsPlayerBody, _disabled: bool):
37+
## Perform jump movement
38+
func physics_movement(
39+
_delta: float,
40+
player_body: XRToolsPlayerBody,
41+
_disabled: bool,
42+
) -> void:
3543
# Skip if the player body isn't active
36-
var check1 :bool= (xr_start_node.is_xr_active() and Input.mouse_mode==Input.MOUSE_MODE_CAPTURED)
37-
if !player_body.enabled or check1:
38-
return
44+
var xr_active: bool = (
45+
xr_start_node.is_xr_active()
46+
and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED
47+
)
3948

49+
if not player_body.enabled or xr_active:
50+
return
4051

41-
if Input.is_action_just_pressed(escape_action):
42-
capture=!capture
52+
if Input.is_action_just_pressed("ui_cancel"):
53+
capture = not capture
4354

44-
#print(Input.mouse_mode==Input.MOUSE_MODE_CAPTURED)
55+
if not xr_start_node.is_xr_active() and capture:
56+
# If XR is not active and the mouse should be captured
57+
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
58+
elif Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
59+
# If XR is active and the mouse should not be captured
60+
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
4561

46-
if Input.mouse_mode==Input.MOUSE_MODE_CAPTURED and (xr_start_node.is_xr_active() or !capture):
47-
Input.mouse_mode=Input.MOUSE_MODE_VISIBLE
48-
elif (!xr_start_node.is_xr_active() and capture):
49-
Input.mouse_mode=Input.MOUSE_MODE_CAPTURED
5062
return

0 commit comments

Comments
 (0)