Add Cooler, Bag, and compact hotbar systems
This commit is contained in:
parent
8cd3e83285
commit
49e7faaf84
32 changed files with 1613 additions and 99 deletions
26
items/catalog/basic_fishing_rod.tres
Normal file
26
items/catalog/basic_fishing_rod.tres
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
[gd_resource type="Resource" script_class="ItemData" load_steps=4 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://items/item_data.gd" id="1_script"]
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_rod"]
|
||||
colors = PackedColorArray(0.302, 0.184, 0.11, 1, 0.957, 0.827, 0.369, 1, 0.439, 0.839, 0.82, 1)
|
||||
|
||||
[sub_resource type="GradientTexture2D" id="GradientTexture_rod"]
|
||||
gradient = SubResource("Gradient_rod")
|
||||
width = 128
|
||||
height = 128
|
||||
fill_from = Vector2(0.15, 0.85)
|
||||
fill_to = Vector2(0.85, 0.15)
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_script")
|
||||
item_id = &"basic_fishing_rod"
|
||||
display_name = "Basic Fishing Rod"
|
||||
description = "A dependable starter rod. Select it to cast."
|
||||
category = 0
|
||||
icon = SubResource("GradientTexture_rod")
|
||||
stackable = false
|
||||
max_stack = 1
|
||||
usable = true
|
||||
equippable = true
|
||||
hotbar_allowed = true
|
||||
8
items/catalog/item_catalog.tres
Normal file
8
items/catalog/item_catalog.tres
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[gd_resource type="Resource" script_class="ItemCatalog" load_steps=3 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://items/item_catalog.gd" id="1_script"]
|
||||
[ext_resource type="Resource" path="res://items/catalog/basic_fishing_rod.tres" id="2_rod"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_script")
|
||||
items = [ExtResource("2_rod")]
|
||||
30
items/item_catalog.gd
Normal file
30
items/item_catalog.gd
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
class_name ItemCatalog
|
||||
extends Resource
|
||||
|
||||
const ItemDataType = preload("res://items/item_data.gd")
|
||||
|
||||
@export var items: Array[ItemDataType] = []
|
||||
|
||||
|
||||
func get_item_by_id(item_id: StringName) -> ItemDataType:
|
||||
if item_id.is_empty():
|
||||
return null
|
||||
for item: ItemDataType in items:
|
||||
if item != null and item.item_id == item_id:
|
||||
return item
|
||||
return null
|
||||
|
||||
|
||||
func get_valid_items() -> Array[ItemDataType]:
|
||||
var result: Array[ItemDataType] = []
|
||||
var seen: Dictionary[StringName, bool] = {}
|
||||
for item: ItemDataType in items:
|
||||
if (
|
||||
item == null
|
||||
or not item.is_valid()
|
||||
or seen.has(item.item_id)
|
||||
):
|
||||
continue
|
||||
seen[item.item_id] = true
|
||||
result.append(item)
|
||||
return result
|
||||
1
items/item_catalog.gd.uid
Normal file
1
items/item_catalog.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://citlop0eiu8rx
|
||||
36
items/item_data.gd
Normal file
36
items/item_data.gd
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
class_name ItemData
|
||||
extends Resource
|
||||
|
||||
enum Category {
|
||||
ROD,
|
||||
TOOL,
|
||||
BAIT,
|
||||
CONSUMABLE,
|
||||
UTILITY,
|
||||
QUEST,
|
||||
COSMETIC,
|
||||
}
|
||||
|
||||
@export var item_id: StringName
|
||||
@export var display_name: String
|
||||
@export_multiline var description: String
|
||||
@export var category: Category = Category.UTILITY
|
||||
@export var icon: Texture2D
|
||||
@export var stackable: bool = false
|
||||
@export_range(1, 999, 1) var max_stack: int = 1
|
||||
@export var usable: bool = false
|
||||
@export var equippable: bool = false
|
||||
@export var hotbar_allowed: bool = false
|
||||
|
||||
|
||||
func is_valid() -> bool:
|
||||
return (
|
||||
not item_id.is_empty()
|
||||
and not display_name.strip_edges().is_empty()
|
||||
and max_stack >= 1
|
||||
and (stackable or max_stack == 1)
|
||||
)
|
||||
|
||||
|
||||
func get_category_name() -> String:
|
||||
return Category.keys()[category].capitalize()
|
||||
1
items/item_data.gd.uid
Normal file
1
items/item_data.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cah5thda5aohb
|
||||
20
items/owned_item.gd
Normal file
20
items/owned_item.gd
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
class_name OwnedItem
|
||||
extends Resource
|
||||
|
||||
@export var item_id: StringName
|
||||
@export var quantity: int = 1
|
||||
|
||||
|
||||
func is_valid() -> bool:
|
||||
return not item_id.is_empty() and quantity > 0
|
||||
|
||||
|
||||
func duplicate_record():
|
||||
return duplicate(true)
|
||||
|
||||
|
||||
func to_save_dict() -> Dictionary:
|
||||
return {
|
||||
"item_id": String(item_id),
|
||||
"quantity": quantity,
|
||||
}
|
||||
1
items/owned_item.gd.uid
Normal file
1
items/owned_item.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c7julskwitfxi
|
||||
Loading…
Add table
Add a link
Reference in a new issue