Implement item unlocking mechanism and refactor save functionality; update scene timer node

This commit is contained in:
Kirill
2026-08-27 23:04:56 +03:00
parent 23929e3651
commit 57cc023558
3 changed files with 96 additions and 64 deletions
+45 -37
View File
@@ -18,7 +18,7 @@ var cumulative_amount: Dictionary[String, float] = {}
var current_amount: Dictionary[String, float] = {}
# ----
# ------------------------------------
var state: Dictionary = {
'datetime': 0.0,
@@ -26,6 +26,12 @@ var state: Dictionary = {
'speed': 1,
'speed_in_year': 1,
'energy': 1E14,
'batches': {},
'amount': {},
}
var stats: Dictionary = {
'total_amount': {},
}
var speed: int:
@@ -37,8 +43,16 @@ var speed: int:
func evolute(delta: float) -> Owniverse:
var new_owniverse := Owniverse.new()
_add_time_delta(new_owniverse, delta)
# produce and evolute
new_owniverse.state = state
new_owniverse.stats = stats
new_owniverse.entities = entities
#.locked_entities = locked_entities
return new_owniverse
@@ -51,7 +65,6 @@ func _add_time_delta(new_owniverse: Owniverse, delta: float):
new_owniverse.state.year = floorf(new_owniverse.state.datetime)
# ----------
func cycle(delta: float):
@@ -61,15 +74,6 @@ func cycle(delta: float):
# TODO review
func cycle_legacy(year_delta: float) -> void:
# all owniverse activity should be called here
_produce_automatically(year_delta)
_check_locked_items()
#state.update_distribution(current_amount)
#region auto production and evolution
@@ -155,15 +159,6 @@ func _count_amount(entity_id: String, amount: float) -> void:
items_to_update[entity_id] = current_amount[entity_id]
func _check_locked_items() -> void:
for entity: OwniverseEntity in locked_entities:
for elem in entity.unlock:
if cumulative_amount[elem] < entity.unlock[elem]:
continue
#print(entity.id, " ", elem, ":", entity.unlock[elem])
unlock_item.emit(entity.id)
locked_entities.erase(entity)
return # SIC!
#endregion
@@ -177,11 +172,11 @@ func _check_locked_items() -> void:
func load_data() -> bool:
var game_data: Dictionary = SaveManager.load_data("owniverse", "qwerty")
if game_data == {}:
var _game_data: Dictionary = SaveManager.load_data("owniverse", "qwerty")
if _game_data == {}:
return false
if !game_data.has_all(["cumulative_amount"
if !_game_data.has_all(["cumulative_amount"
, "current_amount"
#, "entity_batches"
#, "year",
@@ -189,44 +184,56 @@ func load_data() -> bool:
return false
#entity_batches = game_data["entity_batches"]
cumulative_amount = game_data["cumulative_amount"]
current_amount = game_data["current_amount"]
state = game_data["state"]
print(state)
cumulative_amount = _game_data["cumulative_amount"]
current_amount = _game_data["current_amount"]
#state = _game_data["state"]
#stats = _game_data["stats"]
for item in current_amount:
items_to_update[item] = current_amount[item]
print("loaded")
#print("loaded: ", _game_data)
#print("state: ", state)
#print("stats: ", stats)
return true
func save_data() -> void:
var game_data: Dictionary = {}
game_data["cumulative_amount"] = cumulative_amount
game_data["current_amount"] = current_amount
game_data["state"] = state
var _game_data: Dictionary = {}
_game_data["cumulative_amount"] = cumulative_amount
_game_data["current_amount"] = current_amount
_game_data["state"] = state
_game_data["stats"] = stats
#game_data["entity_batches"] = entity_batches
SaveManager.save_data("owniverse", "qwerty", game_data)
print("saved: ", game_data)
SaveManager.save_data("owniverse", "qwerty", _game_data)
print("saved")
#, _game_data)
func init_enitities() -> void:
func init_enitities() -> Dictionary:
var _result := {
'locked_items' : [],
}
var _auto_production := []
for _entity_id in Global.OwniverseEntities:
var _entity = OwniverseEntity.new(Global.OwniverseEntities[_entity_id])
entities[_entity_id] = _entity
current_amount[_entity_id] = 0
state.amount[_entity_id] = 0
cumulative_amount[_entity_id] = 0
stats.total_amount[_entity_id] = 0
if _entity.group_as != "":
current_amount[_entity.group_as] = 0
state.amount[_entity.group_as] = 0
cumulative_amount[_entity.group_as] = 0
stats.total_amount[_entity.group_as] = 0
if _entity.unlock != {}:
locked_entities.append(_entity)
_result.locked_items.append(_entity.id)
#state.init_entity(_entity)
@@ -246,5 +253,6 @@ func init_enitities() -> void:
entity_event_groups[_entity.event_group].append(_entity_id)
#evolution.init_batches(_auto_production)
return _result
#endregion
+3 -3
View File
@@ -872,8 +872,8 @@ layout_mode = 2
wait_time = 0.2
autostart = true
[node name="SaveData" type="Timer" parent="Stage" unique_id=1208861837]
wait_time = 5.0
[node name="Unlock&Save" type="Timer" parent="Stage" unique_id=1208861837]
wait_time = 2.0
autostart = true
[connection signal="timeout" from="Background/Timer" to="Background" method="randomize_parallax"]
@@ -890,4 +890,4 @@ autostart = true
[connection signal="pressed" from="Stage/StageRows/PageScroller/HBoxContainer/LifePage/LifeHeader/AggressionIndicator" to="Stage" method="_on_indicator_pressed" binds= ["Aggression", 4]]
[connection signal="pressed" from="Stage/StageRows/PageScroller/HBoxContainer/LifePage/LifeHeader/TrendIndicator" to="Stage" method="_on_indicator_pressed" binds= ["Trends", 4]]
[connection signal="timeout" from="Stage/ItemAmountUpdate" to="Stage" method="set_owniverse_item_value"]
[connection signal="timeout" from="Stage/SaveData" to="Stage" method="_on_save_data"]
[connection signal="timeout" from="Stage/Unlock&Save" to="Stage" method="_on_unlock_and_save_timeout"]