Replace generic Resource usage with type-safe resources

This commit is contained in:
2026-03-21 10:28:43 +01:00
parent c55b59fcad
commit 52c23b194e
11 changed files with 85 additions and 100 deletions

View File

@@ -16,12 +16,12 @@ var _catalog_initialized: bool = false
func _ready() -> void:
_initialize_currency_catalog()
func get_known_currencies() -> Array[Resource]:
func get_known_currencies() -> Array[Currency]:
_initialize_currency_catalog_if_needed()
var result: Array[Resource] = []
var result: Array[Currency] = []
for raw_currency in _currency_by_id.values():
var currency: Resource = raw_currency as Resource
var currency: Currency = raw_currency as Currency
if currency != null:
result.append(currency)
return result
@@ -37,11 +37,11 @@ func get_known_currency_ids() -> Array[StringName]:
ids.append(currency_id)
return ids
func get_currency_id(currency: Resource) -> StringName:
func get_currency_id(currency: Currency) -> StringName:
if currency == null:
return &""
var raw_id: Variant = currency.get("id")
var raw_id: Variant = currency.id
if raw_id is StringName:
return _normalize_currency_id(raw_id)
return _normalize_currency_id(StringName(String(raw_id)))
@@ -66,7 +66,7 @@ func is_known_currency_id(currency_id: StringName) -> bool:
return false
return _currency_by_id.has(normalized_currency_id)
func get_currency_resource(currency_id: StringName) -> Resource:
func get_currency_resource(currency_id: StringName) -> Currency:
_initialize_currency_catalog_if_needed()
var normalized_currency_id: StringName = _normalize_currency_id(currency_id)
@@ -74,14 +74,14 @@ func get_currency_resource(currency_id: StringName) -> Resource:
return null
var raw_currency: Variant = _currency_by_id.get(normalized_currency_id)
if raw_currency is Resource:
if raw_currency is Currency:
return raw_currency
return null
func get_currency_name(currency_id: StringName) -> String:
var currency: Resource = get_currency_resource(currency_id)
var currency: Currency = get_currency_resource(currency_id)
if currency != null:
var display_name: String = String(currency.get("display_name")).strip_edges()
var display_name: String = String(currency.display_name).strip_edges()
if not display_name.is_empty():
return display_name
return _humanize_currency_id(currency_id)
@@ -91,7 +91,7 @@ func get_currency_icon(currency_id: StringName) -> Texture2D:
if currency == null:
return null
var raw_icon: Variant = currency.get("icon")
var raw_icon: Variant = currency.icon
if raw_icon is Texture2D:
return raw_icon
return null