Refactor item management and unlock logic; remove unused item update list and signal
This commit is contained in:
+7
-20
@@ -75,7 +75,6 @@ var owniverse:Owniverse = Owniverse.new()
|
||||
var owniverse_items: Dictionary[String, OwniverseItem] = {}
|
||||
var locked_items: Array = []
|
||||
|
||||
var item_list_to_update: Dictionary = {}
|
||||
|
||||
func set_datetime(value: float):
|
||||
date_time.text = str(snapped(value, 0.1))
|
||||
@@ -83,24 +82,16 @@ func set_datetime(value: float):
|
||||
#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:
|
||||
for item_id in owniverse.items_to_update:
|
||||
if owniverse_items.has(item_id):
|
||||
owniverse_items[item_id].set_label(owniverse.items_to_update[item_id])
|
||||
owniverse.items_to_update = {}
|
||||
for _item_id in owniverse_items:
|
||||
owniverse_items[_item_id].set_label(owniverse.state.amount[_item_id])
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
func _unlock_items():
|
||||
if locked_items.size() == 0: return
|
||||
var _new_locked_items = []
|
||||
for _item_id in locked_items:
|
||||
#print(_item_id ' | ', _entity.unlock)
|
||||
@@ -114,6 +105,7 @@ func _unlock_items():
|
||||
owniverse_items[_item_id].set_visible(true)
|
||||
else:
|
||||
_new_locked_items.append(_item_id)
|
||||
locked_items = _new_locked_items
|
||||
|
||||
|
||||
func _on_indicator_pressed(indicator_name: String, page: int = 0):
|
||||
@@ -187,11 +179,7 @@ func item_activated(item: OwniverseItem) -> void:
|
||||
_set_item_description(item)
|
||||
|
||||
if item.item_id == "S" or item.item_id == "H":
|
||||
owniverse.produce(item.item_id, 100_000)
|
||||
|
||||
func _unlock_item(item_id: String):
|
||||
pass
|
||||
#owniverse_items[item_id].set_visible(true)
|
||||
var _value = owniverse.produce_hs(item.item_id, 100_000)
|
||||
|
||||
|
||||
func _check_counters(delta: float) -> Array:
|
||||
@@ -272,11 +260,9 @@ func _page_action_pressed(page_id: int, action_amount: float) -> void:
|
||||
func _ready() -> void:
|
||||
var _output = owniverse.init_enitities()
|
||||
locked_items = _output.locked_items
|
||||
print(locked_items)
|
||||
owniverse.load_data()
|
||||
_init_owniverse_items()
|
||||
|
||||
owniverse.unlock_item.connect(_unlock_item)
|
||||
g_counters.swipe.sec = 0.2
|
||||
|
||||
for pa in page_actions:
|
||||
@@ -289,7 +275,7 @@ func _process(delta: float) -> void:
|
||||
owniverse = owniverse.evolute(delta)
|
||||
set_datetime(owniverse.state.year)
|
||||
|
||||
owniverse.cycle(delta)
|
||||
#owniverse.cycle(delta)
|
||||
|
||||
#owniverse.cycle_legacy(year_delta)
|
||||
|
||||
@@ -333,4 +319,5 @@ func _on_topmenu_button_pressed(ButtonName) -> void:
|
||||
|
||||
func _on_unlock_and_save_timeout() -> void:
|
||||
owniverse.save_data()
|
||||
|
||||
_unlock_items()
|
||||
|
||||
@@ -3,8 +3,6 @@ class_name Owniverse
|
||||
|
||||
#var state: State = State.new()
|
||||
|
||||
signal unlock_item(item_id: String)
|
||||
|
||||
var entities: Dictionary[String, OwniverseEntity] = {}
|
||||
var entity_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)
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -105,6 +106,15 @@ func _get_distribution(source: Dictionary) -> Dictionary:
|
||||
|
||||
#region Production
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----
|
||||
|
||||
|
||||
|
||||
func produce(item_id: String, amount: float) -> void:
|
||||
var _entity: OwniverseEntity = entities[item_id]
|
||||
|
||||
@@ -123,6 +133,9 @@ func produce(item_id: String, amount: float) -> void:
|
||||
#state.add(_entity, current_year, amount)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func automated_production(_delta: float) -> void:
|
||||
for entity_id in auto_production:
|
||||
var _entity = entities[entity_id]
|
||||
@@ -186,8 +199,9 @@ func load_data() -> bool:
|
||||
#entity_batches = game_data["entity_batches"]
|
||||
cumulative_amount = _game_data["cumulative_amount"]
|
||||
current_amount = _game_data["current_amount"]
|
||||
#state = _game_data["state"]
|
||||
#stats = _game_data["stats"]
|
||||
#print("loaded ", _game_data)
|
||||
state = _game_data["state"]
|
||||
stats = _game_data["stats"]
|
||||
|
||||
for item in current_amount:
|
||||
items_to_update[item] = current_amount[item]
|
||||
@@ -206,8 +220,7 @@ func save_data() -> void:
|
||||
|
||||
#game_data["entity_batches"] = entity_batches
|
||||
SaveManager.save_data("owniverse", "qwerty", _game_data)
|
||||
print("saved")
|
||||
#, _game_data)
|
||||
#print("saved ", _game_data)
|
||||
|
||||
|
||||
func init_enitities() -> Dictionary:
|
||||
|
||||
Reference in New Issue
Block a user