Skip to content

Commit

Permalink
Update other scripts to use XRTools.Buttons and XRTools.Axis
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiaanOlij committed Oct 25, 2022
1 parent 836aff6 commit 5cfb5f8
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 153 deletions.
27 changes: 3 additions & 24 deletions addons/godot-xr-tools/functions/function_pointer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,6 @@ extends Spatial
##


# enum our buttons, should find a way to put this more central
enum Buttons {
VR_BUTTON_BY = 1,
VR_GRIP = 2,
VR_BUTTON_3 = 3,
VR_BUTTON_4 = 4,
VR_BUTTON_5 = 5,
VR_BUTTON_6 = 6,
VR_BUTTON_AX = 7,
VR_BUTTON_8 = 8,
VR_BUTTON_9 = 9,
VR_BUTTON_10 = 10,
VR_BUTTON_11 = 11,
VR_BUTTON_12 = 12,
VR_BUTTON_13 = 13,
VR_PAD = 14,
VR_TRIGGER = 15,
VR_ACTION = 255
}


## Pointer enabled property
export var enabled : bool = true setget set_enabled

Expand All @@ -66,7 +45,7 @@ export var collide_with_bodies : bool = true setget set_collide_with_bodies
export var collide_with_areas : bool = false setget set_collide_with_areas

## Active button
export (Buttons) var active_button : int = Buttons.VR_TRIGGER
export (XRTools.Buttons) var active_button : int = XRTools.Buttons.VR_TRIGGER

## Action to monitor (if button set to VR_ACTION)
export var action = ""
Expand Down Expand Up @@ -95,7 +74,7 @@ func _ready():
ws = ARVRServer.world_scale

# If pointer-trigger is a button then subscribe to button signals
if active_button != Buttons.VR_ACTION:
if active_button != XRTools.Buttons.VR_ACTION:
# Get button press feedback from our parent (should be an ARVRController)
get_parent().connect("button_pressed", self, "_on_button_pressed")
get_parent().connect("button_release", self, "_on_button_release")
Expand All @@ -117,7 +96,7 @@ func _process(_delta):
return

# If pointer-trigger is an action then check for action
if active_button == Buttons.VR_ACTION and action != "":
if active_button == XRTools.Buttons.VR_ACTION and action != "":
if Input.is_action_just_pressed(action):
_button_pressed()
elif !Input.is_action_pressed(action) and target:
Expand Down
24 changes: 2 additions & 22 deletions addons/godot-xr-tools/functions/function_teleport.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,6 @@ extends KinematicBody
##


# enum our buttons, should find a way to put this more central
enum Buttons {
VR_BUTTON_BY = 1,
VR_GRIP = 2,
VR_BUTTON_3 = 3,
VR_BUTTON_4 = 4,
VR_BUTTON_5 = 5,
VR_BUTTON_6 = 6,
VR_BUTTON_AX = 7,
VR_BUTTON_8 = 8,
VR_BUTTON_9 = 9,
VR_BUTTON_10 = 10,
VR_BUTTON_11 = 11,
VR_BUTTON_12 = 12,
VR_BUTTON_13 = 13,
VR_PAD = 14,
VR_TRIGGER = 15
}


## Teleport enabled property
export var enabled : bool = true setget set_enabled

Expand Down Expand Up @@ -69,7 +49,7 @@ export (int, LAYERS_3D_PHYSICS) var valid_teleport_mask : int = ~0
export var camera : NodePath

## Teleport button
export (Buttons) var teleport_button : int = Buttons.VR_TRIGGER
export (XRTools.Buttons) var teleport_button : int = XRTools.Buttons.VR_TRIGGER


var origin_node : ARVROrigin
Expand Down Expand Up @@ -280,7 +260,7 @@ func _physics_process(delta):
color = cant_teleport_color

# check our axis to see if we need to rotate
teleport_rotation += (delta * controller.get_joystick_axis(0) * -4.0)
teleport_rotation += (delta * controller.get_joystick_axis(XRTools.Axis.VR_PRIMARY_X_AXIS) * -4.0)

# update target and colour
var target_basis = Basis()
Expand Down
22 changes: 1 addition & 21 deletions addons/godot-xr-tools/functions/movement_crouch.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,14 @@ extends XRToolsMovementProvider
##


