From 8dd9e0b4c5e79f5596738c48dc946b87c0163f53 Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Mon, 30 Dec 2024 15:50:41 -0700 Subject: [PATCH] Added logic for next/prev club select in shot setup --- project.godot | 9 +++++---- src/player/shot_setup/shot_setup.gd | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/project.godot b/project.godot index bc989cf..affcf3e 100644 --- a/project.godot +++ b/project.godot @@ -17,6 +17,7 @@ run/main_scene="res://src/game/game.tscn" config/use_custom_user_dir=true config/project_settings_override="user://settings.godot" config/features=PackedStringArray("4.3", "Forward Plus") +run/max_fps=60 [autoload] @@ -186,22 +187,22 @@ select_putter={ } club_next={ "deadzone": 0.5, -"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(105, 13),"global_position":Vector2(114, 59),"factor":1.0,"button_index":8,"canceled":false,"pressed":true,"double_click":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194306,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } club_previous={ "deadzone": 0.5, -"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(277, 2),"global_position":Vector2(286, 48),"factor":1.0,"button_index":9,"canceled":false,"pressed":true,"double_click":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194306,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } ball_next={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":71,"key_label":0,"unicode":103,"location":0,"echo":false,"script":null) ] } ball_previous={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":71,"key_label":0,"unicode":71,"location":0,"echo":false,"script":null) ] } pause={ diff --git a/src/player/shot_setup/shot_setup.gd b/src/player/shot_setup/shot_setup.gd index 16c3a50..d3ceb4e 100644 --- a/src/player/shot_setup/shot_setup.gd +++ b/src/player/shot_setup/shot_setup.gd @@ -53,6 +53,10 @@ const NICE_THRESHOLD := 0.2 ## Force by which explosions knock the ball away const EXPLOSIVE_FORCE_FACTOR := 0.12 +const CLUB_SELECT_ORDER: Array[Club.Type] = [ + Club.Type.DRIVER, Club.Type.IRON, Club.Type.WEDGE, Club.Type.SPECIAL, Club.Type.PUTTER +] + ## In Driving Range mode, the ball can be retrieved in the shot phase. @export var driving_range := false @@ -534,6 +538,20 @@ func _on_game_ball_changed(ball: GameBall) -> void: player_offset.position.z = z_offset +func _get_relative_club(delta: int, from: int = -1) -> Club.Type: + from = from if from != -1 else club_type + var old_idx := CLUB_SELECT_ORDER.find(from) + var new_idx := wrapi(old_idx + delta, 0, len(CLUB_SELECT_ORDER)) + var new_club := CLUB_SELECT_ORDER[new_idx] + + # UX behavior: if there is not club in the next slot, get the NEXT next slot, etc etc + # NOTE: this will enter a loop if the player has no clubs! + if not player.get_club(new_club): + return _get_relative_club(delta, new_club) + + return new_club + + func _process(_delta: float) -> void: # REMOVEME if Input.is_action_just_pressed("ui_menu"): @@ -587,6 +605,10 @@ func _process(_delta: float) -> void: camera_distance = min(camera_distance + 1.0, ZOOM_MAX) # Club select + if Input.is_action_just_pressed("club_next"): + club_type = _get_relative_club(1) + if Input.is_action_just_pressed("club_previous"): + club_type = _get_relative_club(-1) if Input.is_action_just_pressed("select_driver"): club_type = Club.Type.DRIVER if Input.is_action_just_pressed("select_iron"):