refactor: separate content from presentation assets

This commit is contained in:
Rijad Zuzo
2026-08-12 21:41:33 +02:00
parent 5a70aaaded
commit bf4bf73675
22 changed files with 480 additions and 70 deletions
+21 -4
View File
@@ -14,10 +14,12 @@ const CONFIGURATION_KEYS := [
var last_error := ""
var _catalog: AnimalCatalog
var _presentation_catalog: PresentationCatalog
func _init(catalog: AnimalCatalog = null) -> void:
func _init(catalog: AnimalCatalog = null, presentation_catalog: PresentationCatalog = null) -> void:
_catalog = catalog if catalog != null else AnimalCatalog.create_core()
_presentation_catalog = presentation_catalog
if _catalog == null:
last_error = "Animal catalog could not be loaded"
elif not _catalog.rebuild().is_empty():
@@ -28,6 +30,10 @@ func get_catalog() -> AnimalCatalog:
return _catalog
func get_presentation_catalog() -> PresentationCatalog:
return _presentation_catalog
func create_presentation(
animal_definition_id: StringName,
animal_id: StringName,
@@ -44,15 +50,26 @@ func create_presentation(
if not _configuration_is_valid(configuration):
return null
var definition := _catalog.get_definition(animal_definition_id)
var presentation_scene := load(definition.presentation_scene_path) as PackedScene
if _presentation_catalog == null:
return _fail("Presentation catalog must be injected before creating presentation")
if not _presentation_catalog.is_valid():
return _fail("Injected presentation catalog is invalid")
var cue := _presentation_catalog.get_definition(definition.presentation_cue_id)
if cue == null:
return _fail(
(
"Unknown presentation cue '%s' for '%s'"
% [definition.presentation_cue_id, animal_definition_id]
)
)
var node := (
presentation_scene.instantiate() as AnimalNode if presentation_scene != null else null
_presentation_catalog.instantiate_scene(definition.presentation_cue_id) as AnimalNode
)
if node == null:
return _fail(
"Presentation scene for '%s' must instantiate AnimalNode" % animal_definition_id
)
if not node.apply_animal_definition(definition):
if not node.apply_animal_definition(definition, cue.get_parameters()):
node.free()
return _fail("Presentation rejected definition '%s'" % animal_definition_id)
node.animal_id = animal_id