diff --git a/src/components/controls/FaceLock.gd b/src/components/controls/FaceLock.gd index da05d7d..7f520b2 100644 --- a/src/components/controls/FaceLock.gd +++ b/src/components/controls/FaceLock.gd @@ -40,10 +40,9 @@ static func handle_rot_right(is_alt: bool) -> Quaternion: return left_q.normalized().inverse() return (alt_q * down_q.normalized().inverse()).inverse() -static func handle_face_lock_input(controlledNode: MeshIcosahedron): +static func handle_face_lock_input(controlledNode: MeshIcosahedron, is_inverted := false): if controlledNode.is_rotating: return - var is_inverted = G.settings.IS_CONTROL_INVERTED var q: Quaternion if Input.is_action_just_pressed("ui_up"): if not controlledNode.is_alt: diff --git a/src/components/controls/FreeSpin.gd b/src/components/controls/FreeSpin.gd new file mode 100644 index 0000000..ca5f5eb --- /dev/null +++ b/src/components/controls/FreeSpin.gd @@ -0,0 +1,19 @@ +extends RefCounted +class_name FreeSpin + +static func handle_free_spin_input(controlledNode: MeshInstance3D, rot_speed: float, is_inverted := false): + if not controlledNode: + return + var rotation: Quaternion + + if Input.is_action_pressed("ui_up"): + rotation = rotation * Quaternion(0, 0, -rot_speed, 1, ) + if Input.is_action_pressed("ui_down"): + rotation = rotation * Quaternion(0, 0, rot_speed, 1, ) + if Op.xor(is_inverted, Input.is_action_pressed("ui_right")): + rotation = rotation * Quaternion(0, rot_speed, 0, 1, ) + if Op.xor(is_inverted, Input.is_action_pressed("ui_left")): + rotation = rotation * Quaternion(0, -rot_speed, 0, 1, ) + if rotation: + var t = rotation.normalized() * controlledNode.quaternion + controlledNode.transform.basis = Basis(t).orthonormalized() diff --git a/src/components/controls/LoopControls.gd b/src/components/controls/LoopControls.gd index bc6e576..3f2fbc9 100644 --- a/src/components/controls/LoopControls.gd +++ b/src/components/controls/LoopControls.gd @@ -3,7 +3,6 @@ class_name LoopControls @export var figureRoot: FigureRoot @export var controlledNode: MeshIcosahedron -@export var ROTATION_SPEED: float @onready var game_progress: GameProgress = %GameProgress @onready var game_state_manager: GameStateManager = %GameStateManager @onready var sfx_player: SfxPlayer = $"/root/MainScene/SfxPlayer" @@ -13,7 +12,6 @@ enum ControlType {FREE_SPIN, FACE_LOCK} # Called when the node enters the scene tree for the first time. func _ready() -> void: game_state_manager.game_state_changed.connect(_on_game_state) - ROTATION_SPEED = G.settings.ROTATION_SPEED func _on_game_state(old_state: GameStateManager.GameState, new_state: GameStateManager.GameState): var gs := GameStateManager.GameState @@ -99,25 +97,9 @@ func _process(delta: float) -> void: return if game_state_manager.game_state == GameStateManager.GameState.GAME_END: return + var is_inverted = G.settings.IS_CONTROL_INVERTED if G.settings.CONTROL_TYPE == "FACE_LOCK": - FaceLock.handle_face_lock_input(controlledNode) + FaceLock.handle_face_lock_input(controlledNode, is_inverted) else: - handle_free_spin_input(delta) - -# TODO make statc -func handle_free_spin_input(delta: float): - var rotation: Quaternion - var rs := ROTATION_SPEED / 10. * delta - var is_inverted = G.settings.IS_CONTROL_INVERTED - - if Input.is_action_pressed("ui_up"): - rotation = rotation * Quaternion(0, 0, -rs, 1, ) - if Input.is_action_pressed("ui_down"): - rotation = rotation * Quaternion(0, 0, rs, 1, ) - if Op.xor(is_inverted, Input.is_action_pressed("ui_right")): - rotation = rotation * Quaternion(0, rs, 0, 1, ) - if Op.xor(is_inverted, Input.is_action_pressed("ui_left")): - rotation = rotation * Quaternion(0, -rs, 0, 1, ) - if controlledNode and rotation: - var t = rotation.normalized() * controlledNode.quaternion - controlledNode.transform.basis = Basis(t).orthonormalized() + var rot_speed: float = G.settings.ROTATION_SPEED / 10. * delta + FreeSpin.handle_free_spin_input(controlledNode, rot_speed, is_inverted) diff --git a/src/models/icosahedron/test/variant_test.gd b/src/models/icosahedron/test/variant_test.gd index 3d582d9..6fc1b2a 100644 --- a/src/models/icosahedron/test/variant_test.gd +++ b/src/models/icosahedron/test/variant_test.gd @@ -3,7 +3,7 @@ extends Node3D const IcosahedronScene = preload('res://src/models/icosahedron/Icosahedron.tscn') var controlledNode # TODO get from defaults -var ROTATION_SPEED := 12 +@export var ROTATION_SPEED: float = G.settings.ROTATION_SPEED @export var show_face_numbers: bool = false # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -18,22 +18,5 @@ func _process(delta: float) -> void: return if Input.is_action_just_pressed('ui_accept'): controlledNode.transform.basis = Basis(Quaternion()).orthonormalized() - handle_free_spin_input(delta) - pass - -func handle_free_spin_input(delta: float): - var _rotation: Quaternion var rs := ROTATION_SPEED / 10. * delta - var is_inverted = false - - if Input.is_action_pressed("ui_up"): - _rotation = _rotation * Quaternion(0, 0, -rs, 1, ) - if Input.is_action_pressed("ui_down"): - _rotation = _rotation * Quaternion(0, 0, rs, 1, ) - if Op.xor(is_inverted, Input.is_action_pressed("ui_right")): - _rotation = _rotation * Quaternion(0, rs, 0, 1, ) - if Op.xor(is_inverted, Input.is_action_pressed("ui_left")): - _rotation = _rotation * Quaternion(0, -rs, 0, 1, ) - if controlledNode and _rotation: - var t = _rotation.normalized() * controlledNode.quaternion - controlledNode.transform.basis = Basis(t).orthonormalized() + FreeSpin.handle_free_spin_input(controlledNode, rs)