Refactor save/load functionality; improve error messages and add save data timer
This commit is contained in:
+65
-2
@@ -8,6 +8,8 @@ var current_speed: int = 1
|
||||
var current_speed_in_years:int = 1
|
||||
|
||||
var entities: Dictionary[String, OwniverseEntity] = {}
|
||||
var entity_groups: Dictionary[String, Array] = {}
|
||||
var entity_event_groups: Dictionary[String, Array] = {}
|
||||
|
||||
var items_to_update: Dictionary[String, float] = {}
|
||||
|
||||
@@ -28,6 +30,8 @@ func cycle(year_delta: float) -> void:
|
||||
_entity_evolution(year_delta)
|
||||
|
||||
_check_locked_items()
|
||||
|
||||
#print(_get_distribution(current_amount))
|
||||
|
||||
|
||||
#region auto production and evolution
|
||||
@@ -46,7 +50,18 @@ func _auto_production(year_delta: float) -> void:
|
||||
|
||||
func _entity_evolution(year_delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _get_distribution(source: Dictionary) -> Dictionary:
|
||||
var distribution: Dictionary = {}
|
||||
var total: float = 0
|
||||
for id in source:
|
||||
if source[id] != 0:
|
||||
total += source[id]
|
||||
distribution[id] = source[id]
|
||||
for id in distribution:
|
||||
distribution[id] /= total
|
||||
return distribution
|
||||
|
||||
#endregion
|
||||
|
||||
#region Production
|
||||
@@ -80,7 +95,6 @@ func get_available_to_produce(item_id: String) -> float:
|
||||
var amount: float = 1E50
|
||||
for elem in entity.cost:
|
||||
amount = min(floorf(current_amount[elem] / entity.cost[elem]), amount)
|
||||
#print(elem, amount)
|
||||
return amount
|
||||
|
||||
# add to all lists
|
||||
@@ -132,6 +146,38 @@ func change_speed(delta: int) -> int:
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Init save load routines
|
||||
|
||||
|
||||
func load_data() -> bool:
|
||||
var is_succesfull = false
|
||||
|
||||
var game_data: Dictionary = SaveManager.load_data("owniverse", "qwerty")
|
||||
if game_data == {}:
|
||||
return false
|
||||
|
||||
if !game_data.has_all(["cumulative_amount", "current_amount", "entity_batches"]):
|
||||
return false
|
||||
|
||||
entity_batches = game_data["entity_batches"]
|
||||
cumulative_amount = game_data["cumulative_amount"]
|
||||
current_amount = game_data["current_amount"]
|
||||
|
||||
for item in current_amount:
|
||||
items_to_update[item] = current_amount[item]
|
||||
|
||||
return true
|
||||
|
||||
|
||||
func save_data() -> void:
|
||||
var game_data: Dictionary = {}
|
||||
game_data["cumulative_amount"] = cumulative_amount
|
||||
game_data["current_amount"] = current_amount
|
||||
game_data["entity_batches"] = entity_batches
|
||||
SaveManager.save_data("owniverse", "qwerty", game_data)
|
||||
|
||||
|
||||
func init_enitities() -> void:
|
||||
for entity_id in Global.OwniverseEntities:
|
||||
var entity = OwniverseEntity.new()
|
||||
@@ -149,3 +195,20 @@ func init_enitities() -> void:
|
||||
|
||||
if entity.product_per_year_type != "":
|
||||
auto_production.append(entity)
|
||||
|
||||
# groups
|
||||
if entity.group_as != "":
|
||||
if !entity_groups.has(entity.group_as):
|
||||
entity_groups[entity.group_as] = []
|
||||
entity_groups[entity.group_as].append(entity_id)
|
||||
|
||||
if entity.event_group != "":
|
||||
if !entity_event_groups.has(entity.event_group):
|
||||
entity_event_groups[entity.event_group] = []
|
||||
entity_event_groups[entity.event_group].append(entity_id)
|
||||
|
||||
#if entity.event_group != "":
|
||||
#entity_event_groups.append(entity.id)
|
||||
print(entity_groups)
|
||||
print(entity_event_groups)
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user