Skip to content

Commit

Permalink
formatting cleanup for godot standards
Browse files Browse the repository at this point in the history
  • Loading branch information
lunarcloud committed Oct 20, 2022
1 parent ab82688 commit a913825
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 109 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# Godot 4+ specific ignores
.godot/

# Godot-specific ignores
.import/
export.cfg
export_presets.cfg

# Imported translations (automatically generated from CSV files)
*.translation

# Mono-specific ignores
.mono/
data_*/
mono_crash.*.json

# builds
[Bb]uild/

29 changes: 10 additions & 19 deletions example_character/character.gd
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
extends KinematicBody



##
## Example XR / Flat -Controlled Character
##
## @desc:
## The script provides a simple example of a character controlled by the
## input, and using the camera helpers from, "XrOrFlatMode" singleton.
## The script provides a simple example of a character controlled by the
## input, and using the camera helpers from, "XrOrFlatMode" singleton.
##

enum Follow { NEITHER, FLAT, BOTH }

enum Follow {
Flat,
Both,
Neither
}

export (float, 10.0, 60.0) var speed : float = 8.0
export(float, 10.0, 60.0) var speed: float = 8.0

export (Follow) var FollowStyle := Follow.Both
export(Follow) var follow_style := Follow.BOTH

export (float, 0.01, 1.0) var bump_vibrate = 0.75
export(float, 0.01, 1.0) var bump_vibrate = 0.75

var _velocity := Vector3.ZERO

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

onready var _anim = $AnimationPlayer


func _physics_process(_delta):
if _velocity != Vector3.ZERO:
# warning-ignore:return_value_discarded
move_and_slide_with_snap(_velocity, Vector3.DOWN)

match FollowStyle:
Follow.Both:
match follow_style:
Follow.BOTH:
XrOrFlatMode.camera_slide_to(translation, Vector3(0, 4.5, 5), Vector3(0, 0, 7.5))
Follow.Flat:
Follow.FLAT:
XrOrFlatMode.flat_camera_slide_to(translation, Vector3(0, 4.5, 5))


Expand Down Expand Up @@ -67,5 +60,3 @@ func _process_vibration():
if is_on_wall() and not _was_on_wall:
XrOrFlatMode.vibrate(bump_vibrate, 0.0, 0.1)
_was_on_wall = is_on_wall()


13 changes: 10 additions & 3 deletions hud/xr_floating_hud.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
extends Spatial

##
## XR Floating HUD
##
## The script ensures the HUD stays relative to the XR player's height.
##

var _offset := Vector3.ZERO


func _ready():
_offset = global_translation - XrOrFlatMode._get_xr_origin().global_translation
_offset = global_translation - XrOrFlatMode.get_xr_origin().global_translation


func _process(delta):
func _process(_delta):
# Keep the original X/Z offset
global_translation = XrOrFlatMode._get_xr_origin().global_translation + _offset
global_translation = XrOrFlatMode.get_xr_origin().global_translation + _offset

# Apply the player height Y
translation.y = XrOrFlatMode.xr_player_height()
26 changes: 12 additions & 14 deletions launcher/xr_or_flat_mode_launcher.gd
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
class_name XrOrFlatModeLauncher
extends Node


##
## XR / Flat Mode Game Launcher
##
## @desc:
## The script launches the game in either flat or xr modes based on
## either features added to the export options, command-line arguments,
## or autodetected based on whether the XR interface can be started,
## i.e. if a VR headset is connected or not.
## The script launches the game in either flat or xr modes based on
## either features added to the export options, command-line arguments,
## or autodetected based on whether the XR interface can be started,
## i.e. if a VR headset is connected or not.
##


func _ready():
if _check_os_features(): return
if _check_args(): return
if _check_os_features():
return
if _check_args():
return
_autodetect()