# enum our buttons, should find a way to put this more central
enum Buttons {
VR_BUTTON_BY = 1,
VR_GRIP = 2,
VR_BUTTON_3 = 3,
VR_BUTTON_4 = 4,
VR_BUTTON_5 = 5,
VR_BUTTON_6 = 6,
VR_BUTTON_AX = 7,
VR_BUTTON_8 = 8,
VR_BUTTON_9 = 9,
VR_BUTTON_10 = 10,
VR_BUTTON_11 = 11,
VR_BUTTON_12 = 12,
VR_BUTTON_13 = 13,
VR_PAD = 14,
VR_TRIGGER = 15
}


## Movement provider order
export var order : int = 10

## Crouch height
export var crouch_height : float = 1.0

## Crouch button
export (Buttons) var crouch_button : int = Buttons.VR_PAD
export (XRTools.Buttons) var crouch_button : int = XRTools.Buttons.VR_PAD


## Crouching flag
Expand Down
4 changes: 2 additions & 2 deletions addons/godot-xr-tools/functions/movement_direct.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ func physics_movement(_delta: float, player_body: XRToolsPlayerBody, _disabled:
return

# Apply forwards/backwards ground control
player_body.ground_control_velocity.y += _controller.get_joystick_axis(1) * max_speed
player_body.ground_control_velocity.y += _controller.get_joystick_axis(XRTools.Axis.VR_PRIMARY_Y_AXIS) * max_speed

# Apply left/right ground control
if strafe:
player_body.ground_control_velocity.x += _controller.get_joystick_axis(0) * max_speed
player_body.ground_control_velocity.x += _controller.get_joystick_axis(XRTools.Axis.VR_PRIMARY_X_AXIS) * max_speed

# Clamp ground control
var length := player_body.ground_control_velocity.length()
Expand Down
25 changes: 3 additions & 22 deletions addons/godot-xr-tools/functions/movement_flight.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,6 @@ signal flight_started()
signal flight_finished()


# enum our buttons, should find a way to put this more central
enum Buttons {
VR_BUTTON_BY = 1,
VR_GRIP = 2,
VR_BUTTON_3 = 3,
VR_BUTTON_4 = 4,
VR_BUTTON_5 = 5,
VR_BUTTON_6 = 6,
VR_BUTTON_AX = 7,
VR_BUTTON_8 = 8,
VR_BUTTON_9 = 9,
VR_BUTTON_10 = 10,
VR_BUTTON_11 = 11,
VR_BUTTON_12 = 12,
VR_BUTTON_13 = 13,
VR_PAD = 14,
VR_TRIGGER = 15
}

# Enumeration of controller to use for flight
enum FlightController {
LEFT, # Use left controller
Expand Down Expand Up @@ -92,7 +73,7 @@ export var order : int = 30
export (FlightController) var controller : int = FlightController.LEFT

## Flight toggle button
export (Buttons) var flight_button : int = Buttons.VR_BUTTON_BY
export (XRTools.Buttons) var flight_button : int = XRTools.Buttons.VR_BUTTON_BY

## Flight pitch control
export (FlightPitch) var pitch : int = FlightPitch.CONTROLLER
Expand Down Expand Up @@ -186,8 +167,8 @@ func physics_movement(delta: float, player_body: XRToolsPlayerBody, disabled: bo
var side := forwards.cross(Vector3.UP)

# Construct the target velocity
var joy_forwards := _controller.get_joystick_axis(1)
var joy_side := _controller.get_joystick_axis(0)
var joy_forwards := _controller.get_joystick_axis(XRTools.Axis.VR_PRIMARY_Y_AXIS)
var joy_side := _controller.get_joystick_axis(XRTools.Axis.VR_PRIMARY_X_AXIS)
var heading := forwards * joy_forwards + side * joy_side

# Calculate the flight velocity
Expand Down
21 changes: 1 addition & 20 deletions addons/godot-xr-tools/functions/movement_grapple.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,6 @@ signal grapple_started()
signal grapple_finished()


# enum our buttons, should find a way to put this more central
enum Buttons {
VR_BUTTON_BY = 1,
VR_GRIP = 2,
VR_BUTTON_3 = 3,
VR_BUTTON_4 = 4,
VR_BUTTON_5 = 5,
VR_BUTTON_6 = 6,
VR_BUTTON_AX = 7,
VR_BUTTON_8 = 8,
VR_BUTTON_9 = 9,
VR_BUTTON_10 = 10,
VR_BUTTON_11 = 11,
VR_BUTTON_12 = 12,
VR_BUTTON_13 = 13,
VR_PAD = 14,
VR_TRIGGER = 15
}

# Grapple state
enum GrappleState {
IDLE, # Idle
Expand Down Expand Up @@ -76,7 +57,7 @@ export var rope_width : float = 0.02
export var friction : float = 0.1

## Grapple button (triggers grappling movement). Be sure this button does not conflict with other functions.
export (Buttons) var grapple_button_id : int = Buttons.VR_TRIGGER
export (XRTools.Buttons) var grapple_button_id : int = XRTools.Buttons.VR_TRIGGER

# Hook related variables
var hook_object : Spatial = null
Expand Down
20 changes: 1 addition & 19 deletions addons/godot-xr-tools/functions/movement_jump.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,12 @@ extends XRToolsMovementProvider
## and jump velocity.
##

# enum our buttons, should find a way to put this more central
enum Buttons {
VR_BUTTON_BY = 1,
VR_GRIP = 2,
VR_BUTTON_3 = 3,
VR_BUTTON_4 = 4,
VR_BUTTON_5 = 5,
VR_BUTTON_6 = 6,
VR_BUTTON_AX = 7,
VR_BUTTON_8 = 8,
VR_BUTTON_9 = 9,
VR_BUTTON_10 = 10,
VR_BUTTON_11 = 11,
VR_BUTTON_12 = 12,
VR_BUTTON_13 = 13,
VR_PAD = 14,
VR_TRIGGER = 15
}

## Movement provider order
export var order : int = 20

## Button to trigger jump
export (Buttons) var jump_button_id : int = Buttons.VR_TRIGGER
export (XRTools.Buttons) var jump_button_id : int = XRTools.Buttons.VR_TRIGGER

# Node references
onready var _controller: ARVRController = get_parent()
Expand Down
2 changes: 1 addition & 1 deletion addons/godot-xr-tools/functions/movement_turn.gd
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func physics_movement(delta: float, player_body: XRToolsPlayerBody, _disabled: b
return

# Read the left/right joystick axis
var left_right := _controller.get_joystick_axis(0)
var left_right := _controller.get_joystick_axis(XRTools.Axis.VR_PRIMARY_X_AXIS)
if abs(left_right) <= 0.1:
# Not turning
_turn_step = 0.0
Expand Down
22 changes: 1 addition & 21 deletions addons/godot-xr-tools/misc/hold_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,10 @@ extends Spatial
signal pressed


# Button
enum Buttons {
VR_BUTTON_BY = 1,
VR_GRIP = 2,
VR_BUTTON_3 = 3,
VR_BUTTON_4 = 4,
VR_BUTTON_5 = 5,
VR_BUTTON_6 = 6,
VR_BUTTON_AX = 7,
VR_BUTTON_8 = 8,
VR_BUTTON_9 = 9,
VR_BUTTON_10 = 10,
VR_BUTTON_11 = 11,
VR_BUTTON_12 = 12,
VR_BUTTON_13 = 13,
VR_PAD = 14,
VR_TRIGGER = 15
}


# Enable our button
export var enabled : bool = false setget set_enabled

export (Buttons) var activate_button : int = Buttons.VR_TRIGGER
export (XRTools.Buttons) var activate_button : int = XRTools.Buttons.VR_TRIGGER

# Countdown
export var hold_time : float = 2.0
Expand Down
3 changes: 2 additions & 1 deletion addons/godot-xr-tools/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ enum Buttons {
VR_BUTTON_12 = 12,
VR_BUTTON_13 = 13,
VR_PAD = 14,
VR_TRIGGER = 15
VR_TRIGGER = 15,
VR_ACTION = 255 ## Only supported in function pointer, should solve that differently!!
}


Expand Down

0 comments on commit 5cfb5f8

Please sign in to comment.