uploading before earth explodes
This commit is contained in:
parent
80dfcec856
commit
5c4c0384ba
12 changed files with 228 additions and 223 deletions
0
.zed/settings.json
Normal file
0
.zed/settings.json
Normal file
|
@ -1,23 +1,35 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://bshvduqysqivm"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://cn7tgd4y67wnd"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ct5na682hxc6g" path="res://src/input_listener.gd" id="1_qw0r6"]
|
||||
[ext_resource type="Script" uid="uid://qvoqvonnxwfc" path="res://src/inventory_ui.gd" id="2_hj2ta"]
|
||||
[ext_resource type="Resource" uid="uid://bllq6ri54q3ne" path="res://resources/player_inventory.tres" id="3_ty45s"]
|
||||
[ext_resource type="Script" uid="uid://c62nslejr74jw" path="res://src/h_item_list.gd" id="4_yyk2a"]
|
||||
[ext_resource type="PackedScene" uid="uid://gn8k2ir47n1m" path="res://scenes/inventory_item.tscn" id="5_uae8j"]
|
||||
[ext_resource type="Script" uid="uid://dfvvqpgu8r5v6" path="res://src/item_details_ui.gd" id="6_uae8j"]
|
||||
[ext_resource type="Script" uid="uid://qvoqvonnxwfc" path="res://src/inventory_ui.gd" id="1_a0rpf"]
|
||||
[ext_resource type="Script" uid="uid://bx4wxlm5mv268" path="res://src/root_control.gd" id="1_as33y"]
|
||||
[ext_resource type="Resource" uid="uid://bllq6ri54q3ne" path="res://resources/player_inventory.tres" id="2_as33y"]
|
||||
[ext_resource type="PackedScene" uid="uid://gn8k2ir47n1m" path="res://scenes/inventory_item.tscn" id="3_tg4gd"]
|
||||
[ext_resource type="Script" uid="uid://13lxe4c4fmrp" path="res://addons/FreeControl/src/CustomClasses/Carousel/Carousel.gd" id="4_usnyx"]
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
visible = false
|
||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_as33y"]
|
||||
size = Vector2(128, 128)
|
||||
|
||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_tg4gd"]
|
||||
size = Vector2(128, 128)
|
||||
|
||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_usnyx"]
|
||||
size = Vector2(128, 64)
|
||||
|
||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_sebc8"]
|
||||
size = Vector2(256, 256)
|
||||
|
||||
[node name="Inventory" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
focus_mode = 2
|
||||
script = ExtResource("1_qw0r6")
|
||||
open_action = &"inventory"
|
||||
script = ExtResource("1_as33y")
|
||||
open_action = &"open_inventory"
|
||||
close_action = &"ui_close_inventory"
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
|
@ -27,64 +39,74 @@ anchor_right = 1.0
|
|||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0.10748, 0.10748, 0.10748, 1)
|
||||
color = Color(0.147672, 0.147672, 0.147672, 1)
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
clip_contents = true
|
||||
[node name="Contents" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("2_hj2ta")
|
||||
inventory = ExtResource("3_ty45s")
|
||||
|
||||
[node name="ItemNavigation" type="HBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HItemList" type="HBoxContainer" parent="VBoxContainer/ItemNavigation"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
script = ExtResource("4_yyk2a")
|
||||
item_scene = ExtResource("5_uae8j")
|
||||
|
||||
[node name="Details" type="HBoxContainer" parent="VBoxContainer" node_paths=PackedStringArray("icon_image", "description_label")]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource("6_uae8j")
|
||||
icon_image = NodePath("ItemDisplay/TextureRect")
|
||||
description_label = NodePath("ItemDescription/Label")
|
||||
|
||||
[node name="Status" type="VBoxContainer" parent="VBoxContainer/Details"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="ItemDisplay" type="HBoxContainer" parent="VBoxContainer/Details"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
alignment = 1
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Details/ItemDisplay"]
|
||||
[node name="InventoryUI" type="Control" parent="Contents" node_paths=PackedStringArray("carousel")]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
expand_mode = 5
|
||||
stretch_mode = 4
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource("1_a0rpf")
|
||||
inventory = ExtResource("2_as33y")
|
||||
item_scene = ExtResource("3_tg4gd")
|
||||
carousel = NodePath("Carousel")
|
||||
metadata/_custom_type_script = "uid://qvoqvonnxwfc"
|
||||
|
||||
[node name="ItemDescription" type="Control" parent="VBoxContainer/Details"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/Details/ItemDescription"]
|
||||
[node name="Carousel" type="Container" parent="Contents/InventoryUI"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
autowrap_mode = 2
|
||||
script = ExtResource("4_usnyx")
|
||||
display_range = 5
|
||||
snap_behavior = 2
|
||||
paging_requirement = 100
|
||||
|
||||
[connection signal="closed" from="." to="." method="hide"]
|
||||
[connection signal="opened" from="." to="." method="show"]
|
||||
[connection signal="opened" from="." to="." method="grab_focus"]
|
||||
[connection signal="selected" from="VBoxContainer/ItemNavigation/HItemList" to="VBoxContainer/Details" method="_on_updated"]
|
||||
[node name="ItemDetails" type="HBoxContainer" parent="Contents"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="PlayerInfo" type="VBoxContainer" parent="Contents/ItemDetails"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="Contents/ItemDetails/PlayerInfo"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
texture = SubResource("PlaceholderTexture2D_as33y")
|
||||
|
||||
[node name="TextureRect2" type="TextureRect" parent="Contents/ItemDetails/PlayerInfo"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
texture = SubResource("PlaceholderTexture2D_tg4gd")
|
||||
|
||||
[node name="TextureRect3" type="TextureRect" parent="Contents/ItemDetails/PlayerInfo"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
texture = SubResource("PlaceholderTexture2D_usnyx")
|
||||
|
||||
[node name="Display" type="VBoxContainer" parent="Contents/ItemDetails"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="Contents/ItemDetails/Display"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
texture = SubResource("PlaceholderTexture2D_sebc8")
|
||||
|
||||
[node name="Description" type="VBoxContainer" parent="Contents/ItemDetails"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Label" type="Label" parent="Contents/ItemDetails/Description"]
|
||||
layout_mode = 2
|
||||
text = "a description"
|
||||
|
|
|
@ -1,115 +0,0 @@
|
|||
[gd_scene load_steps=10 format=3 uid="uid://cn7tgd4y67wnd"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://qvoqvonnxwfc" path="res://src/inventory_ui.gd" id="1_a0rpf"]
|
||||
[ext_resource type="Script" uid="uid://bx4wxlm5mv268" path="res://src/root_control.gd" id="1_as33y"]
|
||||
[ext_resource type="Resource" uid="uid://bllq6ri54q3ne" path="res://resources/player_inventory.tres" id="2_as33y"]
|
||||
[ext_resource type="PackedScene" uid="uid://gn8k2ir47n1m" path="res://scenes/inventory_item.tscn" id="3_tg4gd"]
|
||||
[ext_resource type="Script" uid="uid://13lxe4c4fmrp" path="res://addons/FreeControl/src/CustomClasses/Carousel/Carousel.gd" id="4_usnyx"]
|
||||
|
||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_as33y"]
|
||||
size = Vector2(128, 128)
|
||||
|
||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_tg4gd"]
|
||||
size = Vector2(128, 128)
|
||||
|
||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_usnyx"]
|
||||
size = Vector2(128, 64)
|
||||
|
||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_sebc8"]
|
||||
size = Vector2(256, 256)
|
||||
|
||||
[node name="Inventory" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
focus_mode = 2
|
||||
script = ExtResource("1_as33y")
|
||||
open_action = &"open_inventory"
|
||||
close_action = &"ui_close_inventory"
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0.147672, 0.147672, 0.147672, 1)
|
||||
|
||||
[node name="Contents" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="InventoryUI" type="Control" parent="Contents" node_paths=PackedStringArray("carousel")]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource("1_a0rpf")
|
||||
inventory = ExtResource("2_as33y")
|
||||
item_scene = ExtResource("3_tg4gd")
|
||||
carousel = NodePath("Carousel")
|
||||
metadata/_custom_type_script = "uid://qvoqvonnxwfc"
|
||||
|
||||
[node name="Carousel" type="Container" parent="Contents/InventoryUI"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -104.0
|
||||
offset_top = 5.0
|
||||
offset_right = -104.0
|
||||
offset_bottom = 5.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("4_usnyx")
|
||||
display_range = 4
|
||||
snap_behavior = 2
|
||||
paging_requirement = 100
|
||||
|
||||
[node name="ItemDetails" type="HBoxContainer" parent="Contents"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="PlayerInfo" type="VBoxContainer" parent="Contents/ItemDetails"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="Contents/ItemDetails/PlayerInfo"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
texture = SubResource("PlaceholderTexture2D_as33y")
|
||||
|
||||
[node name="TextureRect2" type="TextureRect" parent="Contents/ItemDetails/PlayerInfo"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
texture = SubResource("PlaceholderTexture2D_tg4gd")
|
||||
|
||||
[node name="TextureRect3" type="TextureRect" parent="Contents/ItemDetails/PlayerInfo"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
texture = SubResource("PlaceholderTexture2D_usnyx")
|
||||
|
||||
[node name="Display" type="VBoxContainer" parent="Contents/ItemDetails"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="Contents/ItemDetails/Display"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
texture = SubResource("PlaceholderTexture2D_sebc8")
|
||||
|
||||
[node name="Description" type="VBoxContainer" parent="Contents/ItemDetails"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Label" type="Label" parent="Contents/ItemDetails/Description"]
|
||||
layout_mode = 2
|
||||
text = "a description"
|
|
@ -1,13 +1,14 @@
|
|||
[gd_scene load_steps=14 format=3 uid="uid://dttyp3682enn7"]
|
||||
[gd_scene load_steps=15 format=3 uid="uid://dttyp3682enn7"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://crbrniwi6kd3p" path="res://scenes/player.tscn" id="1_2q6dc"]
|
||||
[ext_resource type="Script" uid="uid://csjccrhj5wnx7" path="res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_3d.gd" id="2_klq6b"]
|
||||
[ext_resource type="Script" uid="uid://r8orotw16wn8" path="res://src/door.gd" id="2_w8frs"]
|
||||
[ext_resource type="Script" uid="uid://ds8lef4lc6xuj" path="res://src/door.gd" id="2_w8frs"]
|
||||
[ext_resource type="Script" uid="uid://8umksf8e80fw" path="res://addons/phantom_camera/scripts/resources/tween_resource.gd" id="3_b121j"]
|
||||
[ext_resource type="Script" uid="uid://b5eitlv3jchk" path="res://src/interactable.gd" id="3_w8frs"]
|
||||
[ext_resource type="Script" uid="uid://dyghf5fq7s72x" path="res://src/interactable.gd" id="3_w8frs"]
|
||||
[ext_resource type="Script" uid="uid://bd046eokvcnu2" path="res://addons/phantom_camera/scripts/phantom_camera_host/phantom_camera_host.gd" id="4_8c41q"]
|
||||
[ext_resource type="Script" uid="uid://cdvtrsqkkxtdd" path="res://src/persistence.gd" id="4_mx8sn"]
|
||||
[ext_resource type="PackedScene" uid="uid://bshvduqysqivm" path="res://scenes/inventory.tscn" id="8_b121j"]
|
||||
[ext_resource type="Resource" uid="uid://cqfnwpmo4fyv4" path="res://resources/items/key.tres" id="7_8c41q"]
|
||||
[ext_resource type="PackedScene" uid="uid://cn7tgd4y67wnd" path="res://scenes/inventory.tscn" id="8_b121j"]
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_rd3vj"]
|
||||
|
||||
|
@ -69,6 +70,8 @@ transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 10,
|
|||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5)
|
||||
collision_layer = 3
|
||||
script = ExtResource("2_w8frs")
|
||||
is_locked = true
|
||||
key = ExtResource("7_8c41q")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Door"]
|
||||
transform = Transform3D(2, 0, 0, 0, 2.5, 0, 0, 0, 0.5, 0, 1.25, 0)
|
||||
|
@ -107,8 +110,8 @@ layout_mode = 2
|
|||
text = "Load
|
||||
"
|
||||
|
||||
[node name="Control2" parent="CanvasLayer" instance=ExtResource("8_b121j")]
|
||||
visible = true
|
||||
[node name="Inventory" parent="CanvasLayer" instance=ExtResource("8_b121j")]
|
||||
visible = false
|
||||
|
||||
[connection signal="interacted" from="Door/Interactable" to="Door" method="_on_interact"]
|
||||
[connection signal="pressed" from="CanvasLayer/Control/HBoxContainer/SaveButton" to="CanvasLayer/Control/Persistence" method="save" binds= ["save1.sav"]]
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
[gd_scene load_steps=42 format=3 uid="uid://crbrniwi6kd3p"]
|
||||
[gd_scene load_steps=44 format=3 uid="uid://crbrniwi6kd3p"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dpmbimh6m4ari" path="res://scenes/player_mesh.tscn" id="1_3vyb7"]
|
||||
[ext_resource type="Script" uid="uid://50vv0ta67tgl" path="res://src/player.gd" id="1_qhqgy"]
|
||||
[ext_resource type="Script" uid="uid://cngjp2wws4ld2" path="res://src/player_input.gd" id="3_dqkch"]
|
||||
[ext_resource type="Script" uid="uid://d1drx1b1s1evy" path="res://src/player.gd" id="1_qhqgy"]
|
||||
[ext_resource type="Script" uid="uid://877g2wvcupw6" path="res://src/player_input.gd" id="3_dqkch"]
|
||||
[ext_resource type="Script" uid="uid://c3wlcxy4vnm2i" path="res://src/interactor.gd" id="4_dqkch"]
|
||||
[ext_resource type="Script" uid="uid://csjl56hf0fnoy" path="res://src/item_container.gd" id="5_qlg0r"]
|
||||
[ext_resource type="Resource" uid="uid://bllq6ri54q3ne" path="res://resources/player_inventory.tres" id="6_tuyoq"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_qhqgy"]
|
||||
|
||||
|
@ -174,9 +176,10 @@ script = ExtResource("1_qhqgy")
|
|||
[node name="Input" type="Node" parent="."]
|
||||
script = ExtResource("3_dqkch")
|
||||
|
||||
[node name="Interactor" type="Node3D" parent="." node_paths=PackedStringArray("area")]
|
||||
[node name="Interactor" type="Node3D" parent="." node_paths=PackedStringArray("area", "root_node")]
|
||||
script = ExtResource("4_dqkch")
|
||||
area = NodePath("Area3D")
|
||||
root_node = NodePath("..")
|
||||
|
||||
[node name="Area3D" type="Area3D" parent="Interactor"]
|
||||
collision_mask = 2
|
||||
|
@ -199,4 +202,8 @@ anim_player = NodePath("../Mesh/AnimationPlayer")
|
|||
parameters/Handgun/BlendTree/Blend2/blend_amount = 1.0
|
||||
parameters/Handgun/Walk/Blend2/blend_amount = 1.0
|
||||
|
||||
[node name="ItemContainer" type="Node" parent="."]
|
||||
script = ExtResource("5_qlg0r")
|
||||
inventory = ExtResource("6_tuyoq")
|
||||
|
||||
[editable path="Mesh"]
|
||||
|
|
|
@ -1,8 +1,79 @@
|
|||
class_name Door extends StaticBody3D
|
||||
|
||||
const Interactor = preload("res://src/interactor.gd")
|
||||
signal opened
|
||||
signal closed
|
||||
signal locked
|
||||
signal unlocked
|
||||
|
||||
@export var locked: bool = false
|
||||
@export var is_open: bool = false
|
||||
@export var is_locked: bool = false
|
||||
@export var key: Item
|
||||
|
||||
func _on_interact(_interactor: Interactor):
|
||||
print('interacting!! with the door!!')
|
||||
var requires_key: bool:
|
||||
get: return key != null
|
||||
|
||||
class UnopenableDoorError:
|
||||
static var name:
|
||||
get: return "UnopenableDoorError"
|
||||
class NodeNoInventoryError:
|
||||
static var name:
|
||||
get: return "NodeNoInventoryError"
|
||||
class MissingKeyError:
|
||||
static var name:
|
||||
get: return "MissingKeyError"
|
||||
class LockedError:
|
||||
static var name:
|
||||
get: return "LockedError"
|
||||
|
||||
func check_requirements(interactor: Node) -> Result:
|
||||
if not is_locked: return Result.Unit
|
||||
elif not requires_key: return Result.err(UnopenableDoorError)
|
||||
|
||||
match NodeExt.find_child_variant(interactor, ItemContainer):
|
||||
var opt when opt.is_none(): return Result.err(NodeNoInventoryError)
|
||||
var opt: match opt.unwrap():
|
||||
var inv when inv.has_item(key): return Result.Unit
|
||||
_: return Result.err(MissingKeyError)
|
||||
|
||||
func open() -> Result:
|
||||
if is_locked: return Result.err(LockedError)
|
||||
if not is_open:
|
||||
is_open = true
|
||||
opened.emit()
|
||||
return Result.Unit
|
||||
|
||||
func close() -> Result:
|
||||
if is_open:
|
||||
is_open = false
|
||||
closed.emit()
|
||||
return Result.Unit
|
||||
|
||||
func unlock() -> Result:
|
||||
if is_locked:
|
||||
is_locked = false
|
||||
unlocked.emit()
|
||||
return Result.Unit
|
||||
|
||||
func lock() -> Result:
|
||||
if not is_locked:
|
||||
is_locked = true
|
||||
locked.emit()
|
||||
return Result.Unit
|
||||
|
||||
func try_unlock(node: Node) -> Result:
|
||||
match check_requirements(node):
|
||||
var result when result.is_ok(): return unlock()
|
||||
var err: return err
|
||||
|
||||
func try_open(node: Node) -> Result:
|
||||
if is_locked: return try_unlock(node)
|
||||
else: return open()
|
||||
|
||||
func try_interact(node: Node) -> Result:
|
||||
if is_open: return close()
|
||||
else: return try_open(node)
|
||||
|
||||
func _on_interact(interactor: Interactor):
|
||||
match try_interact(interactor.root_node):
|
||||
var ok when ok.is_ok(): pass
|
||||
var err: push_error(err.unwrap_err().name)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
extends Node3D
|
||||
class_name Interactable extends Node3D
|
||||
|
||||
const Interactor = preload("res://src/interactor.gd")
|
||||
signal interacted(interactor: Interactor)
|
||||
|
||||
func interact(interactor: Node):
|
||||
|
|
|
@ -1,72 +1,72 @@
|
|||
extends Node3D
|
||||
class_name Interactor extends Node3D
|
||||
|
||||
const Interactable = preload("res://src/interactable.gd")
|
||||
const EnterSignals: Array[String] = ["area_entered", "body_entered"]
|
||||
const ExitSignals: Array[String] = ["area_exited", "body_exited"]
|
||||
|
||||
@export var area: Area3D
|
||||
@export var root_node: Node = self
|
||||
|
||||
class InteractableNode:
|
||||
var _body: CollisionObject3D
|
||||
var _interactable: Interactable
|
||||
var _body: CollisionObject3D
|
||||
var _interactable: Interactable
|
||||
|
||||
var global_position: Vector3:
|
||||
get: return _body.global_position
|
||||
var global_position: Vector3:
|
||||
get: return _body.global_position
|
||||
|
||||
func _init(body: CollisionObject3D, interactable: Interactable):
|
||||
_body = body
|
||||
_interactable = interactable
|
||||
func _init(body: CollisionObject3D, interactable: Interactable):
|
||||
_body = body
|
||||
_interactable = interactable
|
||||
|
||||
func interact(interactor: Node):
|
||||
_interactable.interact(interactor)
|
||||
func interact(interactor: Node):
|
||||
_interactable.interact(interactor)
|
||||
|
||||
func squared_distance_to(b: InteractableNode) -> float:
|
||||
return global_position.distance_squared_to(b.global_position)
|
||||
func squared_distance_to(b: InteractableNode) -> float:
|
||||
return global_position.distance_squared_to(b.global_position)
|
||||
|
||||
var interactables: Array[InteractableNode] = []
|
||||
var _sorted: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
_connect_many(area, EnterSignals, _on_object_entered)
|
||||
_connect_many(area, ExitSignals, _on_object_exited)
|
||||
_connect_many(area, EnterSignals, _on_object_entered)
|
||||
_connect_many(area, ExitSignals, _on_object_exited)
|
||||
|
||||
func _connect_many(node: Node, signals: Array[String], fn: Callable):
|
||||
for signal_name in signals:
|
||||
node.connect(signal_name, fn)
|
||||
for signal_name in signals:
|
||||
node.connect(signal_name, fn)
|
||||
|
||||
func _on_object_entered(object: CollisionObject3D):
|
||||
_sorted = false
|
||||
var child = NodeExt.find_child_variant(object, Interactable)
|
||||
if child.is_some():
|
||||
interactables.append(InteractableNode.new(object, child.unwrap() as Interactable))
|
||||
_sorted = false
|
||||
var child = NodeExt.find_child_variant(object, Interactable)
|
||||
if child.is_some():
|
||||
interactables.append(InteractableNode.new(object, child.unwrap() as Interactable))
|
||||
|
||||
func is_same_object(object: CollisionObject3D, node: InteractableNode) -> bool:
|
||||
return object == node._body
|
||||
return object == node._body
|
||||
|
||||
func _on_object_exited(object: CollisionObject3D):
|
||||
var index = interactables.find_custom(
|
||||
func(node): return is_same_object(object, node)
|
||||
)
|
||||
var index = interactables.find_custom(
|
||||
func(node): return is_same_object(object, node)
|
||||
)
|
||||
|
||||
if index >= 0:
|
||||
interactables.remove_at(index)
|
||||
if index >= 0:
|
||||
interactables.remove_at(index)
|
||||
|
||||
func _distance_from(node: InteractableNode) -> float:
|
||||
return global_position.distance_squared_to(node.global_position)
|
||||
return global_position.distance_squared_to(node.global_position)
|
||||
|
||||
func _distance_compare(a: InteractableNode, b: InteractableNode):
|
||||
return _distance_from(a) > _distance_from(b)
|
||||
return _distance_from(a) > _distance_from(b)
|
||||
|
||||
func _sort_by_distance():
|
||||
interactables.sort_custom(_distance_compare)
|
||||
_sorted = true
|
||||
interactables.sort_custom(_distance_compare)
|
||||
_sorted = true
|
||||
|
||||
func interact(interactable: InteractableNode):
|
||||
interactable.interact(self)
|
||||
interactable.interact(self)
|
||||
|
||||
func interact_nearest():
|
||||
if not _sorted:
|
||||
_sort_by_distance()
|
||||
if not _sorted:
|
||||
_sort_by_distance()
|
||||
|
||||
if len(interactables) > 0:
|
||||
return interact(interactables[0])
|
||||
if len(interactables) > 0:
|
||||
return interact(interactables[0])
|
||||
|
|
1
godot/src/item_cointainer.gd.uid
Normal file
1
godot/src/item_cointainer.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://bbkm8bt2mrq1c
|
18
godot/src/item_container.gd
Normal file
18
godot/src/item_container.gd
Normal file
|
@ -0,0 +1,18 @@
|
|||
class_name ItemContainer extends Node
|
||||
|
||||
@export var inventory: Inventory
|
||||
|
||||
func has_item(item: Item) -> bool:
|
||||
return inventory.has_item(item)
|
||||
|
||||
func find(item: Item) -> Option:
|
||||
return inventory.find(item)
|
||||
|
||||
func add_item(item: Item, quantity: int = 1):
|
||||
return inventory.add_item(item, quantity)
|
||||
|
||||
func remove_item(item: Item, quantity: int = 1):
|
||||
return inventory.remove_item(item, quantity)
|
||||
|
||||
func iter() -> Inventory.InventoryIterator:
|
||||
return inventory.iter()
|
1
godot/src/item_container.gd.uid
Normal file
1
godot/src/item_container.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://csjl56hf0fnoy
|
|
@ -1,6 +1,4 @@
|
|||
class_name NodeExt
|
||||
extends Object
|
||||
|
||||
class NodeChildIterator:
|
||||
var _node: Node
|
||||
var _include_internal: bool
|
||||
|
|
Loading…
Add table
Reference in a new issue