Files
aetherbound-guild/runtime/foundation/app_services.gd
T

43 lines
1.2 KiB
GDScript

class_name ABGAppServices
extends RefCounted
const ScreenStackScript = preload("res://foundation/screen_stack.gd")
## Explicit dependency bundle for new Runtime pages. Existing legacy pages may
## continue to construct their own services until they are migrated, but new
## code should receive this object instead of reaching through a root facade.
var screen_stack
var _services: Dictionary = {}
func _init(initial_services: Dictionary = {}) -> void:
screen_stack = initial_services.get("screen_stack", ScreenStackScript.new())
for key in initial_services.keys():
if key == "screen_stack":
continue
_services[StringName(key)] = initial_services[key]
func register_service(service_id: StringName, service: Variant) -> void:
if service == null:
_services.erase(service_id)
return
_services[service_id] = service
func has_service(service_id: StringName) -> bool:
return _services.has(service_id) and _services[service_id] != null
func resolve_service(service_id: StringName) -> Variant:
return _services.get(service_id, null)
func service_snapshot() -> Dictionary:
var result: Dictionary = {}
for key in _services.keys():
result[String(key)] = _services[key] != null
result["screen_stack"] = screen_stack != null
return result