Refactor item management and unlock logic; remove unused item update list and signal

This commit is contained in:
Kirill
2026-08-28 00:07:18 +03:00
parent 57cc023558
commit e531e7d9b6
2 changed files with 36 additions and 36 deletions
+7 -20
View File
@@ -75,7 +75,6 @@ var owniverse:Owniverse = Owniverse.new()
var owniverse_items: Dictionary[String, OwniverseItem] = {} var owniverse_items: Dictionary[String, OwniverseItem] = {}
var locked_items: Array = [] var locked_items: Array = []
var item_list_to_update: Dictionary = {}
func set_datetime(value: float): func set_datetime(value: float):
date_time.text = str(snapped(value, 0.1)) date_time.text = str(snapped(value, 0.1))
@@ -83,24 +82,16 @@ func set_datetime(value: float):
#region Item manipulations: update and visibility #region Item manipulations: update and visibility
func add_to_update_list(item_id: String, amount: int) -> void:
if item_list_to_update.has(item_id):
item_list_to_update[item_id] += amount
else:
item_list_to_update[item_id] = amount
func set_owniverse_item_value() -> void: func set_owniverse_item_value() -> void:
for item_id in owniverse.items_to_update: for _item_id in owniverse_items:
if owniverse_items.has(item_id): owniverse_items[_item_id].set_label(owniverse.state.amount[_item_id])
owniverse_items[item_id].set_label(owniverse.items_to_update[item_id])
owniverse.items_to_update = {}
#endregion #endregion
func _unlock_items(): func _unlock_items():
if locked_items.size() == 0: return
var _new_locked_items = [] var _new_locked_items = []
for _item_id in locked_items: for _item_id in locked_items:
#print(_item_id ' | ', _entity.unlock) #print(_item_id ' | ', _entity.unlock)
@@ -114,6 +105,7 @@ func _unlock_items():
owniverse_items[_item_id].set_visible(true) owniverse_items[_item_id].set_visible(true)
else: else:
_new_locked_items.append(_item_id) _new_locked_items.append(_item_id)
locked_items = _new_locked_items
func _on_indicator_pressed(indicator_name: String, page: int = 0): func _on_indicator_pressed(indicator_name: String, page: int = 0):
@@ -187,11 +179,7 @@ func item_activated(item: OwniverseItem) -> void:
_set_item_description(item) _set_item_description(item)
if item.item_id == "S" or item.item_id == "H": if item.item_id == "S" or item.item_id == "H":
owniverse.produce(item.item_id, 100_000) var _value = owniverse.produce_hs(item.item_id, 100_000)
func _unlock_item(item_id: String):
pass
#owniverse_items[item_id].set_visible(true)
func _check_counters(delta: float) -> Array: func _check_counters(delta: float) -> Array:
@@ -272,11 +260,9 @@ func _page_action_pressed(page_id: int, action_amount: float) -> void:
func _ready() -> void: func _ready() -> void:
var _output = owniverse.init_enitities() var _output = owniverse.init_enitities()
locked_items = _output.locked_items locked_items = _output.locked_items
print(locked_items)
owniverse.load_data() owniverse.load_data()
_init_owniverse_items() _init_owniverse_items()
owniverse.unlock_item.connect(_unlock_item)
g_counters.swipe.sec = 0.2 g_counters.swipe.sec = 0.2
for pa in page_actions: for pa in page_actions:
@@ -289,7 +275,7 @@ func _process(delta: float) -> void:
owniverse = owniverse.evolute(delta) owniverse = owniverse.evolute(delta)
set_datetime(owniverse.state.year) set_datetime(owniverse.state.year)
owniverse.cycle(delta) #owniverse.cycle(delta)
#owniverse.cycle_legacy(year_delta) #owniverse.cycle_legacy(year_delta)
@@ -333,4 +319,5 @@ func _on_topmenu_button_pressed(ButtonName) -> void:
func _on_unlock_and_save_timeout() -> void: func _on_unlock_and_save_timeout() -> void:
owniverse.save_data() owniverse.save_data()
_unlock_items() _unlock_items()
+27 -14
View File
@@ -3,8 +3,6 @@ class_name Owniverse
#var state: State = State.new() #var state: State = State.new()
signal unlock_item(item_id: String)
var entities: Dictionary[String, OwniverseEntity] = {} var entities: Dictionary[String, OwniverseEntity] = {}
var entity_groups: Dictionary[String, Array] = {} var entity_groups: Dictionary[String, Array] = {}
var entity_event_groups: Dictionary[String, Array] = {} var entity_event_groups: Dictionary[String, Array] = {}
@@ -65,16 +63,19 @@ func _add_time_delta(new_owniverse: Owniverse, delta: float):
new_owniverse.state.year = floorf(new_owniverse.state.datetime) new_owniverse.state.year = floorf(new_owniverse.state.datetime)
func produce_hs(entity_id: String, value: float) -> float:
var _to_produce: float = floorf(value)
_to_produce = min(_to_produce, state.energy)
state.energy -= _to_produce
state.amount[entity_id] += _to_produce
stats.total_amount[entity_id] += _to_produce
return _to_produce
# ---------- # ----------
func cycle(delta: float):
var new_state:State = State.new()
#new_state.evolute(state, delta, current_speed_in_years)
# TODO review
#region auto production and evolution #region auto production and evolution
@@ -105,6 +106,15 @@ func _get_distribution(source: Dictionary) -> Dictionary:
#region Production #region Production
#-----
func produce(item_id: String, amount: float) -> void: func produce(item_id: String, amount: float) -> void:
var _entity: OwniverseEntity = entities[item_id] var _entity: OwniverseEntity = entities[item_id]
@@ -123,6 +133,9 @@ func produce(item_id: String, amount: float) -> void:
#state.add(_entity, current_year, amount) #state.add(_entity, current_year, amount)
func automated_production(_delta: float) -> void: func automated_production(_delta: float) -> void:
for entity_id in auto_production: for entity_id in auto_production:
var _entity = entities[entity_id] var _entity = entities[entity_id]
@@ -186,8 +199,9 @@ func load_data() -> bool:
#entity_batches = game_data["entity_batches"] #entity_batches = game_data["entity_batches"]
cumulative_amount = _game_data["cumulative_amount"] cumulative_amount = _game_data["cumulative_amount"]
current_amount = _game_data["current_amount"] current_amount = _game_data["current_amount"]
#state = _game_data["state"] #print("loaded ", _game_data)
#stats = _game_data["stats"] state = _game_data["state"]
stats = _game_data["stats"]
for item in current_amount: for item in current_amount:
items_to_update[item] = current_amount[item] items_to_update[item] = current_amount[item]
@@ -206,8 +220,7 @@ func save_data() -> void:
#game_data["entity_batches"] = entity_batches #game_data["entity_batches"] = entity_batches
SaveManager.save_data("owniverse", "qwerty", _game_data) SaveManager.save_data("owniverse", "qwerty", _game_data)
print("saved") #print("saved ", _game_data)
#, _game_data)
func init_enitities() -> Dictionary: func init_enitities() -> Dictionary: