From 57cc023558656eee413ce79eebd87d5f23b3b027 Mon Sep 17 00:00:00 2001 From: Kirill Date: Thu, 27 Aug 2026 23:04:56 +0300 Subject: [PATCH] Implement item unlocking mechanism and refactor save functionality; update scene timer node --- stage/stage.gd | 72 ++++++++++++++++++++----------- world/owniverse/owniverse.gd | 82 ++++++++++++++++++++---------------- world/world.tscn | 6 +-- 3 files changed, 96 insertions(+), 64 deletions(-) diff --git a/stage/stage.gd b/stage/stage.gd index 2953978..82254a8 100644 --- a/stage/stage.gd +++ b/stage/stage.gd @@ -73,6 +73,7 @@ var g_active_items: Dictionary = {} var owniverse:Owniverse = Owniverse.new() var owniverse_items: Dictionary[String, OwniverseItem] = {} +var locked_items: Array = [] var item_list_to_update: Dictionary = {} @@ -98,6 +99,23 @@ func set_owniverse_item_value() -> void: #endregion + +func _unlock_items(): + var _new_locked_items = [] + 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 owniverse.stats.total_amount[_elem] < owniverse.entities[_item_id].unlock[_elem]: + _flag_to_unlock = false + break + + if _flag_to_unlock: + owniverse_items[_item_id].set_visible(true) + else: + _new_locked_items.append(_item_id) + + func _on_indicator_pressed(indicator_name: String, page: int = 0): _set_description(indicator_name, page) @@ -160,7 +178,7 @@ func _init_owniverse_items() -> bool: item.item_activated.connect(item_activated) owniverse_items[item_id] = item - + return false @@ -172,7 +190,8 @@ func item_activated(item: OwniverseItem) -> void: owniverse.produce(item.item_id, 100_000) func _unlock_item(item_id: String): - owniverse_items[item_id].set_visible(true) + pass + #owniverse_items[item_id].set_visible(true) func _check_counters(delta: float) -> Array: @@ -191,7 +210,7 @@ func _check_counters(delta: float) -> Array: return actions -#region Swipe +#region Swipe and page func _do_actions(actions: Array) -> void: for action: String in actions: @@ -226,11 +245,34 @@ func _input(event: InputEvent) -> void: g_counters.swipe.value = 0 elif event is InputEventScreenTouch: pass + + +func _set_active_page_actions() -> void: + for pa in page_actions: + if !g_active_items.has(pa): continue + + var item_id: String = g_active_items[pa].item_id + var amount = owniverse.get_available_to_produce(item_id) + page_actions[pa].set_actions(item_id, amount) + + +func _page_action_pressed(page_id: int, action_amount: float) -> void: + if !g_active_items.has(page_id): + return + + var item_id: String = g_active_items[page_id].item_id + + if action_amount > 0: + owniverse.produce(item_id, action_amount) + + #endregion func _ready() -> void: - owniverse.init_enitities() + var _output = owniverse.init_enitities() + locked_items = _output.locked_items + print(locked_items) owniverse.load_data() _init_owniverse_items() @@ -255,25 +297,6 @@ func _process(delta: float) -> void: _do_actions(actions) _set_active_page_actions() - -func _set_active_page_actions() -> void: - for pa in page_actions: - if !g_active_items.has(pa): continue - - var item_id: String = g_active_items[pa].item_id - var amount = owniverse.get_available_to_produce(item_id) - page_actions[pa].set_actions(item_id, amount) - - - -func _page_action_pressed(page_id: int, action_amount: float) -> void: - if !g_active_items.has(page_id): - return - - var item_id: String = g_active_items[page_id].item_id - - if action_amount > 0: - owniverse.produce(item_id, action_amount) func _change_speed(delta: int) -> void: @@ -308,5 +331,6 @@ func _on_topmenu_button_pressed(ButtonName) -> void: #z *= 10 -func _on_save_data() -> void: +func _on_unlock_and_save_timeout() -> void: owniverse.save_data() + _unlock_items() diff --git a/world/owniverse/owniverse.gd b/world/owniverse/owniverse.gd index 60812a8..8cae519 100644 --- a/world/owniverse/owniverse.gd +++ b/world/owniverse/owniverse.gd @@ -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 diff --git a/world/world.tscn b/world/world.tscn index 81d6ef7..a8d1a0b 100644 --- a/world/world.tscn +++ b/world/world.tscn @@ -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"]