Finished basic PickupableItem

This commit is contained in:
Alexey 2025-08-01 13:11:26 +03:00
commit 88c56f8aed
21 changed files with 163 additions and 35 deletions

View file

@ -1,10 +1,12 @@
[gd_resource type="Resource" script_class="WeaponPickupableResource" load_steps=3 format=3 uid="uid://cdsrjmq8xd5b0"]
[gd_resource type="Resource" script_class="WeaponPickupableResource" load_steps=4 format=3 uid="uid://cdsrjmq8xd5b0"]
[ext_resource type="Script" uid="uid://dob8q3jclxrtd" path="res://base/scripts/interactive/weapon_pickupable_resource.gd" id="1_7xmtm"]
[ext_resource type="Texture2D" uid="uid://dq1uplqdiuxur" path="res://base/assets/sprites/guns/gangstaholder/world.png" id="2_bxcfp"]
[ext_resource type="PackedScene" uid="uid://cig5dryfni4f8" path="res://base/scenes/weapons/auto_weapon_test.tscn" id="2_qbjol"]
[resource]
script = ExtResource("1_7xmtm")
weapon = ExtResource("2_qbjol")
texture = ExtResource("2_bxcfp")
id = &"auto_weapon_test"
metadata/_custom_type_script = "uid://dob8q3jclxrtd"

View file