Expand Down Expand Up @@ -71,8 +71,8 @@ func _check_args() -> bool:
func _autodetect() -> void:
# if we didn't specify, autodetect
print("Autodetecting XR or non-XR mode on whether a headset is connected...")
var xrInterface := ARVRServer.find_interface("OpenXR")
if xrInterface and xrInterface.initialize():
var xr_interface := ARVRServer.find_interface("OpenXR")
if xr_interface and xr_interface.initialize():
launch_xr()
else:
launch_flat()
Expand All @@ -81,7 +81,7 @@ func _autodetect() -> void:
# Launch the XR scene
func launch_xr() -> void:
print("XR Mode Active")
XrOrFlatMode.CurrentMode = XrOrFlatMode.XR
XrOrFlatMode.current_mode = XrOrFlatMode.Mode.XR
if get_tree().change_scene("res://example_level/xr.tscn") != OK:
print("Failed to load initial scene, quitting...")
get_tree().notification(NOTIFICATION_WM_QUIT_REQUEST)
Expand All @@ -90,9 +90,7 @@ func launch_xr() -> void:
# Launch the Flat Scene
func launch_flat() -> void:
print("Standard Non-XR Mode Active")
XrOrFlatMode.CurrentMode = XrOrFlatMode.Flat
XrOrFlatMode.current_mode = XrOrFlatMode.Mode.FLAT
if get_tree().change_scene("res://example_level/flat.tscn") != OK:
print("Failed to load initial scene, quitting...")
get_tree().notification(NOTIFICATION_WM_QUIT_REQUEST)


17 changes: 6 additions & 11 deletions xr_cam_corrected.gd
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
class_name CorrectedARVRCamera
extends ARVRCamera



##
## XR Stage/Camera Rotation Mis-Match Correction Script
##
## @desc:
## This whole script is a workaround for sometimes the XR stage not
## being aligned with the initial camera rotation
## This whole script is a workaround for sometimes the XR stage not
## being aligned with the initial camera rotation
##


var _last_rotation := Vector3.ZERO

var _correction_applied := false


func _process(delta):
func _process(_delta):
if _last_rotation != Vector3.ZERO and not _correction_applied:
var rotationY = global_rotation.y
var rotation_y = global_rotation.y

# Rotate towards where the Origin node is pointing
get_parent().global_rotation.y -= rotationY
get_parent().global_rotation.y -= rotation_y

# Inform the Singleton of the offset applied
XrOrFlatMode.XrRotationYCorrection = rotationY
XrOrFlatMode.xr_y_rotation_correction = rotation_y

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

_last_rotation = global_rotation

21 changes: 9 additions & 12 deletions xr_character_input.gd
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
tool
class_name XRModeCharacterInput, "res://addons/godot-xr-tools/editor/icons/function.svg"
extends Node
tool



##
## XR Character Input
##
## @desc:
## The script provides a means to capture the input from XR controller and
## passes it along to the "XrOrFlatMode" singleton for use with a character.
## The script provides a means to capture the input from XR controller and
## passes it along to the "XrOrFlatMode" singleton for use with a character.
##


# use enum from XRTools if they centralize these
enum Buttons {
VR_BUTTON_BY = 1,
Expand All @@ -33,14 +29,15 @@ enum Buttons {
}

## Button to trigger jump
export (Buttons) var jump_button_id = Buttons.VR_BUTTON_AX
export(Buttons) var jump_button_id = Buttons.VR_BUTTON_AX

export var left_right_deadzone := 0.3

export var up_down_deadzone := 0.3

# Controller node
onready var _controller : ARVRController = get_parent()
onready var _controller: ARVRController = get_parent()


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

# Read the left/right joystick axis
var left_right : float = _controller.get_joystick_axis(0)
var left_right: float = _controller.get_joystick_axis(0)
if abs(left_right) <= left_right_deadzone:
left_right = 0

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

var input := Vector2(left_right, up_down)
XrOrFlatMode.XrCharacterInput = input
XrOrFlatMode.xr_character_input = input


# This method verifies the movement provider has a valid configuration.
Expand Down
Loading

0 comments on commit a913825

Please sign in to comment.