Refactor Owniverse modules for quantity mathematics and entity catalog

- Introduced `quantity_math.gd` for arithmetic operations including allocation, normalization, and accumulation of quantities without scene tree dependencies.
- Created `entity_catalog.gd` to manage entity definitions, groups, and event indexes, ensuring separation from simulation state and UI.
- Implemented `item_presentation.gd` for read-only projections of simulation state, handling amounts and unlock conditions for UI elements.
- Updated `civilization_evolution.gd` and `civilization_state.gd` to utilize new quantity math functions, improving code clarity and maintainability.
- Enhanced tests in `test_quantity_catalog.gd` to validate new functionality and ensure correctness of mathematical operations.
- Revised documentation to reflect changes in module structure and functionality.
This commit is contained in:
Kirill
2026-09-29 19:55:20 +03:00
parent c2313e9163
commit da03ba11c0
19 changed files with 424 additions and 207 deletions
+9 -38
View File
@@ -116,25 +116,11 @@ func set_owniverse_item_value() -> void:
func _unlock_items():
if locked_items.size() == 0: return
var _new_locked_items = []
var display_totals: Dictionary = owniverse.get_item_amounts(true)
for _item_id in locked_items:
#print(_item_id ' | ', _entity.unlock)
var _flag_to_unlock = true
for _elem in owniverse.entities[_item_id].unlock:
if maxf(owniverse.state.stats.total_amount.get(_elem, 0.0), display_totals.get(_elem, 0.0)) < owniverse.entities[_item_id].unlock[_elem]:
_flag_to_unlock = false
break
if _flag_to_unlock:
for item_id in [_item_id, owniverse.entities[_item_id].count_as]:
if owniverse_items.has(item_id):
owniverse_items[item_id].set_visible(true)
else:
_new_locked_items.append(_item_id)
locked_items = _new_locked_items
var result: Dictionary = owniverse.presentation.unlocks(owniverse.state, owniverse.catalog, locked_items)
for item_id in result.visible:
if owniverse_items.has(item_id):
owniverse_items[item_id].set_visible(true)
locked_items = result.remaining
func _on_indicator_pressed(indicator_name: String, page: int = 0):
_set_description(indicator_name, page)
@@ -228,7 +214,7 @@ func item_activated(item: OwniverseItem) -> void:
if item.item_id == "S" or item.item_id == "H":
var _value = owniverse.state.amount[item.item_id]
_value = 10 * _value if _value > 0 else 1
_value = 9 * _value if _value > 0 else 1
owniverse.produce_hs(item.item_id, _value)
@@ -504,9 +490,9 @@ func init_enitities() -> Dictionary:
var _result := {
'locked_items': [],
}
for entity_id in Global.OwniverseEntities:
var entity = OwniverseEntity.new(Global.OwniverseEntities[entity_id])
owniverse.entities[entity_id] = entity
owniverse.catalog.load_definitions(Global.OwniverseEntities)
for entity_id in owniverse.entities:
var entity: OwniverseEntity = owniverse.entities[entity_id]
owniverse.state.stats.total_amount[entity_id] = 0
owniverse.state.amount[entity_id] = 0
@@ -519,22 +505,7 @@ func init_enitities() -> Dictionary:
owniverse.state.stats.total_amount[entity.group_as] = 0
if entity.unlock != {}:
owniverse.locked_entities.append(entity)
_result.locked_items.append(entity.id)
if entity.product_per_year_type != "":
owniverse.auto_production.append(entity)
# groups
if entity.group_as != "":
if !owniverse.entity_groups.has(entity.group_as):
owniverse.entity_groups[entity.group_as] = []
owniverse.entity_groups[entity.group_as].append(entity_id)
if entity.event_group != "":
if !owniverse.entity_event_groups.has(entity.event_group):
owniverse.entity_event_groups[entity.event_group] = []
owniverse.entity_event_groups[entity.event_group].append(entity_id)
return _result