Skip to content

Commit a913825

Browse files
committed
formatting cleanup for godot standards
1 parent ab82688 commit a913825

File tree

7 files changed

+94
-109
lines changed

7 files changed

+94
-109
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
# Godot 4+ specific ignores
2+
.godot/
13

24
# Godot-specific ignores
35
.import/
46
export.cfg
57
export_presets.cfg
68

9+
# Imported translations (automatically generated from CSV files)
10+
*.translation
11+
712
# Mono-specific ignores
813
.mono/
914
data_*/
15+
mono_crash.*.json
1016

1117
# builds
1218
[Bb]uild/
19+

example_character/character.gd

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
extends KinematicBody
22

3-
4-
53
##
64
## Example XR / Flat -Controlled Character
75
##
8-
## @desc:
9-
## The script provides a simple example of a character controlled by the
10-
## input, and using the camera helpers from, "XrOrFlatMode" singleton.
6+
## The script provides a simple example of a character controlled by the
7+
## input, and using the camera helpers from, "XrOrFlatMode" singleton.
118
##
129

10+
enum Follow { NEITHER, FLAT, BOTH }
1311

14-
enum Follow {
15-
Flat,
16-
Both,
17-
Neither
18-
}
19-
20-
export (float, 10.0, 60.0) var speed : float = 8.0
12+
export(float, 10.0, 60.0) var speed: float = 8.0
2113

22-
export (Follow) var FollowStyle := Follow.Both
14+
export(Follow) var follow_style := Follow.BOTH
2315

24-
export (float, 0.01, 1.0) var bump_vibrate = 0.75
16+
export(float, 0.01, 1.0) var bump_vibrate = 0.75
2517

2618
var _velocity := Vector3.ZERO
2719

@@ -30,15 +22,16 @@ var _was_on_wall := true
3022

3123
onready var _anim = $AnimationPlayer
3224

25+
3326
func _physics_process(_delta):
3427
if _velocity != Vector3.ZERO:
3528
# warning-ignore:return_value_discarded
3629
move_and_slide_with_snap(_velocity, Vector3.DOWN)
3730

38-
match FollowStyle:
39-
Follow.Both:
31+
match follow_style:
32+
Follow.BOTH:
4033
XrOrFlatMode.camera_slide_to(translation, Vector3(0, 4.5, 5), Vector3(0, 0, 7.5))
41-
Follow.Flat:
34+
Follow.FLAT:
4235
XrOrFlatMode.flat_camera_slide_to(translation, Vector3(0, 4.5, 5))
4336

4437

@@ -67,5 +60,3 @@ func _process_vibration():
6760
if is_on_wall() and not _was_on_wall:
6861
XrOrFlatMode.vibrate(bump_vibrate, 0.0, 0.1)
6962
_was_on_wall = is_on_wall()
70-
71-

hud/xr_floating_hud.gd

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
extends Spatial
22

3+
##
4+
## XR Floating HUD
5+
##
6+
## The script ensures the HUD stays relative to the XR player's height.
7+
##
8+
39
var _offset := Vector3.ZERO
410

11+
512
func _ready():
6-
_offset = global_translation - XrOrFlatMode._get_xr_origin().global_translation
13+
_offset = global_translation - XrOrFlatMode.get_xr_origin().global_translation
714

815

9-
func _process(delta):
16+
func _process(_delta):
1017
# Keep the original X/Z offset
11-
global_translation = XrOrFlatMode._get_xr_origin().global_translation + _offset
18+
global_translation = XrOrFlatMode.get_xr_origin().global_translation + _offset
1219

1320
# Apply the player height Y
1421
translation.y = XrOrFlatMode.xr_player_height()

launcher/xr_or_flat_mode_launcher.gd

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
class_name XrOrFlatModeLauncher
22
extends Node
33

4-
54
##
65
## XR / Flat Mode Game Launcher
76
##
8-
## @desc:
9-
## The script launches the game in either flat or xr modes based on
10-
## either features added to the export options, command-line arguments,
11-
## or autodetected based on whether the XR interface can be started,
12-
## i.e. if a VR headset is connected or not.
7+
## The script launches the game in either flat or xr modes based on
8+
## either features added to the export options, command-line arguments,
9+
## or autodetected based on whether the XR interface can be started,
10+
## i.e. if a VR headset is connected or not.
1311
##
1412

1513

1614
func _ready():
17-
if _check_os_features(): return
18-
if _check_args(): return
15+
if _check_os_features():
16+
return
17+
if _check_args():
18+
return
1919
_autodetect()
2020

2121

