diff --git a/base/scenes/player.tscn b/base/scenes/player.tscn index d0fcbf3..f755b17 100644 --- a/base/scenes/player.tscn +++ b/base/scenes/player.tscn @@ -1,8 +1,10 @@ -[gd_scene load_steps=5 format=3 uid="uid://dwx5tcatj35gu"] +[gd_scene load_steps=7 format=3 uid="uid://dwx5tcatj35gu"] [ext_resource type="Script" uid="uid://dts8lbivkgsmj" path="res://base/scripts/player/player.gd" id="1_1w3ab"] [ext_resource type="Texture2D" uid="uid://cfw6p5g680c55" path="res://base/assets/sprites/guns/placeholder/shoot1.png" id="2_i1xqq"] [ext_resource type="PackedScene" uid="uid://bb6ovrbusyxpi" path="res://base/scenes/weapons/weapon_base.tscn" id="2_ma1q3"] +[ext_resource type="Script" uid="uid://byhp4pklbjltn" path="res://base/scripts/player/weapon_container.gd" id="3_1w3ab"] +[ext_resource type="Script" uid="uid://diu6eno2ag6ga" path="res://base/scripts/player/weapon_slot.gd" id="4_gt0rj"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_jjqxs"] @@ -49,5 +51,18 @@ theme_override_font_sizes/font_size = 32 text = "0/0" [node name="WeaponContainer" type="Node3D" parent="."] +script = ExtResource("3_1w3ab") -[node name="Weapon" parent="WeaponContainer" instance=ExtResource("2_ma1q3")] +[node name="Primary" type="Node3D" parent="WeaponContainer"] +script = ExtResource("4_gt0rj") +metadata/_custom_type_script = "uid://diu6eno2ag6ga" + +[node name="Weapon" parent="WeaponContainer/Primary" instance=ExtResource("2_ma1q3")] + +[node name="Secondary" type="Node3D" parent="WeaponContainer"] +script = ExtResource("4_gt0rj") +metadata/_custom_type_script = "uid://diu6eno2ag6ga" + +[node name="Tertiary" type="Node3D" parent="WeaponContainer"] +script = ExtResource("4_gt0rj") +metadata/_custom_type_script = "uid://diu6eno2ag6ga" diff --git a/base/scripts/player/player.gd b/base/scripts/player/player.gd index 0b20b29..876a22e 100644 --- a/base/scripts/player/player.gd +++ b/base/scripts/player/player.gd @@ -9,7 +9,7 @@ var queue: CommandQueue = CommandQueue.new() @onready var camera: Camera3D = $"Camera" @onready var weapon_player: AnimationPlayer = $"HUD/Weapon/AnimationPlayer" -@onready var weapons: Node3D = $"WeaponContainer" +@onready var weapons: WeaponContainer = $"WeaponContainer" # Placeholder UI @onready var ammo_label: Label = $"HUD/Ammo" @@ -20,19 +20,15 @@ func _ready() -> void: queue.command_pushed.connect(on_queue_command_pushed) queue.command_popped.connect(on_queue_command_popped) - current_weapon = weapons.get_child(0) as Weapon - current_weapon.fired.connect(on_weapon_fired) - current_weapon.fire_failed.connect(finish_task) - - weapon_player.add_animation_library("current", current_weapon.animation_library) - weapon_player.play("current/static") - + weapons.slot_selected.connect(on_weapon_slot_selected) + + get_tree().create_timer(0.02).timeout.connect(on_weapon_slot_selected) + Input.mouse_mode = Input.MOUSE_MODE_CAPTURED - - update_ammo_label() - + func _process(_delta: float) -> void: - + if current_weapon == null: + return var weapon_sides = current_weapon.uses_hands var weapon_sides_are_free = not queue.sides_are_busy(weapon_sides) if weapon_sides_are_free: @@ -77,6 +73,25 @@ func _input(event): camera.rotation.x = new_rotation rotation.y -= event.relative.x * horizontal_sensivity +func on_weapon_slot_selected(): + if current_weapon != null: + current_weapon.fired.disconnect(on_weapon_fired) + current_weapon.fire_failed.disconnect(finish_task) + + weapon_player.remove_animation_library("current") + + current_weapon = weapons.current_weapon + print('im here') + + current_weapon.fired.connect(on_weapon_fired) + current_weapon.fire_failed.connect(finish_task) + + weapon_player.add_animation_library("current", current_weapon.animation_library) + weapon_player.play("current/static") + + update_ammo_label() + + func on_queue_command_pushed(commands: Dictionary): for side in commands: match side: @@ -91,7 +106,6 @@ func push_copied_command(command: CommandQueue.Command, sides: Array[CommandQueu commands[side] = command queue.push(commands) - func finish_task(): queue.pop() diff --git a/base/scripts/player/weapon_container.gd b/base/scripts/player/weapon_container.gd new file mode 100644 index 0000000..3838ab0 --- /dev/null +++ b/base/scripts/player/weapon_container.gd @@ -0,0 +1,30 @@ +extends Node3D +class_name WeaponContainer + +var slots: Array[WeaponSlot] +var current_slot: WeaponSlot = null +var current_weapon: Weapon + +signal slot_selected() + +func _ready(): + for slot in get_children(): + assert(slot is WeaponSlot) + slots.push_back(slot as WeaponSlot) + + for slot in range(slots.size()): + if current_slot == null: + select_slot(slot) + else: + break + + assert(current_slot != null) + +func select_slot(index: int): + assert(index < slots.size()) + + if slots[index].has_weapon: + current_slot = slots[index] + current_weapon = current_slot.weapon + print('here we go') + slot_selected.emit() diff --git a/base/scripts/player/weapon_container.gd.uid b/base/scripts/player/weapon_container.gd.uid new file mode 100644 index 0000000..903e5f7 --- /dev/null +++ b/base/scripts/player/weapon_container.gd.uid @@ -0,0 +1 @@ +uid://byhp4pklbjltn diff --git a/base/scripts/player/weapon_slot.gd b/base/scripts/player/weapon_slot.gd new file mode 100644 index 0000000..11e3bc6 --- /dev/null +++ b/base/scripts/player/weapon_slot.gd @@ -0,0 +1,14 @@ +extends Node3D + +class_name WeaponSlot + +var has_weapon = false +var weapon: Weapon + +func _ready(): + has_weapon = get_child_count() > 0 + + if has_weapon: + var child = get_child(0) + assert(child is Weapon) + weapon = child as Weapon diff --git a/base/scripts/player/weapon_slot.gd.uid b/base/scripts/player/weapon_slot.gd.uid new file mode 100644 index 0000000..401fcf7 --- /dev/null +++ b/base/scripts/player/weapon_slot.gd.uid @@ -0,0 +1 @@ +uid://diu6eno2ag6ga diff --git a/project.godot b/project.godot index b704b7d..b75c7bb 100644 --- a/project.godot +++ b/project.godot @@ -51,6 +51,31 @@ reload={ "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":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null) ] } +slot_primary={ +"deadzone": 0.2, +"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":49,"key_label":0,"unicode":49,"location":0,"echo":false,"script":null) +] +} +slot_secondary={ +"deadzone": 0.2, +"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":50,"key_label":0,"unicode":50,"location":0,"echo":false,"script":null) +] +} +slot_tertiary={ +"deadzone": 0.2, +"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":51,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null) +] +} +slot_next={ +"deadzone": 0.2, +"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":16,"position":Vector2(230, 5),"global_position":Vector2(239, 53),"factor":1.0,"button_index":5,"canceled":false,"pressed":true,"double_click":false,"script":null) +] +} +slot_previous={ +"deadzone": 0.2, +"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":8,"position":Vector2(402, 28),"global_position":Vector2(411, 76),"factor":1.0,"button_index":4,"canceled":false,"pressed":true,"double_click":false,"script":null) +] +} [layer_names]