@ -1,10 +1,12 @@
[gd_resource type="Resource" script_class="WeaponPickupableResource" load_steps=3 format=3 uid="uid://b1pqbhcv5ixmy"]
[gd_resource type="Resource" script_class="WeaponPickupableResource" load_steps=4 format=3 uid="uid://b1pqbhcv5ixmy"]
[ext_resource type="Script" uid="uid://dob8q3jclxrtd" path="res://base/scripts/interactive/weapon_pickupable_resource.gd" id="1_fp2lr"]
[ext_resource type="Texture2D" uid="uid://bk7klildfi4pn" path="res://base/assets/sprites/guns/placeholder/world.png" id="2_8n6rc"]
[ext_resource type="PackedScene" uid="uid://bb6ovrbusyxpi" path="res://base/scenes/weapons/weapon_base.tscn" id="2_fp2lr"]
[resource]
script = ExtResource("1_fp2lr")
weapon = ExtResource("2_fp2lr")
texture = ExtResource("2_8n6rc")
id = &"weapon_base"
metadata/_custom_type_script = "uid://dob8q3jclxrtd"

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dq1uplqdiuxur"
path.s3tc="res://.godot/imported/world.png-e1b2c93270eed42494afaf4cd66554bd.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://base/assets/sprites/guns/gangstaholder/world.png"
dest_files=["res://.godot/imported/world.png-e1b2c93270eed42494afaf4cd66554bd.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bk7klildfi4pn"
path.s3tc="res://.godot/imported/world.png-eaa9564d3ed78f593557d4bf4bb259eb.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://base/assets/sprites/guns/placeholder/world.png"
dest_files=["res://.godot/imported/world.png-eaa9564d3ed78f593557d4bf4bb259eb.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

View file

@ -1,8 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://d23028pr0jahr"]
[gd_scene load_steps=3 format=3 uid="uid://d23028pr0jahr"]
[ext_resource type="PackedScene" uid="uid://bgnb01j1nphhi" path="res://base/scenes/rooms/test.tscn" id="1_sjeh3"]
[ext_resource type="PackedScene" uid="uid://dwx5tcatj35gu" path="res://base/scenes/player.tscn" id="2_uxs03"]
[ext_resource type="PackedScene" uid="uid://twqkevpn0q1a" path="res://base/scenes/enemies/test_enemy.tscn" id="3_tk4w0"]
[node name="Game" type="Node3D"]
@ -11,6 +10,3 @@
[node name="Player" parent="." instance=ExtResource("2_uxs03")]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.208048, 1.61008)
[node name="TestEnemy" parent="." instance=ExtResource("3_tk4w0")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.695979)

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://ddjjrkernsobh"]
[ext_resource type="Texture2D" uid="uid://bdgoa18kfhlwo" path="res://base/assets/sprites/interactive/interactive.png" id="1_yf10f"]
[ext_resource type="Script" uid="uid://fva8kqc3mk86" path="res://base/scripts/interactive_object.gd" id="2_cdwk3"]
[ext_resource type="Script" uid="uid://junnt60g6c7x" path="res://base/scripts/interactive/interactive_object.gd" id="2_cdwk3"]
[sub_resource type="SphereShape3D" id="SphereShape3D_cdwk3"]
@ -11,8 +11,11 @@ billboard = 1
texture_filter = 0
texture = ExtResource("1_yf10f")
script = ExtResource("2_cdwk3")
metadata/_custom_type_script = "uid://junnt60g6c7x"
[node name="Area3D" type="Area3D" parent="."]
collision_layer = 16
collision_mask = 2
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
shape = SubResource("SphereShape3D_cdwk3")

View file

@ -13,6 +13,8 @@ texture = ExtResource("1_2373a")
script = ExtResource("2_2373a")
[node name="Area3D" type="Area3D" parent="."]
collision_layer = 16
collision_mask = 2
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
shape = SubResource("SphereShape3D_cdwk3")

View file

@ -1,11 +1,10 @@
[gd_scene load_steps=12 format=3 uid="uid://dwx5tcatj35gu"]
[gd_scene load_steps=11 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://cf7avgppv4kfk" path="res://base/assets/sprites/guns/placeholder/static.png" id="2_gt0rj"]
[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"]
[ext_resource type="PackedScene" uid="uid://cig5dryfni4f8" path="res://base/scenes/weapons/auto_weapon_test.tscn" id="6_gt0rj"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_jjqxs"]
@ -67,7 +66,7 @@ _data = {
[node name="Player" type="CharacterBody3D"]
collision_layer = 2
collision_mask = 3
collision_mask = 19
platform_wall_layers = 1
script = ExtResource("1_1w3ab")
@ -120,8 +119,6 @@ metadata/_custom_type_script = "uid://diu6eno2ag6ga"
script = ExtResource("4_gt0rj")
metadata/_custom_type_script = "uid://diu6eno2ag6ga"
[node name="Weapon" parent="WeaponContainer/Secondary" instance=ExtResource("6_gt0rj")]
[node name="Tertiary" type="Node3D" parent="WeaponContainer"]
script = ExtResource("4_gt0rj")
metadata/_custom_type_script = "uid://diu6eno2ag6ga"

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=3 format=3 uid="uid://bgnb01j1nphhi"]
[gd_scene load_steps=4 format=3 uid="uid://bgnb01j1nphhi"]
[ext_resource type="PackedScene" uid="uid://c4wpq5gxkbor7" path="res://base/scenes/interactive/pickupable_item.tscn" id="1_1whpt"]
[ext_resource type="Resource" uid="uid://b1pqbhcv5ixmy" path="res://base/assets/resources/items/weapon_base.tres" id="2_ayew2"]
[ext_resource type="Resource" uid="uid://cdsrjmq8xd5b0" path="res://base/assets/resources/items/auto_weapon.tres" id="3_npgpc"]
[node name="Test Room" type="Node3D"]
@ -51,4 +52,8 @@ content = ExtResource("2_ayew2")
[node name="PickupableItem2" parent="." instance=ExtResource("1_1whpt")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.700438, -0.47008, -0.800458)
content = ExtResource("3_npgpc")
[node name="PickupableItem3" parent="." instance=ExtResource("1_1whpt")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.10903, -0.47008, 1.99618)
content = ExtResource("2_ayew2")

View file

@ -0,0 +1,35 @@
extends Node
## Dictionary, that holds resource id and path to it
var resource_registry: Dictionary = {}
const DEFAULT_WEAPON_RESOURCE_ID: StringName = "weapon_base"
## Recursively add resources to registry
func add_resource_path(_path: String) -> void:
var dir = DirAccess.open(_path)
if dir == null:
return
# Used to ignore last slash if it was provided in _path
var path = dir.get_current_dir()
for subdir in dir.get_directories():
var subdir_path = "%s/%s" % [ path, subdir ]
add_resource_path(subdir_path)
for filename in dir.get_files():
if !filename.ends_with('.tres'):
continue
var filepath = "%s/%s" % [ path, filename ]
var res: IdentifiedResource = ResourceLoader.load(filepath, 'IdentifiedResource')
resource_registry[res.id] = filepath
func get_resource(id: String) -> IdentifiedResource:
var path = resource_registry.get(id)
if path == null:
return null
var res: IdentifiedResource = ResourceLoader.load(path, 'IdentifiedResource')
return res
func _init() -> void:
add_resource_path('res://base/assets/resources')
assert(resource_registry.has(DEFAULT_WEAPON_RESOURCE_ID))

View file

@ -0,0 +1 @@
uid://b67umubha4odj

View file

@ -0,0 +1,7 @@
extends Resource
## Basic resource, holding its string identifier
class_name IdentifiedResource
## Item ID, make sure it's unique
@export var id: StringName

View file

@ -0,0 +1 @@
uid://dkk5xaxoo7i8y

View file

@ -1,13 +1,10 @@
extends Resource
extends IdentifiedResource
class_name BasePickupableResource
## Item ID, make sure it's unique
@export var id: StringName
## Texture that will be used in node sprite
@export var texture: Texture2D
## Emitted when item picked up. Returns if PickupableItem should be freed
func _apply(_player: Player) -> bool:
return true
## Emitted when item picked up. Returns IdentifiedResource if it should be swapped
func _apply(_player: Player) -> IdentifiedResource:
return null

View file

@ -9,5 +9,8 @@ func _ready() -> void:
texture = content.texture
func _interact(_player: Player) -> void:
if content._apply(_player):
content = content._apply(_player)
if content == null:
queue_free()
return
_ready()

View file

@ -5,7 +5,7 @@ class_name WeaponPickupableResource
## Weapon that will be added on interaction
@export var weapon: PackedScene
func _apply(player: Player) -> bool:
func _apply(player: Player) -> IdentifiedResource:
var slot = player.weapons.first_free_slot()
# TODO: Implement proper swapping behavior when old or new weapon uses several slots
@ -13,15 +13,11 @@ func _apply(player: Player) -> bool:
slot = player.weapons.current_slot
var set_data = slot.set_weapon(weapon)
set_data.old_weapon.id = id
set_data.new_weapon.id = id
if slot == player.weapons.current_slot:
player.weapons.refresh_current_slot()
return update_by_id(set_data.new_weapon)
# TODO: implement proper updating
func update_by_id(new_id: StringName) -> bool:
id = new_id
return id == ""
var new_res = ResourceHandler.get_resource(set_data.old_weapon) as WeaponPickupableResource
print(new_res)
return new_res

View file

@ -17,10 +17,11 @@ class WeaponSetData:
old_weapon = _old_weapon
func _ready():
has_weapon = get_child_count() > 0
var child_count = get_child_count()
has_weapon = child_count > 0
if has_weapon:
var child = get_child(0)
var child = get_child(child_count - 1)
assert(child is Weapon)
weapon = child as Weapon

View file

@ -6,7 +6,7 @@ signal fired()
signal fire_failed()
signal fire_allowed()
var id: StringName
var id: StringName = ResourceHandler.DEFAULT_WEAPON_RESOURCE_ID
@onready var barrel = $"Barrel"
@export var uses_hands: Array[CommandQueue.Side]