Add item description and testing framework for Owniverse
- Introduced `item_description.gd` to handle item descriptions with localization support. - Implemented a testing script `test_descriptions.gd` to validate item description rendering and localization. - Added a new template file for Russian localization. - Included a large package file `owniverse.0.6.29-145.pck` for game assets. - Ensured proper memory management in tests with fixture and dispose functions.
This commit is contained in:
+24
-7
@@ -29,14 +29,30 @@ func get_localized_item_description(item_id: String, item: String) -> String:
|
||||
return ""
|
||||
|
||||
|
||||
# Russian templates include the class; legacy English keys omit it.
|
||||
func get_template(id: String, category: String, field: String) -> Dictionary:
|
||||
var rows: Dictionary = Templates.get(Locale, {})
|
||||
for key in [id + "." + category + "." + field, id + "." + field]:
|
||||
if rows.has(key):
|
||||
return rows[key]
|
||||
return {}
|
||||
|
||||
|
||||
func render_template(row: Dictionary, variables: Dictionary) -> String:
|
||||
var result: String = str(row.get("text", ""))
|
||||
for i in range(5):
|
||||
var variable: String = str(row.get("value" + str(i), "")).strip_edges()
|
||||
var value: String = str(variables.get(variable, "—")) if variable != "" else ""
|
||||
result = result.replace("%value" + str(i) + "%", value)
|
||||
return result.replace("<br>", "\n").replace("[p]", "\n")
|
||||
|
||||
|
||||
func get_description(item_id: String, items: Array = []) -> String:
|
||||
if !Templates[Locale].has(item_id):
|
||||
return ""
|
||||
var description: String = Templates[Locale][item_id]["text"]
|
||||
var value = 0
|
||||
for item in items:
|
||||
description.replace("value" + str(value), str(item))
|
||||
return description
|
||||
var row: Dictionary = Templates.get(Locale, {}).get(item_id, {})
|
||||
var variables: Dictionary = {}
|
||||
for i in mini(items.size(), 5):
|
||||
variables[str(row.get("value" + str(i), ""))] = items[i]
|
||||
return render_template(row, variables)
|
||||
|
||||
|
||||
func format_number(value: float, digits: int = 0) -> String:
|
||||
@@ -58,6 +74,7 @@ func _ready() -> void:
|
||||
Locales["ru"] = _read_from_csv("res://data/locale.ru.txt")
|
||||
|
||||
Templates["en"] = _read_from_csv("res://data/templates.en.txt")
|
||||
Templates["ru"] = _read_from_csv("res://data/templates.ru.txt")
|
||||
|
||||
|
||||
func _read_from_csv(file_path: String) -> Dictionary:
|
||||
|
||||
Reference in New Issue
Block a user