Implement item unlocking mechanism and refactor save functionality; update scene timer node
This commit is contained in:
+47
-23
@@ -73,6 +73,7 @@ var g_active_items: Dictionary = {}
|
|||||||
|
|
||||||
var owniverse:Owniverse = Owniverse.new()
|
var owniverse:Owniverse = Owniverse.new()
|
||||||
var owniverse_items: Dictionary[String, OwniverseItem] = {}
|
var owniverse_items: Dictionary[String, OwniverseItem] = {}
|
||||||
|
var locked_items: Array = []
|
||||||
|
|
||||||
var item_list_to_update: Dictionary = {}
|
var item_list_to_update: Dictionary = {}
|
||||||
|
|
||||||
@@ -98,6 +99,23 @@ func set_owniverse_item_value() -> void:
|
|||||||
|
|
||||||
#endregion
|
#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):
|
func _on_indicator_pressed(indicator_name: String, page: int = 0):
|
||||||
_set_description(indicator_name, page)
|
_set_description(indicator_name, page)
|
||||||
|
|
||||||
@@ -172,7 +190,8 @@ func item_activated(item: OwniverseItem) -> void:
|
|||||||
owniverse.produce(item.item_id, 100_000)
|
owniverse.produce(item.item_id, 100_000)
|
||||||
|
|
||||||
func _unlock_item(item_id: String):
|
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:
|
func _check_counters(delta: float) -> Array:
|
||||||
@@ -191,7 +210,7 @@ func _check_counters(delta: float) -> Array:
|
|||||||
return actions
|
return actions
|
||||||
|
|
||||||
|
|
||||||
#region Swipe
|
#region Swipe and page
|
||||||
|
|
||||||
func _do_actions(actions: Array) -> void:
|
func _do_actions(actions: Array) -> void:
|
||||||
for action: String in actions:
|
for action: String in actions:
|
||||||
@@ -226,11 +245,34 @@ func _input(event: InputEvent) -> void:
|
|||||||
g_counters.swipe.value = 0
|
g_counters.swipe.value = 0
|
||||||
elif event is InputEventScreenTouch:
|
elif event is InputEventScreenTouch:
|
||||||
pass
|
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
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
owniverse.init_enitities()
|
var _output = owniverse.init_enitities()
|
||||||
|
locked_items = _output.locked_items
|
||||||
|
print(locked_items)
|
||||||
owniverse.load_data()
|
owniverse.load_data()
|
||||||
_init_owniverse_items()
|
_init_owniverse_items()
|
||||||
|
|
||||||
@@ -256,25 +298,6 @@ func _process(delta: float) -> void:
|
|||||||
|
|
||||||
_set_active_page_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:
|
func _change_speed(delta: int) -> void:
|
||||||
|
|
||||||
@@ -308,5 +331,6 @@ func _on_topmenu_button_pressed(ButtonName) -> void:
|
|||||||
#z *= 10
|
#z *= 10
|
||||||
|
|
||||||
|
|
||||||
func _on_save_data() -> void:
|
func _on_unlock_and_save_timeout() -> void:
|
||||||
owniverse.save_data()
|
owniverse.save_data()
|
||||||
|
_unlock_items()
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ var cumulative_amount: Dictionary[String, float] = {}
|
|||||||
var current_amount: Dictionary[String, float] = {}
|
var current_amount: Dictionary[String, float] = {}
|
||||||
|
|
||||||
|
|
||||||
# ----
|
# ------------------------------------
|
||||||
|
|
||||||
var state: Dictionary = {
|
var state: Dictionary = {
|
||||||
'datetime': 0.0,
|
'datetime': 0.0,
|
||||||
@@ -26,6 +26,12 @@ var state: Dictionary = {
|
|||||||
'speed': 1,
|
'speed': 1,
|
||||||
'speed_in_year': 1,
|
'speed_in_year': 1,
|
||||||
'energy': 1E14,
|
'energy': 1E14,
|
||||||
|
'batches': {},
|
||||||
|
'amount': {},
|
||||||
|
}
|
||||||
|
|
||||||
|
var stats: Dictionary = {
|
||||||
|
'total_amount': {},
|
||||||
}
|
}
|
||||||
|
|
||||||
var speed: int:
|
var speed: int:
|
||||||
@@ -37,8 +43,16 @@ var speed: int:
|
|||||||
|
|
||||||
|
|
||||||
func evolute(delta: float) -> Owniverse:
|
func evolute(delta: float) -> Owniverse:
|
||||||
|
|
||||||
var new_owniverse := Owniverse.new()
|
var new_owniverse := Owniverse.new()
|
||||||
_add_time_delta(new_owniverse, delta)
|
_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
|
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)
|
new_owniverse.state.year = floorf(new_owniverse.state.datetime)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ----------
|
# ----------
|
||||||
|
|
||||||
func cycle(delta: float):
|
func cycle(delta: float):
|
||||||
@@ -61,15 +74,6 @@ func cycle(delta: float):
|
|||||||
|
|
||||||
# TODO review
|
# 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
|
#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]
|
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
|
#endregion
|
||||||
|
|
||||||
@@ -177,11 +172,11 @@ func _check_locked_items() -> void:
|
|||||||
|
|
||||||
|
|
||||||
func load_data() -> bool:
|
func load_data() -> bool:
|
||||||
var game_data: Dictionary = SaveManager.load_data("owniverse", "qwerty")
|
var _game_data: Dictionary = SaveManager.load_data("owniverse", "qwerty")
|
||||||
if game_data == {}:
|
if _game_data == {}:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
if !game_data.has_all(["cumulative_amount"
|
if !_game_data.has_all(["cumulative_amount"
|
||||||
, "current_amount"
|
, "current_amount"
|
||||||
#, "entity_batches"
|
#, "entity_batches"
|
||||||
#, "year",
|
#, "year",
|
||||||
@@ -189,44 +184,56 @@ func load_data() -> bool:
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
#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"]
|
#state = _game_data["state"]
|
||||||
|
#stats = _game_data["stats"]
|
||||||
|
|
||||||
print(state)
|
|
||||||
|
|
||||||
for item in current_amount:
|
for item in current_amount:
|
||||||
items_to_update[item] = current_amount[item]
|
items_to_update[item] = current_amount[item]
|
||||||
print("loaded")
|
#print("loaded: ", _game_data)
|
||||||
|
#print("state: ", state)
|
||||||
|
#print("stats: ", stats)
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
||||||
func save_data() -> void:
|
func save_data() -> void:
|
||||||
var game_data: Dictionary = {}
|
var _game_data: Dictionary = {}
|
||||||
game_data["cumulative_amount"] = cumulative_amount
|
_game_data["cumulative_amount"] = cumulative_amount
|
||||||
game_data["current_amount"] = current_amount
|
_game_data["current_amount"] = current_amount
|
||||||
game_data["state"] = state
|
_game_data["state"] = state
|
||||||
|
_game_data["stats"] = stats
|
||||||
|
|
||||||
#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: ", game_data)
|
print("saved")
|
||||||
|
#, _game_data)
|
||||||
|
|
||||||
|
|
||||||
func init_enitities() -> void:
|
func init_enitities() -> Dictionary:
|
||||||
|
|
||||||
|
var _result := {
|
||||||
|
'locked_items' : [],
|
||||||
|
}
|
||||||
var _auto_production := []
|
var _auto_production := []
|
||||||
for _entity_id in Global.OwniverseEntities:
|
for _entity_id in Global.OwniverseEntities:
|
||||||
var _entity = OwniverseEntity.new(Global.OwniverseEntities[_entity_id])
|
var _entity = OwniverseEntity.new(Global.OwniverseEntities[_entity_id])
|
||||||
entities[_entity_id] = _entity
|
entities[_entity_id] = _entity
|
||||||
|
|
||||||
current_amount[_entity_id] = 0
|
current_amount[_entity_id] = 0
|
||||||
|
state.amount[_entity_id] = 0
|
||||||
cumulative_amount[_entity_id] = 0
|
cumulative_amount[_entity_id] = 0
|
||||||
|
stats.total_amount[_entity_id] = 0
|
||||||
if _entity.group_as != "":
|
if _entity.group_as != "":
|
||||||
current_amount[_entity.group_as] = 0
|
current_amount[_entity.group_as] = 0
|
||||||
|
state.amount[_entity.group_as] = 0
|
||||||
|
|
||||||
cumulative_amount[_entity.group_as] = 0
|
cumulative_amount[_entity.group_as] = 0
|
||||||
|
stats.total_amount[_entity.group_as] = 0
|
||||||
|
|
||||||
if _entity.unlock != {}:
|
if _entity.unlock != {}:
|
||||||
locked_entities.append(_entity)
|
locked_entities.append(_entity)
|
||||||
|
_result.locked_items.append(_entity.id)
|
||||||
|
|
||||||
#state.init_entity(_entity)
|
#state.init_entity(_entity)
|
||||||
|
|
||||||
@@ -246,5 +253,6 @@ func init_enitities() -> void:
|
|||||||
entity_event_groups[_entity.event_group].append(_entity_id)
|
entity_event_groups[_entity.event_group].append(_entity_id)
|
||||||
|
|
||||||
#evolution.init_batches(_auto_production)
|
#evolution.init_batches(_auto_production)
|
||||||
|
return _result
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
+3
-3
@@ -872,8 +872,8 @@ layout_mode = 2
|
|||||||
wait_time = 0.2
|
wait_time = 0.2
|
||||||
autostart = true
|
autostart = true
|
||||||
|
|
||||||
[node name="SaveData" type="Timer" parent="Stage" unique_id=1208861837]
|
[node name="Unlock&Save" type="Timer" parent="Stage" unique_id=1208861837]
|
||||||
wait_time = 5.0
|
wait_time = 2.0
|
||||||
autostart = true
|
autostart = true
|
||||||
|
|
||||||
[connection signal="timeout" from="Background/Timer" to="Background" method="randomize_parallax"]
|
[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/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="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/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"]
|
||||||
|
|||||||
Reference in New Issue
Block a user