Files
2026-08-12 20:51:01 +02:00

57 lines
2.0 KiB
GDScript

class_name ItemDefinition
extends Resource
const CATEGORY_RESOURCE := SimulationIds.ITEM_CATEGORY_RESOURCE
const CATEGORY_WEAPON := SimulationIds.ITEM_CATEGORY_WEAPON
const VALID_CATEGORIES := [CATEGORY_RESOURCE, CATEGORY_WEAPON]
@export var item_id: StringName
@export var display_name: String
@export var category: StringName = CATEGORY_RESOURCE
@export var capability_tag_ids: Array[StringName] = []
@export var presentation_cue_id: StringName
@export var equip_slot: StringName
@export_range(0.0, 1000.0, 0.1) var damage := 0.0
@export_range(0.0, 50.0, 0.1) var reach := 0.0
@export_range(0.0, 5.0, 0.05) var attack_cooldown := 0.0
func validate() -> Array[String]:
var errors: Array[String] = []
if item_id.is_empty():
errors.append("item_id is empty")
if display_name.is_empty():
errors.append("display_name is empty for '%s'" % item_id)
if category not in VALID_CATEGORIES:
errors.append("category '%s' is invalid for '%s'" % [category, item_id])
elif category == CATEGORY_WEAPON:
if equip_slot != SimulationIds.EQUIP_SLOT_HAND:
errors.append(
"weapon '%s' must equip in '%s'" % [item_id, SimulationIds.EQUIP_SLOT_HAND]
)
if not is_finite(damage) or damage <= 0.0:
errors.append("damage must be positive for '%s'" % item_id)
if not is_finite(reach) or reach <= 0.0:
errors.append("reach must be positive for '%s'" % item_id)
if not is_finite(attack_cooldown) or attack_cooldown <= 0.0:
errors.append("attack_cooldown must be positive for '%s'" % item_id)
elif not equip_slot.is_empty():
errors.append("resource item '%s' cannot declare equip_slot '%s'" % [item_id, equip_slot])
var seen_tags := {}
for tag_id in capability_tag_ids:
if tag_id.is_empty():
errors.append("capability tag ID is empty for '%s'" % item_id)
elif seen_tags.has(tag_id):
errors.append("duplicate capability tag '%s' for '%s'" % [tag_id, item_id])
else:
seen_tags[tag_id] = true
return errors
func is_weapon() -> bool:
return category == CATEGORY_WEAPON
func is_resource() -> bool:
return category == CATEGORY_RESOURCE