inventaire fonctionnel #13
This commit is contained in:
11
common/inventory/resources/items/default_seed.tres
Normal file
11
common/inventory/resources/items/default_seed.tres
Normal file
@@ -0,0 +1,11 @@
|
||||
[gd_resource type="Resource" script_class="SeedItem" load_steps=3 format=3 uid="uid://lrl2okkhyxmx"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://gui/player_info/assets/icons/bolt.svg" id="1_dy25s"]
|
||||
[ext_resource type="Script" uid="uid://bypjcvlc15gsm" path="res://common/inventory/scripts/items/seed_item.gd" id="2_mgcdi"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("2_mgcdi")
|
||||
plant_type = ""
|
||||
name = "Boule"
|
||||
icon = ExtResource("1_dy25s")
|
||||
metadata/_custom_type_script = "uid://bypjcvlc15gsm"
|
||||
5
common/inventory/scripts/generic_item.gd
Normal file
5
common/inventory/scripts/generic_item.gd
Normal file
@@ -0,0 +1,5 @@
|
||||
extends Resource
|
||||
class_name GenericItem
|
||||
|
||||
@export var name: String
|
||||
@export var icon: Texture2D
|
||||
1
common/inventory/scripts/generic_item.gd.uid
Normal file
1
common/inventory/scripts/generic_item.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://do1a37cqva05e
|
||||
44
common/inventory/scripts/inventory.gd
Normal file
44
common/inventory/scripts/inventory.gd
Normal file
@@ -0,0 +1,44 @@
|
||||
extends Resource
|
||||
class_name Inventory
|
||||
|
||||
signal inventory_changed(inventory: Inventory)
|
||||
|
||||
@export var items: Array[GenericItem] = []
|
||||
@export var max_items: int = 10
|
||||
|
||||
func add_item(item: GenericItem):
|
||||
if items.size() < max_items:
|
||||
items.append(item)
|
||||
emit_signal("inventory_changed", self)
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
func add_items(items_to_add: Array[GenericItem], fillup: bool = false):
|
||||
if fillup:
|
||||
var has_changed := false
|
||||
for i in min(items_to_add.size(), max_items - items.size()):
|
||||
items.append(items_to_add[i])
|
||||
has_changed = true
|
||||
if has_changed:
|
||||
emit_signal("inventory_changed", self)
|
||||
return has_changed
|
||||
elif !fillup && items.size() + items_to_add.size() < max_items:
|
||||
items.append_array(items_to_add)
|
||||
emit_signal("inventory_changed", self)
|
||||
return true
|
||||
|
||||
|
||||
func get_item(ind: int = 0):
|
||||
return items[ind]
|
||||
|
||||
func get_and_remove_item(ind: int = 0):
|
||||
var item_removed: GenericItem = items.pop_at(ind)
|
||||
emit_signal("inventory_changed", self)
|
||||
return item_removed
|
||||
|
||||
func swap_items(item_to_add: GenericItem, ind_to_get: int = 0):
|
||||
var item_to_get := items[ind_to_get]
|
||||
items[ind_to_get] = item_to_add
|
||||
emit_signal("inventory_changed", self)
|
||||
return item_to_get
|
||||
1
common/inventory/scripts/inventory.gd.uid
Normal file
1
common/inventory/scripts/inventory.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://fnu2d6wna4yc
|
||||
4
common/inventory/scripts/items/seed_item.gd
Normal file
4
common/inventory/scripts/items/seed_item.gd
Normal file
@@ -0,0 +1,4 @@
|
||||
extends GenericItem
|
||||
class_name SeedItem
|
||||
|
||||
@export var plant_type: String
|
||||
1
common/inventory/scripts/items/seed_item.gd.uid
Normal file
1
common/inventory/scripts/items/seed_item.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bypjcvlc15gsm
|
||||
Reference in New Issue
Block a user