refactor: route core definitions through content catalog
This commit is contained in:
@@ -9,25 +9,13 @@ static func _ensure_cache() -> void:
|
||||
if _cache_valid:
|
||||
return
|
||||
_items = {}
|
||||
_add_weapon(SimulationIds.ITEM_SWORD, "Sword", 24.0, 2.4, 0.55)
|
||||
_add_weapon(SimulationIds.ITEM_CLAW, "Claw", 10.0, 1.2, 0.4)
|
||||
var catalog := ContentCatalog.create_core()
|
||||
if catalog.is_valid():
|
||||
for item in catalog.get_items():
|
||||
_items[item.item_id] = item
|
||||
_cache_valid = true
|
||||
|
||||
|
||||
static func _add_weapon(
|
||||
item_id: StringName, display_name: String, damage: float, reach: float, cooldown: float
|
||||
) -> void:
|
||||
var item := ItemDefinition.new()
|
||||
item.item_id = item_id
|
||||
item.display_name = display_name
|
||||
item.category = SimulationIds.ITEM_CATEGORY_WEAPON
|
||||
item.equip_slot = SimulationIds.EQUIP_SLOT_HAND
|
||||
item.damage = damage
|
||||
item.reach = reach
|
||||
item.attack_cooldown = cooldown
|
||||
_items[item_id] = item
|
||||
|
||||
|
||||
static func invalidate_cache() -> void:
|
||||
_cache_valid = false
|
||||
|
||||
@@ -42,6 +30,10 @@ static func get_items() -> Array[ItemDefinition]:
|
||||
var values: Array[ItemDefinition] = []
|
||||
for item in _items.values():
|
||||
values.append(item)
|
||||
values.sort_custom(
|
||||
func(first: ItemDefinition, second: ItemDefinition) -> bool:
|
||||
return String(first.item_id) < String(second.item_id)
|
||||
)
|
||||
return values
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user