@@ -71,8 +71,8 @@ func _check_args() -> bool:
7171
func _autodetect() -> void:
7272
# if we didn't specify, autodetect
7373
print("Autodetecting XR or non-XR mode on whether a headset is connected...")
74-
var xrInterface := ARVRServer.find_interface("OpenXR")
75-
if xrInterface and xrInterface.initialize():
74+
var xr_interface := ARVRServer.find_interface("OpenXR")
75+
if xr_interface and xr_interface.initialize():
7676
launch_xr()
7777
else:
7878
launch_flat()
@@ -81,7 +81,7 @@ func _autodetect() -> void:
8181
# Launch the XR scene
8282
func launch_xr() -> void:
8383
print("XR Mode Active")
84-
XrOrFlatMode.CurrentMode = XrOrFlatMode.XR
84+
XrOrFlatMode.current_mode = XrOrFlatMode.Mode.XR
8585
if get_tree().change_scene("res://example_level/xr.tscn") != OK:
8686
print("Failed to load initial scene, quitting...")
8787
get_tree().notification(NOTIFICATION_WM_QUIT_REQUEST)
@@ -90,9 +90,7 @@ func launch_xr() -> void:
9090
# Launch the Flat Scene
9191
func launch_flat() -> void:
9292
print("Standard Non-XR Mode Active")
93-
XrOrFlatMode.CurrentMode = XrOrFlatMode.Flat
93+
XrOrFlatMode.current_mode = XrOrFlatMode.Mode.FLAT
9494
if get_tree().change_scene("res://example_level/flat.tscn") != OK:
9595
print("Failed to load initial scene, quitting...")
9696
get_tree().notification(NOTIFICATION_WM_QUIT_REQUEST)
97-
98-

xr_cam_corrected.gd

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
11
class_name CorrectedARVRCamera
22
extends ARVRCamera
33

4-
5-
64
##
75
## XR Stage/Camera Rotation Mis-Match Correction Script
86
##
9-
## @desc:
10-
## This whole script is a workaround for sometimes the XR stage not
11-
## being aligned with the initial camera rotation
7+
## This whole script is a workaround for sometimes the XR stage not
8+
## being aligned with the initial camera rotation
129
##
1310

14-
1511
var _last_rotation := Vector3.ZERO
1612

1713
var _correction_applied := false
1814

1915

20-
func _process(delta):
16+
func _process(_delta):
2117
if _last_rotation != Vector3.ZERO and not _correction_applied:
22-
var rotationY = global_rotation.y
18+
var rotation_y = global_rotation.y
2319

2420
# Rotate towards where the Origin node is pointing
25-
get_parent().global_rotation.y -= rotationY
21+
get_parent().global_rotation.y -= rotation_y
2622

2723
# Inform the Singleton of the offset applied
28-
XrOrFlatMode.XrRotationYCorrection = rotationY
24+
XrOrFlatMode.xr_y_rotation_correction = rotation_y
2925

3026
# Never Run this code for the life of this XR Camera
3127
_correction_applied = true
3228
set_process(false)
3329

3430
_last_rotation = global_rotation
35-

xr_character_input.gd

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1+
tool
12
class_name XRModeCharacterInput, "res://addons/godot-xr-tools/editor/icons/function.svg"
23
extends Node
3-
tool
4-
5-
64

75
##
86
## XR Character Input
97
##
10-
## @desc:
11-
## The script provides a means to capture the input from XR controller and
12-
## passes it along to the "XrOrFlatMode" singleton for use with a character.
8+
## The script provides a means to capture the input from XR controller and
9+
## passes it along to the "XrOrFlatMode" singleton for use with a character.
1310
##
1411

15-
1612
# use enum from XRTools if they centralize these
1713
enum Buttons {
1814
VR_BUTTON_BY = 1,
@@ -33,14 +29,15 @@ enum Buttons {
3329
}
3430

3531
## Button to trigger jump
36-
export (Buttons) var jump_button_id = Buttons.VR_BUTTON_AX
32+
export(Buttons) var jump_button_id = Buttons.VR_BUTTON_AX
3733

3834
export var left_right_deadzone := 0.3
3935

4036
export var up_down_deadzone := 0.3
4137

4238
# Controller node
43-
onready var _controller : ARVRController = get_parent()
39+
onready var _controller: ARVRController = get_parent()
40+
4441

4542
func _ready():
4643
# If I don't handle end/begin events, replacing the headset stops character control
@@ -68,17 +65,17 @@ func _process(_delta):
6865
return
6966

7067
# Read the left/right joystick axis
71-
var left_right : float = _controller.get_joystick_axis(0)
68+
var left_right: float = _controller.get_joystick_axis(0)
7269
if abs(left_right) <= left_right_deadzone:
7370
left_right = 0
7471

7572
# Read the up/down joystick axis
76-
var up_down : float = _controller.get_joystick_axis(1) * -1 # flip vertical
73+
var up_down: float = _controller.get_joystick_axis(1) * -1 # flip vertical
7774
if abs(up_down) <= up_down_deadzone:
7875
up_down = 0
7976

8077
var input := Vector2(left_right, up_down)
81-
XrOrFlatMode.XrCharacterInput = input
78+
XrOrFlatMode.xr_character_input = input
8279

8380

8481
# This method verifies the movement provider has a valid configuration.

0 commit comments

Comments
 (0)