diff --git a/app/content/functions/movable.gd b/app/content/functions/movable.gd index cabc429..5b3dd75 100644 --- a/app/content/functions/movable.gd +++ b/app/content/functions/movable.gd @@ -39,6 +39,12 @@ func reset(): initiator2 = null on_moved.emit() +func _on_action_value(event: EventAction): + if event.name != "primary"||event.initiator != initiator: + return + + relative_transform = relative_transform.translated(Vector3(0, 0, -event.value.y * 0.05)).rotated_local(Vector3(0, 1, 0), event.value.x * 0.05) + func _on_grab_down(event: EventPointer): if disabled: return @@ -65,6 +71,8 @@ func _on_grab_down(event: EventPointer): initiator = event.initiator + EventSystem.on_action_value.connect(_on_action_value) + _update_relative_transform() initial_global_transform = get_parent().global_transform @@ -115,6 +123,7 @@ func _on_grab_up(event: EventPointer): initiator = null initiator2 = null on_moved.emit() + EventSystem.on_action_value.disconnect(_on_action_value) func _get_first_ray_point(): if initiator == null: diff --git a/app/content/system/controller_left/controller_left.gd b/app/content/system/controller_left/controller_left.gd index 61ef73a..5e97648 100644 --- a/app/content/system/controller_left/controller_left.gd +++ b/app/content/system/controller_left/controller_left.gd @@ -52,14 +52,6 @@ var grabbed = false var moving_entity = null func _ready(): - button_pressed.connect(func(action_name): - EventSystem.emit_action(action_name, true, false) - ) - - button_released.connect(func(action_name): - EventSystem.emit_action(action_name, false, false) - ) - _setup_hand() palm.remove_child(entity_settings) diff --git a/app/content/system/controller_right/controller_right.gd b/app/content/system/controller_right/controller_right.gd index c08f470..5a839f7 100644 --- a/app/content/system/controller_right/controller_right.gd +++ b/app/content/system/controller_right/controller_right.gd @@ -39,13 +39,6 @@ var pressed = false var grabbed = false func _ready(): - button_pressed.connect(func(action_name): - EventSystem.emit_action(action_name, true, true) - ) - button_released.connect(func(action_name): - EventSystem.emit_action(action_name, false, true) - ) - _setup_hand() func _setup_hand(): diff --git a/app/content/system/raycast/raycast.gd b/app/content/system/raycast/raycast.gd index 7b94df6..5eb2cf7 100644 --- a/app/content/system/raycast/raycast.gd +++ b/app/content/system/raycast/raycast.gd @@ -32,14 +32,26 @@ func _ready(): add_child(pointer) get_parent().button_pressed.connect(func(button: String): + EventSystem.emit_action(button, true, initiator) + if _event_type_map.has(button): pointer.pressed(_event_type_map[button]) ) get_parent().button_released.connect(func(button: String): + EventSystem.emit_action(button, false, initiator) + if _event_type_map.has(button): pointer.released(_event_type_map[button]) ) + get_parent().input_float_changed.connect(func(action_name, value): + EventSystem.emit_action(action_name, value, initiator) + ) + + get_parent().input_vector2_changed.connect(func(action_name, value): + EventSystem.emit_action(action_name, value, initiator) + ) + R.effect(func(_arg): var style=Store.settings.state.cursor_style diff --git a/app/lib/events/event_action.gd b/app/lib/events/event_action.gd index 59e120c..74cc5e1 100644 --- a/app/lib/events/event_action.gd +++ b/app/lib/events/event_action.gd @@ -2,9 +2,11 @@ extends Event ## EventAction is emitted when the user presses a button or trigger on the controller. class_name EventAction +const Initiator = preload ("res://lib/utils/pointer/initiator.gd") + ## The name of the action that was triggered. var name: String -## True if the right controller triggered the action, false if the left controller triggered the action. -var right_controller: bool ## Boolean, Float or Vector2 -var value \ No newline at end of file +var value +## The initiator that started the event. +var initiator: Initiator \ No newline at end of file diff --git a/app/lib/globals/event_system.gd b/app/lib/globals/event_system.gd index 798c020..22d7c2a 100644 --- a/app/lib/globals/event_system.gd +++ b/app/lib/globals/event_system.gd @@ -1,5 +1,7 @@ extends Node +const Initiator = preload ("res://lib/utils/pointer/initiator.gd") + ## Prefix for the function names to be called const FN_PREFIX = "_on_" ## Prefix for the signal names to be emitted @@ -83,11 +85,11 @@ func notify(message: String, type:=EventNotify.Type.INFO): emit("notify", event) ## Helper for emitting controller actions -func emit_action(name: String, value, right_controller: bool=true): +func emit_action(name: String, value, initiator: Initiator): var event = EventAction.new() event.name = name event.value = value - event.right_controller = right_controller + event.initiator = initiator match typeof(value): TYPE_BOOL: