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:
+38
-11
@@ -4,6 +4,12 @@ const OWNIVERSE_ITEM = preload("uid://d3xjfxwe3w16v")
|
||||
|
||||
const SPEED_TEXTURE_NAME_TEMPLATE = "res://ui/topmenu/time&speed/time%s.png"
|
||||
|
||||
const ItemDescription = preload("res://world/owniverse/item_description.gd")
|
||||
var description_targets: Dictionary = {}
|
||||
var description_samples: Dictionary = {}
|
||||
var description_rates: Dictionary = {}
|
||||
var description_elapsed: float = 0.0
|
||||
|
||||
const PAGE_COUNT = 5
|
||||
const RESOURCE_PAGE = 1
|
||||
const PAGE_WIDTH = 1080
|
||||
@@ -123,20 +129,40 @@ func _on_indicator_pressed(indicator_name: String, page: int = 0):
|
||||
|
||||
|
||||
func _set_item_description(item: OwniverseItem) -> void:
|
||||
var description: String = "[b]" \
|
||||
+ Global.get_localized_item_description(item.item_name, "label") \
|
||||
+"[/b]" \
|
||||
+"\n" \
|
||||
+ Global.get_localized_item_description(item.item_name, "description")
|
||||
var desc_page = clamp(item.item_page, 0, 4)
|
||||
g_item_descriptions[desc_page].text = description
|
||||
var category: String = "Entity" if owniverse.entities.has(item.item_id) else "Force"
|
||||
var id: String = item.item_id if category == "Entity" else item.item_name.capitalize()
|
||||
var page: int = clampi(item.item_page, 0, 4)
|
||||
if description_targets.get(page, {}).get("id", "") != id:
|
||||
description_samples.erase(id)
|
||||
description_rates.erase(id)
|
||||
description_targets[page] = {"id": id, "category": category}
|
||||
_refresh_descriptions()
|
||||
|
||||
|
||||
func _set_description(item_name: String, page: int) -> void:
|
||||
var description = Global.get_description(item_name + ".Name")
|
||||
description += "\n"
|
||||
description += Global.get_description(item_name + ".Description")
|
||||
g_item_descriptions[page].text = description
|
||||
description_targets[page] = {"id": item_name, "category": "Indicator"}
|
||||
_refresh_descriptions()
|
||||
|
||||
|
||||
func _refresh_descriptions() -> void:
|
||||
for page in description_targets:
|
||||
var target: Dictionary = description_targets[page]
|
||||
var label: RichTextLabel = g_item_descriptions[page]
|
||||
label.bbcode_enabled = true
|
||||
label.text = ItemDescription.render(owniverse, Global, target.id, target.category, description_rates.get(target.id, 0.0))
|
||||
|
||||
|
||||
func _update_descriptions(delta: float) -> void:
|
||||
description_elapsed += delta
|
||||
if description_elapsed < 0.25:
|
||||
return
|
||||
for page in description_targets:
|
||||
var id: String = description_targets[page].id
|
||||
var total: float = ItemDescription.quantities(owniverse, id).total
|
||||
description_rates[id] = (total - description_samples[id]) / description_elapsed if description_samples.has(id) else 0.0
|
||||
description_samples[id] = total
|
||||
description_elapsed = 0.0
|
||||
_refresh_descriptions()
|
||||
|
||||
|
||||
func _control_page(item: OwniverseItem) -> void:
|
||||
@@ -299,6 +325,7 @@ func _ready() -> void:
|
||||
func _process(delta: float) -> void:
|
||||
|
||||
owniverse.evolute(delta)
|
||||
_update_descriptions(delta)
|
||||
set_owniverse_item_value()
|
||||
set_datetime(owniverse.state.time.year)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user