Refactor state management; update unlock logic and enhance signal bindings in scene
This commit is contained in:
+6
-6
@@ -97,7 +97,7 @@ func _unlock_items():
|
|||||||
#print(_item_id ' | ', _entity.unlock)
|
#print(_item_id ' | ', _entity.unlock)
|
||||||
var _flag_to_unlock = true
|
var _flag_to_unlock = true
|
||||||
for _elem in owniverse.entities[_item_id].unlock:
|
for _elem in owniverse.entities[_item_id].unlock:
|
||||||
if owniverse.stats.total_amount[_elem] < owniverse.entities[_item_id].unlock[_elem]:
|
if owniverse.state.stats.total_amount[_elem] < owniverse.entities[_item_id].unlock[_elem]:
|
||||||
_flag_to_unlock = false
|
_flag_to_unlock = false
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ func _set_active_page_actions() -> void:
|
|||||||
|
|
||||||
#var amount = owniverse.get_available_to_produce(entity)
|
#var amount = owniverse.get_available_to_produce(entity)
|
||||||
var amount = owniverse.calculate_max_producible(entity)
|
var amount = owniverse.calculate_max_producible(entity)
|
||||||
print(item_id, " : ", amount)
|
#print(item_id, " : ", amount)
|
||||||
page_actions[pa].set_actions(item_id, amount)
|
page_actions[pa].set_actions(item_id, amount)
|
||||||
|
|
||||||
|
|
||||||
@@ -264,8 +264,8 @@ func _page_action_pressed(page_id: int, action_amount: float) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
var _output = owniverse.init_enitities()
|
var inited_result = owniverse.init_enitities()
|
||||||
locked_items = _output.locked_items
|
locked_items = inited_result.locked_items
|
||||||
owniverse.load_data()
|
owniverse.load_data()
|
||||||
_init_owniverse_items()
|
_init_owniverse_items()
|
||||||
|
|
||||||
@@ -278,7 +278,7 @@ func _ready() -> void:
|
|||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
|
|
||||||
owniverse = owniverse.evolute(delta)
|
owniverse.evolute(delta)
|
||||||
set_datetime(owniverse.state.year)
|
set_datetime(owniverse.state.year)
|
||||||
|
|
||||||
#owniverse.cycle(delta)
|
#owniverse.cycle(delta)
|
||||||
@@ -315,7 +315,7 @@ func _change_speed(delta: int) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _on_topmenu_button_pressed(ButtonName) -> void:
|
func _on_topmenu_button_pressed(ButtonName) -> void:
|
||||||
print(ButtonName)
|
print("Debug: ", owniverse.state)
|
||||||
#var s: float = 1E15
|
#var s: float = 1E15
|
||||||
#var z = 1.0
|
#var z = 1.0
|
||||||
#for i in range(30):
|
#for i in range(30):
|
||||||
|
|||||||
@@ -13,11 +13,12 @@ var auto_production: Array = []
|
|||||||
var locked_entities: Array = []
|
var locked_entities: Array = []
|
||||||
|
|
||||||
#var cumulative_amount: Dictionary[String, float] = {}
|
#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,
|
||||||
'year': 0.0,
|
'year': 0.0,
|
||||||
@@ -27,11 +28,13 @@ var state: Dictionary = {
|
|||||||
'batches': {},
|
'batches': {},
|
||||||
'binds': {},
|
'binds': {},
|
||||||
'amount': {},
|
'amount': {},
|
||||||
}
|
'stats': {
|
||||||
|
|
||||||
var stats: Dictionary = {
|
|
||||||
'total_amount': {},
|
'total_amount': {},
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var new_state = state.duplicate_deep()
|
||||||
|
|
||||||
|
|
||||||
var speed: int:
|
var speed: int:
|
||||||
get:
|
get:
|
||||||
@@ -41,26 +44,26 @@ var speed: int:
|
|||||||
state.speed_in_years = pow(10, state.speed - 1)
|
state.speed_in_years = pow(10, state.speed - 1)
|
||||||
|
|
||||||
|
|
||||||
func evolute(delta: float) -> Owniverse:
|
func evolute(delta: float):
|
||||||
var new_owniverse := Owniverse.new()
|
|
||||||
_add_time_delta(new_owniverse, delta)
|
_add_time_delta(delta)
|
||||||
# produce and evolute
|
# produce and evolute
|
||||||
new_owniverse.state = state
|
|
||||||
new_owniverse.stats = stats
|
#new_owniverse.state = state
|
||||||
new_owniverse.entities = entities
|
#new_owniverse.stats = stats
|
||||||
|
#new_owniverse.entities = entities
|
||||||
|
|
||||||
#.locked_entities = locked_entities
|
#.locked_entities = locked_entities
|
||||||
|
|
||||||
|
|
||||||
return new_owniverse
|
|
||||||
|
|
||||||
|
|
||||||
func _add_time_delta(new_owniverse: Owniverse, delta: float):
|
func _add_time_delta(delta: float):
|
||||||
new_owniverse.state.speed_in_year = state.speed_in_year
|
pass
|
||||||
new_owniverse.state.datetime = state.datetime \
|
#new_owniverse.state.datetime = state.datetime \
|
||||||
+ delta * new_owniverse.state.speed_in_year
|
#+ delta * new_owniverse.state.speed_in_year
|
||||||
|
#
|
||||||
new_owniverse.state.year = floorf(new_owniverse.state.datetime)
|
#new_owniverse.state.year = floorf(new_owniverse.state.datetime)
|
||||||
|
|
||||||
|
|
||||||
# ----------
|
# ----------
|
||||||
@@ -113,7 +116,7 @@ func produce_hs(entity_id: String, value: float) -> float:
|
|||||||
|
|
||||||
state.energy -= to_produce
|
state.energy -= to_produce
|
||||||
_process_enitity(entity_id, to_produce)
|
_process_enitity(entity_id, to_produce)
|
||||||
stats.total_amount[entity_id] = stats.total_amount.get(entity_id, 0.0) + to_produce
|
state.stats.total_amount[entity_id] = state.stats.total_amount.get(entity_id, 0.0) + to_produce
|
||||||
|
|
||||||
return to_produce
|
return to_produce
|
||||||
|
|
||||||
@@ -137,7 +140,7 @@ func calculate_max_producible(entity: OwniverseEntity, desired_amount: float = 1
|
|||||||
for bind_item in entity.bind:
|
for bind_item in entity.bind:
|
||||||
if entity.bind[bind_item] == 0:
|
if entity.bind[bind_item] == 0:
|
||||||
continue
|
continue
|
||||||
var available = current_amount.get(bind_item, 0.0)
|
var available = state.amount.get(bind_item, 0.0)
|
||||||
var max_from_bind = floorf(available / entity.bind[bind_item])
|
var max_from_bind = floorf(available / entity.bind[bind_item])
|
||||||
max_producible = min(max_producible, max_from_bind)
|
max_producible = min(max_producible, max_from_bind)
|
||||||
|
|
||||||
@@ -345,12 +348,12 @@ func _process_enitity(entity_id: String, amount: float) -> 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(["state"
|
||||||
, "current_amount"
|
, "stats"
|
||||||
#, "entity_batches"
|
#, "entity_batches"
|
||||||
#, "year",
|
#, "year",
|
||||||
]):
|
]):
|
||||||
@@ -358,29 +361,24 @@ 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"]
|
||||||
#print("loaded ", _game_data)
|
#print("loaded ", _game_data)
|
||||||
#state = _game_data["state"]
|
state = game_data["state"]
|
||||||
stats = _game_data["stats"]
|
#state2 = game_data["state2"]
|
||||||
|
|
||||||
for item in current_amount:
|
for item in state.amount:
|
||||||
items_to_update[item] = current_amount[item]
|
items_to_update[item] = state.amount[item]
|
||||||
#print("loaded: ", _game_data)
|
|
||||||
#print("state: ", state)
|
#print("state: ", state)
|
||||||
#print("stats: ", stats)
|
#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["state"] = state
|
||||||
_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)
|
||||||
SaveManager.save_data("owniverse", "qwerty", _game_data)
|
#print("saved ", game_data, "\n\n\n")
|
||||||
#print("saved ", _game_data)
|
|
||||||
|
|
||||||
|
|
||||||
func init_enitities() -> Dictionary:
|
func init_enitities() -> Dictionary:
|
||||||
@@ -392,17 +390,17 @@ func init_enitities() -> Dictionary:
|
|||||||
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
|
||||||
stats.total_amount[entity_id] = 0
|
state.stats.total_amount[entity_id] = 0
|
||||||
state.amount[entity_id] = 0
|
state.amount[entity_id] = 0
|
||||||
if entity.lifespan > 0:
|
if entity.lifespan > 0:
|
||||||
state.batches[entity] = []
|
state.batches[entity] = []
|
||||||
add_entity_to_batch(entity, 0, 0)
|
add_entity_to_batch(entity, 0, 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
|
state.amount[entity.group_as] = 0
|
||||||
|
|
||||||
stats.total_amount[entity.group_as] = 0
|
state.stats.total_amount[entity.group_as] = 0
|
||||||
|
|
||||||
if entity.unlock != {}:
|
if entity.unlock != {}:
|
||||||
locked_entities.append(entity)
|
locked_entities.append(entity)
|
||||||
@@ -422,6 +420,7 @@ func init_enitities() -> Dictionary:
|
|||||||
entity_event_groups[entity.event_group] = []
|
entity_event_groups[entity.event_group] = []
|
||||||
entity_event_groups[entity.event_group].append(entity_id)
|
entity_event_groups[entity.event_group].append(entity_id)
|
||||||
|
|
||||||
|
#print("ns: ", new_state)
|
||||||
return _result
|
return _result
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -877,5 +877,17 @@ 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"]
|
||||||
|
[connection signal="pressed" from="Stage/StageRows/TopMenu/BurgerButton" to="Stage" method="_on_topmenu_button_pressed" binds= ["Burger"]]
|
||||||
|
[connection signal="pressed" from="Stage/StageRows/TopMenu/TimeMinus" to="Stage" method="_change_speed" binds= [-1]]
|
||||||
|
[connection signal="pressed" from="Stage/StageRows/TopMenu/TimePlus" to="Stage" method="_change_speed" binds= [1]]
|
||||||
|
[connection signal="pressed" from="Stage/StageRows/TopMenu/ReportButton" to="Stage" method="_on_topmenu_button_pressed" binds= ["Report"]]
|
||||||
|
[connection signal="pressed" from="Stage/StageRows/PageScroller/HBoxContainer/ResourcePage/ResourceHeader/EnergyIndicator" to="Stage" method="_on_indicator_pressed" binds= ["Energy", 1]]
|
||||||
|
[connection signal="pressed" from="Stage/StageRows/PageScroller/HBoxContainer/ResourcePage/ResourceHeader/DensityIndicator" to="Stage" method="_on_indicator_pressed" binds= ["Density", 1]]
|
||||||
|
[connection signal="pressed" from="Stage/StageRows/PageScroller/HBoxContainer/StarPage/StarHeader/BurnabilityIndicator" to="Stage" method="_on_indicator_pressed" binds= ["Burnability", 2]]
|
||||||
|
[connection signal="pressed" from="Stage/StageRows/PageScroller/HBoxContainer/StarPage/StarHeader/ExplosivenessIndicator" to="Stage" method="_on_indicator_pressed" binds= ["Explosiveness", 2]]
|
||||||
|
[connection signal="pressed" from="Stage/StageRows/PageScroller/HBoxContainer/StructurePage/StructureHeader/EnergyIndicator" to="Stage" method="_on_indicator_pressed" binds= ["Energy", 3]]
|
||||||
|
[connection signal="pressed" from="Stage/StageRows/PageScroller/HBoxContainer/StructurePage/StructureHeader/DensityIndicator" to="Stage" method="_on_indicator_pressed" binds= ["Density", 3]]
|
||||||
|
[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/ItemAmountUpdate" to="Stage" method="set_owniverse_item_value"]
|
||||||
[connection signal="timeout" from="Stage/Unlock&Save" to="Stage" method="_on_unlock_and_save_timeout"]
|
[connection signal="timeout" from="Stage/Unlock&Save" to="Stage" method="_on_unlock_and_save_timeout"]
|
||||||
|
|||||||
Reference in New Issue
Block a user