refactor: route core definitions through content catalog
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
class_name ItemDefinition
|
||||
extends Resource
|
||||
|
||||
const CATEGORY_RESOURCE := &"resource"
|
||||
const CATEGORY_RESOURCE := SimulationIds.ITEM_CATEGORY_RESOURCE
|
||||
const CATEGORY_WEAPON := SimulationIds.ITEM_CATEGORY_WEAPON
|
||||
const VALID_CATEGORIES := [CATEGORY_RESOURCE, CATEGORY_WEAPON]
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ static var _profession_list: Array[ProfessionDefinition] = []
|
||||
static var _action_map: Dictionary = {}
|
||||
static var _profession_map: Dictionary = {}
|
||||
static var _profession_id_list: Array[StringName] = []
|
||||
static var _catalog_errors: Array[String] = []
|
||||
static var _cache_valid := false
|
||||
|
||||
|
||||
@@ -41,19 +42,19 @@ static func _ensure_cache() -> void:
|
||||
_action_map = {}
|
||||
_profession_map = {}
|
||||
_profession_id_list = []
|
||||
|
||||
for path in ACTION_PATHS:
|
||||
var definition := load(path) as ActionDefinition
|
||||
if definition != null:
|
||||
_action_list.append(definition)
|
||||
_action_map[definition.action_id] = definition
|
||||
|
||||
for path in PROFESSION_PATHS:
|
||||
var definition := load(path) as ProfessionDefinition
|
||||
if definition != null:
|
||||
_profession_list.append(definition)
|
||||
_profession_map[definition.profession_id] = definition
|
||||
_profession_id_list.append(definition.profession_id)
|
||||
_catalog_errors = []
|
||||
var catalog := ContentCatalog.create_core()
|
||||
if not catalog.is_valid():
|
||||
_catalog_errors = catalog.get_errors()
|
||||
_cache_valid = true
|
||||
return
|
||||
_action_list = catalog.get_actions()
|
||||
_profession_list = catalog.get_professions()
|
||||
for definition in _action_list:
|
||||
_action_map[definition.action_id] = definition
|
||||
for definition in _profession_list:
|
||||
_profession_map[definition.profession_id] = definition
|
||||
_profession_id_list.append(definition.profession_id)
|
||||
|
||||
_cache_valid = true
|
||||
|
||||
@@ -89,7 +90,7 @@ static func get_profession_ids() -> Array[StringName]:
|
||||
|
||||
static func validate() -> Array[String]:
|
||||
_ensure_cache()
|
||||
var errors: Array[String] = []
|
||||
var errors: Array[String] = _catalog_errors.duplicate()
|
||||
if _action_list.size() != ACTION_PATHS.size():
|
||||
errors.append("One or more ActionDefinition resources failed to load")
|
||||
if _profession_list.size() != PROFESSION_PATHS.size():
|
||||
|
||||
@@ -9,28 +9,10 @@ static func _ensure_cache() -> void:
|
||||
if _cache_valid:
|
||||
return
|
||||
_enemies = {}
|
||||
var raider := EnemyDefinition.new()
|
||||
raider.enemy_id = &"enemy_raider"
|
||||
raider.display_name = "Raider"
|
||||
raider.kind = SimulationIds.COMBATANT_KIND_RAIDER
|
||||
raider.weapon_id = SimulationIds.ITEM_SWORD
|
||||
raider.health = 60.0
|
||||
raider.move_speed = 3.5
|
||||
raider.body_color = Color(0.4, 0.13, 0.1, 1.0)
|
||||
raider.accent_color = Color(0.55, 0.55, 0.58, 1.0)
|
||||
_enemies[raider.enemy_id] = raider
|
||||
|
||||
var wolf := EnemyDefinition.new()
|
||||
wolf.enemy_id = &"enemy_wolf"
|
||||
wolf.display_name = "Wolf"
|
||||
wolf.kind = SimulationIds.COMBATANT_KIND_WOLF
|
||||
wolf.weapon_id = SimulationIds.ITEM_CLAW
|
||||
wolf.health = 40.0
|
||||
wolf.move_speed = 4.2
|
||||
wolf.body_color = Color(0.32, 0.32, 0.34, 1.0)
|
||||
wolf.accent_color = Color(0.95, 0.5, 0.12, 1.0)
|
||||
wolf.visual_scale = Vector3(0.8, 0.8, 0.8)
|
||||
_enemies[wolf.enemy_id] = wolf
|
||||
var catalog := ContentCatalog.create_core()
|
||||
if catalog.is_valid():
|
||||
for enemy in catalog.get_enemies():
|
||||
_enemies[enemy.enemy_id] = enemy
|
||||
_cache_valid = true
|
||||
|
||||
|
||||
@@ -48,4 +30,8 @@ static func get_all() -> Array[EnemyDefinition]:
|
||||
var values: Array[EnemyDefinition] = []
|
||||
for enemy in _enemies.values():
|
||||
values.append(enemy)
|
||||
values.sort_custom(
|
||||
func(first: EnemyDefinition, second: EnemyDefinition) -> bool:
|
||||
return String(first.enemy_id) < String(second.enemy_id)
|
||||
)
|
||||
return values
|
||||
|
||||
@@ -4,6 +4,17 @@ extends RefCounted
|
||||
const PLAYER_ACTOR_ID := -1
|
||||
const PLAYER_INVENTORY_ID := &"player_inventory"
|
||||
|
||||
const WORLD_CORE := &"world_core"
|
||||
const LOCATION_JAJCE := &"settlement_jajce"
|
||||
|
||||
const ENTITY_PERSON := &"person"
|
||||
const ENTITY_PLAYER := &"player"
|
||||
const ENTITY_WORLD_TARGET := &"world_target"
|
||||
const ENTITY_LOCATION := &"location"
|
||||
const ENTITY_SETTLEMENT := &"settlement"
|
||||
const ENTITY_MOBILE_GROUP := &"mobile_group"
|
||||
const ENTITY_POLITY := &"polity"
|
||||
|
||||
const ACTION_IDLE := &"idle"
|
||||
const ACTION_DEAD := &"dead"
|
||||
const ACTION_SLEEP := &"sleep"
|
||||
@@ -74,6 +85,7 @@ const KNOWLEDGE_ACQUISITION_LEGACY := &"legacy"
|
||||
|
||||
const ITEM_SWORD := &"item_sword"
|
||||
const ITEM_CLAW := &"item_claw"
|
||||
const ITEM_CATEGORY_RESOURCE := &"resource"
|
||||
const ITEM_CATEGORY_WEAPON := &"weapon"
|
||||
const EQUIP_SLOT_HAND := &"hand"
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ extends RefCounted
|
||||
|
||||
const SCHEMA_VERSION := 1
|
||||
const ENTITY_TYPE_NPC := &"npc"
|
||||
const ENTITY_TYPE_PLAYER := &"player"
|
||||
const ENTITY_TYPE_WORLD := &"world_entity"
|
||||
const ROLE_ACTOR := &"actor"
|
||||
const ROLE_SOURCE := &"source"
|
||||
@@ -102,9 +103,12 @@ static func from_economic_event(
|
||||
if economic_event == null:
|
||||
return null
|
||||
var economic_data := economic_event.to_dictionary()
|
||||
var actor_id := int(economic_data["actor_id"])
|
||||
var actor_type := (
|
||||
ENTITY_TYPE_PLAYER if actor_id == SimulationIds.PLAYER_ACTOR_ID else ENTITY_TYPE_NPC
|
||||
)
|
||||
var participants: Dictionary = {
|
||||
ROLE_ACTOR:
|
||||
WorldEntityRef.create(ENTITY_TYPE_NPC, StringName(str(int(economic_data["actor_id"]))))
|
||||
ROLE_ACTOR: WorldEntityRef.create(actor_type, StringName(str(actor_id)))
|
||||
}
|
||||
var source_id := StringName(economic_data["source_id"])
|
||||
if not source_id.is_empty():
|
||||
|
||||
Reference in New Issue
Block a user