wow that was Fucking Annoying
This commit is contained in:
parent
b2f1aa504f
commit
f32dd273ab
12 changed files with 150 additions and 130 deletions
1
godot/addons/range/integer.gd.uid
Normal file
1
godot/addons/range/integer.gd.uid
Normal file
|
@ -0,0 +1 @@
|
||||||
|
uid://dtjqmx0kj66bx
|
|
@ -1,4 +1,4 @@
|
||||||
class_name Utils
|
class_name KCUtils
|
||||||
|
|
||||||
static func remove_children(node: Node):
|
static func remove_children(node: Node):
|
||||||
for i in range(node.get_child_count()):
|
for i in range(node.get_child_count()):
|
||||||
|
@ -6,9 +6,9 @@ static func remove_children(node: Node):
|
||||||
|
|
||||||
static func get_class_name(value: Object) -> String:
|
static func get_class_name(value: Object) -> String:
|
||||||
match value.get_script():
|
match value.get_script():
|
||||||
var script:
|
var script when script != null:
|
||||||
match script.get_global_name():
|
match script.get_global_name():
|
||||||
var name: return name
|
var name when name != null: return name
|
||||||
_: return script.get_instance_base_type()
|
_: return script.get_instance_base_type()
|
||||||
_: return value.get_class()
|
_: return value.get_class()
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,10 @@ PhantomCameraManager="*res://addons/phantom_camera/scripts/managers/phantom_came
|
||||||
|
|
||||||
enabled=PackedStringArray("res://addons/FreeControl/plugin.cfg", "res://addons/godot_object_serializer/plugin.cfg", "res://addons/phantom_camera/plugin.cfg")
|
enabled=PackedStringArray("res://addons/FreeControl/plugin.cfg", "res://addons/godot_object_serializer/plugin.cfg", "res://addons/phantom_camera/plugin.cfg")
|
||||||
|
|
||||||
|
[filesystem]
|
||||||
|
|
||||||
|
import/blender/enabled=false
|
||||||
|
|
||||||
[global_group]
|
[global_group]
|
||||||
|
|
||||||
persist=""
|
persist=""
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
[gd_resource type="Resource" script_class="Inventory" load_steps=2 format=3 uid="uid://bllq6ri54q3ne"]
|
[gd_resource type="Resource" script_class="Inventory" load_steps=5 format=3 uid="uid://bllq6ri54q3ne"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://db4nrsnmkv3h0" path="res://src/item_instance.gd" id="1_uptie"]
|
||||||
[ext_resource type="Script" uid="uid://dh4ytedxidq0x" path="res://src/inventory.gd" id="2_1njko"]
|
[ext_resource type="Script" uid="uid://dh4ytedxidq0x" path="res://src/inventory.gd" id="2_1njko"]
|
||||||
|
[ext_resource type="Resource" uid="uid://cqfnwpmo4fyv4" path="res://resources/items/key.tres" id="2_85a8j"]
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id="Resource_hfe8y"]
|
||||||
|
script = ExtResource("1_uptie")
|
||||||
|
item = ExtResource("2_85a8j")
|
||||||
|
quantity = 1
|
||||||
|
metadata/_custom_type_script = "uid://1rjq1ttxq4nd"
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
script = ExtResource("2_1njko")
|
script = ExtResource("2_1njko")
|
||||||
max_capacity = null
|
initial_items = Array[ExtResource("1_uptie")]([SubResource("Resource_hfe8y")])
|
||||||
|
max_capacity = 6
|
||||||
metadata/_custom_type_script = "uid://dh4ytedxidq0x"
|
metadata/_custom_type_script = "uid://dh4ytedxidq0x"
|
||||||
|
|
|
@ -73,7 +73,6 @@ script = ExtResource("4_usnyx")
|
||||||
display_range = 4
|
display_range = 4
|
||||||
snap_behavior = 2
|
snap_behavior = 2
|
||||||
paging_requirement = 100
|
paging_requirement = 100
|
||||||
metadata/_custom_type_script = "uid://13lxe4c4fmrp"
|
|
||||||
|
|
||||||
[node name="ItemDetails" type="HBoxContainer" parent="Contents"]
|
[node name="ItemDetails" type="HBoxContainer" parent="Contents"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
|
@ -12,13 +12,13 @@ size_flags_horizontal = 3
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
alignment = 1
|
alignment = 1
|
||||||
script = ExtResource("1_letey")
|
script = ExtResource("1_letey")
|
||||||
name_label = NodePath("VBoxContainer/Name")
|
name_label = NodePath("VBoxContainer/Label")
|
||||||
icon_texture = NodePath("VBoxContainer/Icon")
|
icon_texture = NodePath("VBoxContainer/Icon")
|
||||||
|
|
||||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="Name" type="Label" parent="VBoxContainer"]
|
[node name="Label" type="Label" parent="VBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Empty"
|
text = "Empty"
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://crbrniwi6kd3p" path="res://scenes/player.tscn" id="1_2q6dc"]
|
[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://csjccrhj5wnx7" path="res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_3d.gd" id="2_klq6b"]
|
||||||
[ext_resource type="Script" uid="uid://ds8lef4lc6xuj" path="res://src/door.gd" id="2_w8frs"]
|
[ext_resource type="Script" uid="uid://r8orotw16wn8" 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://8umksf8e80fw" path="res://addons/phantom_camera/scripts/resources/tween_resource.gd" id="3_b121j"]
|
||||||
[ext_resource type="Script" uid="uid://dyghf5fq7s72x" path="res://src/interactable.gd" id="3_w8frs"]
|
[ext_resource type="Script" uid="uid://b5eitlv3jchk" 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://bd046eokvcnu2" path="res://addons/phantom_camera/scripts/phantom_camera_host/phantom_camera_host.gd" id="4_8c41q"]
|
||||||
[ext_resource type="Script" uid="uid://pdpejp2xor23" path="res://src/persistence.gd" id="4_mx8sn"]
|
[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="PackedScene" uid="uid://bshvduqysqivm" path="res://scenes/inventory.tscn" id="8_b121j"]
|
||||||
|
|
||||||
[sub_resource type="PlaneMesh" id="PlaneMesh_rd3vj"]
|
[sub_resource type="PlaneMesh" id="PlaneMesh_rd3vj"]
|
||||||
|
@ -50,7 +50,6 @@ dead_zone_width = 0.5
|
||||||
dead_zone_height = 0.5
|
dead_zone_height = 0.5
|
||||||
show_viewfinder_in_play = true
|
show_viewfinder_in_play = true
|
||||||
spring_length = 10.0
|
spring_length = 10.0
|
||||||
metadata/_custom_type_script = "uid://csjccrhj5wnx7"
|
|
||||||
|
|
||||||
[node name="Camera3D" type="Camera3D" parent="."]
|
[node name="Camera3D" type="Camera3D" parent="."]
|
||||||
physics_interpolation_mode = 1
|
physics_interpolation_mode = 1
|
||||||
|
@ -62,7 +61,6 @@ size = 15.0
|
||||||
process_priority = 300
|
process_priority = 300
|
||||||
process_physics_priority = 300
|
process_physics_priority = 300
|
||||||
script = ExtResource("4_8c41q")
|
script = ExtResource("4_8c41q")
|
||||||
metadata/_custom_type_script = "uid://bd046eokvcnu2"
|
|
||||||
|
|
||||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 10, 0)
|
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 10, 0)
|
||||||
|
@ -94,7 +92,6 @@ offset_bottom = 40.0
|
||||||
|
|
||||||
[node name="Persistence" type="Node" parent="CanvasLayer/Control"]
|
[node name="Persistence" type="Node" parent="CanvasLayer/Control"]
|
||||||
script = ExtResource("4_mx8sn")
|
script = ExtResource("4_mx8sn")
|
||||||
metadata/_custom_type_script = "uid://pdpejp2xor23"
|
|
||||||
|
|
||||||
[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/Control"]
|
[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/Control"]
|
||||||
layout_mode = 0
|
layout_mode = 0
|
||||||
|
|
|
@ -1,9 +1,27 @@
|
||||||
class_name Inventory extends Resource
|
class_name Inventory extends Resource
|
||||||
|
|
||||||
var initial_items: Array[ItemInstance]
|
class InventoryIterator extends Iterator:
|
||||||
var items: Dictionary[RID, ItemInstance]
|
var values: Array[ItemInstance]
|
||||||
|
var size: int
|
||||||
|
var index: int = 0
|
||||||
|
|
||||||
|
@warning_ignore("shadowed_variable")
|
||||||
|
func _init(values: Array[ItemInstance], size: int = values.size()) -> void:
|
||||||
|
self.values = values
|
||||||
|
self.size = size
|
||||||
|
|
||||||
|
func next() -> Option:
|
||||||
|
if index < size:
|
||||||
|
var value = Option.some(values[index])
|
||||||
|
index += 1
|
||||||
|
return value
|
||||||
|
else:
|
||||||
|
return Option.none
|
||||||
|
|
||||||
|
@export var initial_items: Array[ItemInstance]
|
||||||
@export var max_capacity: int = 6
|
@export var max_capacity: int = 6
|
||||||
|
|
||||||
|
var items: Dictionary[int, ItemInstance]
|
||||||
var size: int:
|
var size: int:
|
||||||
get: return items.size()
|
get: return items.size()
|
||||||
|
|
||||||
|
@ -15,25 +33,28 @@ func _init():
|
||||||
call_deferred("_ready")
|
call_deferred("_ready")
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
print(initial_items.size())
|
|
||||||
for item in initial_items:
|
for item in initial_items:
|
||||||
items[item.get_rid()] = item
|
items[_get_id(item.item)] = item
|
||||||
print('setting', item)
|
updated.emit()
|
||||||
|
|
||||||
|
func _get_id(item: Item) -> int:
|
||||||
|
print(item.get_instance_id())
|
||||||
|
return item.get_instance_id()
|
||||||
|
|
||||||
func _item_eq(a: Item, b: ItemInstance) -> bool:
|
func _item_eq(a: Item, b: ItemInstance) -> bool:
|
||||||
return a.item == b
|
return a.item == b
|
||||||
|
|
||||||
func has_item(item: Item) -> bool:
|
func has_item(item: Item) -> bool:
|
||||||
return items.has(item.get_rid())
|
return items.has(_get_id(item))
|
||||||
|
|
||||||
func find(item: Item) -> Option:
|
func find(item: Item) -> Option:
|
||||||
match items.get(item.get_rid()):
|
match items.get(_get_id(item)):
|
||||||
null: return Option.none
|
null: return Option.none
|
||||||
var found: return Option.some(found)
|
var found: return Option.some(found)
|
||||||
|
|
||||||
func add_item(item: Item, quantity: int = 1):
|
func add_item(item: Item, quantity: int = 1):
|
||||||
var rid = item.get_rid()
|
var id = _get_id(item)
|
||||||
var inst = items.get_or_add(rid)
|
var inst = items.get_or_add(id)
|
||||||
inst.quantity += quantity
|
inst.quantity += quantity
|
||||||
item_added.emit(item, inst.quantity)
|
item_added.emit(item, inst.quantity)
|
||||||
updated.emit()
|
updated.emit()
|
||||||
|
@ -42,22 +63,9 @@ func remove_item(item: Item, quantity: int = 1):
|
||||||
if find(item):
|
if find(item):
|
||||||
item.quantity -= quantity
|
item.quantity -= quantity
|
||||||
if item.quantity <= 0:
|
if item.quantity <= 0:
|
||||||
items.erase(item.get_rid())
|
items.erase(_get_id(item))
|
||||||
item_removed.emit(item, item.quantity)
|
item_removed.emit(item, item.quantity)
|
||||||
updated.emit()
|
updated.emit()
|
||||||
|
|
||||||
func _iter_continue(iter: Array) -> bool:
|
func iter() -> InventoryIterator:
|
||||||
return iter[0].size()
|
return InventoryIterator.new(items.values(), max_capacity)
|
||||||
|
|
||||||
func _iter_init(iter: Array) -> bool:
|
|
||||||
iter[0] = items.keys()
|
|
||||||
return _iter_continue(iter)
|
|
||||||
|
|
||||||
func _iter_next(iter: Array) -> bool:
|
|
||||||
iter[0] += 1
|
|
||||||
return _iter_continue(iter)
|
|
||||||
|
|
||||||
func _iter_get(iter: Variant) -> ItemInstance:
|
|
||||||
var rid = iter[0]
|
|
||||||
iter.remove_at(0)
|
|
||||||
return items.get(rid)
|
|
||||||
|
|
|
@ -5,16 +5,19 @@ class_name InventoryUI extends Control
|
||||||
@export var carousel: Carousel
|
@export var carousel: Carousel
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
_build_carousel()
|
|
||||||
inventory.updated.connect(_build_carousel)
|
inventory.updated.connect(_build_carousel)
|
||||||
|
|
||||||
func _build_carousel():
|
func _build_carousel():
|
||||||
Utils.remove_children(carousel)
|
KCUtils.remove_children(carousel)
|
||||||
|
|
||||||
for instance in inventory:
|
var items = inventory.items.values()
|
||||||
print('pussy', instance)
|
var count = items.size()
|
||||||
|
for i in range(inventory.max_capacity):
|
||||||
var scene = create_item()
|
var scene = create_item()
|
||||||
bind_item(scene, Option.from(instance.item))
|
var value = Option.none
|
||||||
|
if i < count:
|
||||||
|
value = Option.some(items[i].item)
|
||||||
|
bind_item(scene, value)
|
||||||
carousel.add_child(scene)
|
carousel.add_child(scene)
|
||||||
|
|
||||||
func create_item() -> Node:
|
func create_item() -> Node:
|
||||||
|
|
|
@ -6,7 +6,7 @@ class_name ItemUI extends Control
|
||||||
var _default_text: String
|
var _default_text: String
|
||||||
var _default_icon: Texture2D
|
var _default_icon: Texture2D
|
||||||
|
|
||||||
func _init() -> void:
|
func _ready() -> void:
|
||||||
_default_text = name_label.text
|
_default_text = name_label.text
|
||||||
_default_icon = icon_texture.texture
|
_default_icon = icon_texture.texture
|
||||||
|
|
||||||
|
@ -19,6 +19,5 @@ func bind(_item: Option):
|
||||||
icon_texture.texture = item.icon
|
icon_texture.texture = item.icon
|
||||||
|
|
||||||
func unbind():
|
func unbind():
|
||||||
print(_default_text)
|
|
||||||
name_label.text = _default_text
|
name_label.text = _default_text
|
||||||
icon_texture.texture = _default_icon
|
icon_texture.texture = _default_icon
|
||||||
|
|
|
@ -20,4 +20,4 @@ func close():
|
||||||
|
|
||||||
func _gui_input(event: InputEvent) -> void:
|
func _gui_input(event: InputEvent) -> void:
|
||||||
super(event)
|
super(event)
|
||||||
Utils.propagate_input_event(self, "_gui_input", event, false)
|
KCUtils.propagate_input_event(self, "_gui_input", event, false)
|
||||||
|
|
Loading…
Add table
Reference in a new issue