17 Commits

Author SHA1 Message Date
Kirill 0162084e53 Refactor state management; update unlock logic and enhance signal bindings in scene 2026-09-01 23:53:05 +03:00
Kirill 2f4b6a98d8 Refactor production logic to use state amounts; update calculate_max_producible function to accept default desired amount 2026-09-01 21:29:07 +03:00
Kirill d90f8693c9 Update Godot core rules to version 4.7; refactor production logic and add entity batch processing 2026-08-31 23:51:07 +03:00
Kirill e870c96879 Add 'binds' key to state dictionary for enhanced state management 2026-08-30 22:31:24 +03:00
Kirill e531e7d9b6 Refactor item management and unlock logic; remove unused item update list and signal 2026-08-28 00:07:18 +03:00
Kirill 57cc023558 Implement item unlocking mechanism and refactor save functionality; update scene timer node 2026-08-27 23:04:56 +03:00
Kirill 23929e3651 Refactor owniverse state management; replace evolution class with state handling and update cycle logic 2026-08-25 00:26:31 +03:00
Kirill 829aadca2d Update version to 0.6.27 and increment version code to 143; refactor resource paths in scene files
Android / android (push) Successful in 30s
2026-08-20 22:58:24 +03:00
Kirill 30486616f8 Update version to 0.6.26 and increment version code to 142
Android / android (push) Successful in 30s
2026-08-20 22:55:01 +03:00
Kirill d9a2679af4 Replace pressed burger button image and update resource path in world.tscn 2026-08-20 22:54:42 +03:00
Kirill 4f57c37572 Update version to 0.6.25 and increment version code to 141; replace burger button image
Android / android (push) Successful in 30s
2026-08-20 22:45:22 +03:00
Kirill e4a0dd2d13 Add new spirituality trend indicator image
Android / android (push) Successful in 30s
2026-08-20 22:29:11 +03:00
Kirill 0a10cff0fa Refactor code structure for improved readability and maintainability 2026-08-20 22:28:03 +03:00
Kirill e4cf5bdad0 Add new button images for time adjustment in the top menu 2026-08-20 22:27:36 +03:00
Kirill 645751cd23 Add new button images for time adjustment in the top menu 2026-08-20 22:26:57 +03:00
Kirill b92a49821d Update version to 0.6.23 and increment version code to 139; add unique IDs to UI nodes
Android / android (push) Successful in 31s
2026-08-20 22:19:19 +03:00
Kirill 3a91528e95 Bump version to 0.6.22 and increment version code to 138
Android / android (push) Successful in 30s
2026-08-20 22:11:09 +03:00
14 changed files with 481 additions and 216 deletions
+9 -3
View File
@@ -1,13 +1,19 @@
---
name: Godot 4.4 Core Rules
name: Godot 4.7 Core Rules
priority: high
---
Ты — senior Godot 4.4 GDScript разработчик.
Ты — senior Godot 4.7 GDScript разработчик.
- Use Godot 4.7+ API.
- Do not use Godot 3.x syntax or APIs.
- Follow the existing project architecture and coding style.
- Do not introduce unnecessary abstractions.
- Do not modify unrelated files.
- Всегда используй Godot 4.4+ API.
- Пиши строго типизированный код (`var health: int = 100`, `: Array[Node]` и т.д.).
- Предпочитай Signals вместо проверки в _process.
- Используй @export, @export_range, @export_enum, @onready.
- Composition over deep inheritance.
- Менеджеры и автолоады выноси в отдельные singleton'ы.
+1
View File
@@ -0,0 +1 @@
- use spaces not tabs for indentation
+1 -1
View File
@@ -110,7 +110,7 @@ architectures/armeabi-v7a=false
architectures/arm64-v8a=true
architectures/x86=false
architectures/x86_64=false
version/code=137
version/code=143
version/name=""
package/unique_name="com.KIDGameProduction.Owniverse"
package/name="Owniverse"
+1 -5
View File
@@ -8,14 +8,10 @@
config_version=5
[animation]
compatibility/default_parent_skeleton_in_mesh_instance_3d=true
[application]
config/name="Owniverse"
config/version="0.6.21"
config/version="0.6.27"
run/main_scene="uid://bv384dpmvjv8o"
config/features=PackedStringArray("4.7", "Mobile")
boot_splash/show_image=false
+73 -50
View File
@@ -73,8 +73,8 @@ var g_active_items: Dictionary = {}
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))
@@ -82,22 +82,32 @@ 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)
var _flag_to_unlock = true
for _elem in owniverse.entities[_item_id].unlock:
if owniverse.state.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)
locked_items = _new_locked_items
func _on_indicator_pressed(indicator_name: String, page: int = 0):
_set_description(indicator_name, page)
@@ -160,7 +170,7 @@ func _init_owniverse_items() -> bool:
item.item_activated.connect(item_activated)
owniverse_items[item_id] = item
return false
@@ -169,11 +179,8 @@ 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):
owniverse_items[item_id].set_visible(true)
var _value = owniverse.produce_hs(item.item_id, 100_000)
func _check_counters(delta: float) -> Array:
var actions: Array = []
@@ -191,7 +198,7 @@ func _check_counters(delta: float) -> Array:
return actions
#region Swipe
#region Swipe and page
func _do_actions(actions: Array) -> void:
for action: String in actions:
@@ -226,41 +233,21 @@ func _input(event: InputEvent) -> void:
g_counters.swipe.value = 0
elif event is InputEventScreenTouch:
pass
#endregion
func _ready() -> void:
owniverse.init_enitities()
owniverse.load_data()
_init_owniverse_items()
owniverse.unlock_item.connect(_unlock_item)
g_counters.swipe.sec = 0.2
for pa in page_actions:
page_actions[pa].action_pressed.connect(_page_action_pressed)
page_actions[pa].page_id = pa
func _process(delta: float) -> void:
var year_delta: float = owniverse.add_time_delta(delta)
set_datetime(year_delta)
owniverse.cycle(year_delta)
var actions = _check_counters(delta)
_do_actions(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)
var entity: OwniverseEntity = owniverse.entities[item_id]
#var amount = owniverse.get_available_to_produce(item_id)
#var amount = owniverse.get_available_to_produce(entity)
var amount = owniverse.calculate_max_producible(entity)
#print(item_id, " : ", amount)
page_actions[pa].set_actions(item_id, amount)
func _page_action_pressed(page_id: int, action_amount: float) -> void:
@@ -273,8 +260,42 @@ func _page_action_pressed(page_id: int, action_amount: float) -> void:
owniverse.produce(item_id, action_amount)
#endregion
func _ready() -> void:
var inited_result = owniverse.init_enitities()
locked_items = inited_result.locked_items
owniverse.load_data()
_init_owniverse_items()
g_counters.swipe.sec = 0.2
for pa in page_actions:
page_actions[pa].action_pressed.connect(_page_action_pressed)
page_actions[pa].page_id = pa
func _process(delta: float) -> void:
owniverse.evolute(delta)
set_datetime(owniverse.state.year)
#owniverse.cycle(delta)
#owniverse.cycle_legacy(year_delta)
var actions = _check_counters(delta)
_do_actions(actions)
_set_active_page_actions()
func _change_speed(delta: int) -> void:
var speed: int = owniverse.change_speed(delta)
owniverse.speed = owniverse.speed + delta
var speed: int = owniverse.speed
var ind: int = 1
for icon in g_speed_icons:
if ind <= speed:
@@ -294,7 +315,7 @@ func _change_speed(delta: int) -> void:
func _on_topmenu_button_pressed(ButtonName) -> void:
print(ButtonName)
print("Debug: ", owniverse.state)
#var s: float = 1E15
#var z = 1.0
#for i in range(30):
@@ -302,5 +323,7 @@ func _on_topmenu_button_pressed(ButtonName) -> void:
#z *= 10
func _on_save_data() -> void:
func _on_unlock_and_save_timeout() -> void:
owniverse.save_data()
_unlock_items()
+1 -1
View File
@@ -2,7 +2,7 @@
[ext_resource type="Script" uid="uid://c2ech05mh56y8" path="res://ui/actions/actions.gd" id="1_cjivn"]
[ext_resource type="FontFile" uid="uid://d3k1ddvv0rmhs" path="res://fonts/Roboto_Condensed/RobotoCondensed-Light.ttf" id="1_lgdyb"]
[ext_resource type="Texture2D" uid="uid://gsclv7fr1rbr" path="res://ui/actions/action_button.png" id="2_cjivn"]
[ext_resource type="Texture2D" path="res://ui/actions/action_button.png" id="2_cjivn"]
[node name="Actions" type="HBoxContainer" unique_id=503388208]
custom_minimum_size = Vector2(0, 216)
+2 -2
View File
@@ -1,6 +1,6 @@
[gd_scene format=3 uid="uid://dg15dpxiepicb"]
[ext_resource type="Texture2D" uid="uid://chxxghyul1im7" path="res://ui/border/border-2px.png" id="1_6kaf8"]
[ext_resource type="Texture2D" path="res://ui/border/border-2px.png" id="1_6kaf8"]
[node name="Border" type="TextureRect"]
[node name="Border" type="TextureRect" unique_id=1148150816]
texture = ExtResource("1_6kaf8")
+1 -1
View File
@@ -1,7 +1,7 @@
[gd_scene format=3 uid="uid://d3xjfxwe3w16v"]
[ext_resource type="Script" uid="uid://bxxllddlgurus" path="res://ui/owniverse_item/owniverse_item.gd" id="1_d5xam"]
[ext_resource type="Texture2D" uid="uid://s16jmvdrq8cb" path="res://ui/owniverse_item/selected.png" id="2_pbv1j"]
[ext_resource type="Texture2D" path="res://ui/owniverse_item/selected.png" id="2_pbv1j"]
[node name="Button" type="Control" unique_id=667620208]
visible = false
+1 -1
View File
@@ -2,7 +2,7 @@
[ext_resource type="Script" uid="uid://bq7xkdvq4iejn" path="res://world/background/starry_sky_layer.gd" id="1_st4ay"]
[node name="StarrySkyLayer" type="Parallax2D"]
[node name="StarrySkyLayer" type="Parallax2D" unique_id=1953063300]
scroll_offset = Vector2(1080, 1920)
repeat_size = Vector2(1080, 1920)
repeat_times = 3
+351 -139
View File
@@ -1,13 +1,7 @@
extends Node
class_name Owniverse
var evolution: OwniverseEvolution = OwniverseEvolution.new()
signal unlock_item(item_id: String)
var current_year: float = 0.0
var current_speed: int = 1
var current_speed_in_years: float = 1.0
#var state: State = State.new()
var entities: Dictionary[String, OwniverseEntity] = {}
var entity_groups: Dictionary[String, Array] = {}
@@ -18,126 +12,334 @@ var items_to_update: Dictionary[String, float] = {}
var auto_production: Array = []
var locked_entities: Array = []
var cumulative_amount: Dictionary[String, float] = {}
var current_amount: Dictionary[String, float] = {}
#var cumulative_amount: Dictionary[String, float] = {}
#var current_amount: Dictionary[String, float] = {}
func cycle(year_delta: float) -> void:
# all owniverse activity should be called here
_auto_production(year_delta)
# ------------------------------------
var state: Dictionary = {
'datetime': 0.0,
'year': 0.0,
'speed': 1,
'speed_in_year': 1,
'energy': 1E14,
'batches': {},
'binds': {},
'amount': {},
'stats': {
'total_amount': {},
}
}
var new_state = state.duplicate_deep()
var speed: int:
get:
return state.speed
set(value):
state.speed = clampi(value, 1, Global.SPEED_LIMIT)
state.speed_in_years = pow(10, state.speed - 1)
func evolute(delta: float):
_check_locked_items()
_add_time_delta(delta)
# produce and evolute
#new_owniverse.state = state
#new_owniverse.stats = stats
#new_owniverse.entities = entities
#.locked_entities = locked_entities
evolution.update_distribution(current_amount)
#region auto production and evolution
func _auto_production(year_delta: float) -> void:
var _cycle_production = {"S": 0.0, "H": 0.0}
for entity: OwniverseEntity in auto_production:
if current_amount[entity.id] == 0:
continue
_cycle_production[entity.product_per_year_type] += \
current_amount[entity.id] * entity.product_per_year_amount * year_delta
for item in _cycle_production:
_count_amount(item, _cycle_production[item])
func _add_time_delta(delta: float):
pass
#new_owniverse.state.datetime = state.datetime \
#+ delta * new_owniverse.state.speed_in_year
#
#new_owniverse.state.year = floorf(new_owniverse.state.datetime)
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
func produce(item_id: String, amount: float) -> void:
var _entity: OwniverseEntity = entities[item_id]
## Produces entities with cost and bind constraints
## @param item_id - entity id to produce
## @param desired_amount - desired quantity to produce
## @return actual amount produced based on available resources
func produce(item_id: String, desired_amount: float) -> float:
# Use special production for S and H
if item_id == "S" or item_id == "H":
return produce_hs(item_id, desired_amount)
var entity_transaction = {}
for elem in _entity.cost:
if current_amount[elem] < amount * _entity.cost[elem]:
return
if _entity.cost[elem] == 0: continue
entity_transaction[elem] = - amount * _entity.cost[elem]
for elem in entity_transaction:
_process_enitity(elem, entity_transaction[elem])
_process_enitity(item_id, amount)
evolution.add(_entity, current_year, amount)
func automated_production(_delta: float) -> void:
for entity_id in auto_production:
var _entity = entities[entity_id]
var _amount_to_produce = int(_entity.amount * _entity.product_per_year_amount * _delta)
func get_available_to_produce(item_id: String) -> float:
var entity: OwniverseEntity = entities[item_id]
if entity.cost == {}: return 0
var amount: float = 1E50
for elem in entity.cost:
amount = min(floorf(current_amount[elem] / entity.cost[elem]), amount)
return amount
if desired_amount <= 0:
return 0.0
var max_producible = calculate_max_producible(entity, desired_amount)
if max_producible <= 0:
return 0.0
apply_costs(entity, max_producible)
apply_binds(item_id, entity, max_producible)
# Add produced entities
_process_enitity(item_id, max_producible)
return max_producible
## Produces S (space) or H (hydrogen) using energy from state.energy
## @param entity_id - entity id to produce ("S" or "H")
## @param value - desired amount to produce
## @return actual amount produced (limited by available energy)
func produce_hs(entity_id: String, value: float) -> float:
if value <= 0:
return 0.0
var to_produce: float = floorf(value)
to_produce = min(to_produce, state.energy)
if to_produce <= 0:
return 0.0
state.energy -= to_produce
_process_enitity(entity_id, to_produce)
state.stats.total_amount[entity_id] = state.stats.total_amount.get(entity_id, 0.0) + to_produce
return to_produce
## Calculates maximum producible amount based on cost and bind constraints
## @param entity - entity to produce
## @param desired_amount - desired quantity
## @return maximum producible amount considering all constraints
func calculate_max_producible(entity: OwniverseEntity, desired_amount: float = 1.0E150) -> float:
var max_producible: float = desired_amount
# Check cost constraints - resources consumed during production
for cost_item in entity.cost:
if entity.cost[cost_item] == 0:
continue
var available = state.amount.get(cost_item, 0.0)
var max_from_cost = floorf(available / entity.cost[cost_item])
max_producible = min(max_producible, max_from_cost)
# Check bind constraints - resources locked by produced entity
for bind_item in entity.bind:
if entity.bind[bind_item] == 0:
continue
var available = state.amount.get(bind_item, 0.0)
var max_from_bind = floorf(available / entity.bind[bind_item])
max_producible = min(max_producible, max_from_bind)
return max_producible
## Applies cost (consumes resources)
## @param entity - entity being produced
## @param amount - amount to produce
func apply_costs(entity: OwniverseEntity, amount: float) -> void:
for cost_item in entity.cost:
if entity.cost[cost_item] == 0:
continue
var cost_amount = amount * entity.cost[cost_item]
_process_enitity(cost_item, -cost_amount)
## Applies bind (locks resources)
## @param item_id - id of entity being produced
## @param entity - entity being produced
## @param amount - amount to produce
func apply_binds(item_id: String, entity: OwniverseEntity, amount: float) -> void:
for bind_item in entity.bind:
if entity.bind[bind_item] == 0:
continue
var bind_amount = amount * entity.bind[bind_item]
# Initialize binds dictionary for this entity if needed
if not state.binds.has(item_id):
state.binds[item_id] = {}
# Record bound amount
state.binds[item_id][bind_item] = bind_amount
# Decrease available amount (lock it)
_process_enitity(bind_item, -bind_amount)
## Computes a normalized distribution of dictionary values (sum equals 1.0)
## @param values - dictionary containing numeric values
## @return dictionary with normalized values, each ranging from 0.0 to 1.0
func _normalize_distribution(values: Dictionary) -> Dictionary:
var normalized_distribution: Dictionary = {}
var distribution_total: float = 0
for id in values:
if values[id] != 0:
distribution_total += values[id]
normalized_distribution[id] = values[id]
for id in normalized_distribution:
normalized_distribution[id] /= distribution_total
return normalized_distribution
#endregion
#region Batches
## Consumes entities from batches based on current year
## Iterates through batches and withdraws amount based on time period:
## - If current_year >= end_year: consume entire batch
## - If current_year in [start_year, end_year): consume proportional amount
## @param entity - entity to consume from
## @param current_year - current year in universe
## @return total amount consumed from all applicable batches
func consume_from_batches(entity: OwniverseEntity, current_year: float) -> float:
var batches = state.batches[entity.id]
var total_consumed: float = 0.0
# Iterate backwards to safely remove completed batches
state.amount[entity.id] = 0
for i in range(batches.size() - 1, -1, -1):
var batch = batches[i]
# Skip batches that haven't started yet
if current_year < batch["start_year"]:
state.amount[entity.id] += batch["amount"]
continue
# If year is past batch end, consume entire batch
if current_year >= batch["end_year"]:
total_consumed += batch["amount"]
batches.remove_at(i)
else:
# Consume proportional amount based on elapsed time
var batch_duration = batch["end_year"] - batch["start_year"]
var time_elapsed = current_year - batch["start_year"]
var proportion = time_elapsed / batch_duration
var consumed_amount = batch["amount"] * proportion
total_consumed += consumed_amount
batch["amount"] -= consumed_amount
state.amount[entity.id] += batch["amount"]
return total_consumed
## Adds entity amount to appropriate batch based on current year
## state.batches[entity_id] contains list of batches with intervals and amounts
## Each batch: {start_year, end_year, amount}
## @param entity_id - id of entity to add
## @param amount - quantity of entity being added
## @param current_year - current year in universe
func add_entity_to_batch(entity: OwniverseEntity, amount: float, current_year: float) -> void:
var batches = state.batches[entity]
# Check if we can add to last batch
var last_batch: Dictionary
if batches.size() > 0:
last_batch = batches[-1]
if batches.size() == 0 or current_year >= last_batch["end_year"]:
# Create new batch based on current_year
last_batch = {
"start_year": current_year,
"end_year": current_year + entity.lifespan_delta,
"amount": amount
}
batches.append(last_batch)
else:
# Add to existing batch
last_batch["amount"] += amount
#endregion
#region ProductionLegacy
#-----
#func _produce_automatically(year_delta: float) -> void:
#var cycle_production = {"S": 0.0, "H": 0.0}
#for entity: OwniverseEntity in auto_production:
#if current_amount[entity.id] == 0:
#continue
#cycle_production[entity.product_per_year_type] += \
#current_amount[entity.id] * entity.product_per_year_amount * year_delta
#for item in cycle_production:
#_count_amount(item, cycle_production[item])
#
#func automated_production(_delta: float) -> void:
#for entity_id in auto_production:
#var entity = entities[entity_id]
#var _amount_to_produce = int(entity.amount * entity.product_per_year_amount * _delta)
#func get_available_to_produce(item_id: String) -> float:
#var entity: OwniverseEntity = entities[item_id]
#if entity.cost == {}: return 0
#var amount: float = 1E50
#for elem in entity.cost:
#amount = min(floorf(current_amount[elem] / entity.cost[elem]), amount)
#return amount
# add to all lists
## Processes entity production/consumption
## @param entity_id - id of entity to process
## @param amount - amount to change (positive for production, negative for consumption)
func _process_enitity(entity_id: String, amount: float) -> void:
if amount == 0: return
_count_amount(entity_id, amount)
func _count_amount(entity_id: String, amount: float) -> void:
if amount == 0: return
if amount == 0:
return
current_amount[entity_id] += amount
var entity: OwniverseEntity = entities[entity_id]
if entity.group_as != "":
current_amount[entity.group_as] += amount
# Update state amount
state.amount[entity_id] = state.amount.get(entity_id, 0.0) + amount
if amount < 0: return
cumulative_amount[entity_id] += amount
# Update items to display
items_to_update[entity_id] = state.amount[entity_id]
# Handle group updates if entity belongs to a group
var entity = entities[entity_id]
if entity.group_as != "":
cumulative_amount[entity.group_as] += amount
state.amount[entity.group_as] = state.amount.get(entity.group_as, 0.0) + amount
items_to_update[entity.group_as] = state.amount[entity.group_as]
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!
#func _count_amount(entity_id: String, amount: float) -> void:
#if amount == 0: return
#
#current_amount[entity_id] += amount
#var entity: OwniverseEntity = entities[entity_id]
#if entity.group_as != "":
#current_amount[entity.group_as] += amount
#
#if amount < 0: return
#
#cumulative_amount[entity_id] += amount
#if entity.group_as != "":
#cumulative_amount[entity.group_as] += amount
#
#items_to_update[entity_id] = current_amount[entity_id]
#endregion
#region Time
func add_time_delta(delta) -> float:
var year_delta: float = delta * current_speed_in_years
current_year += year_delta
return current_year
func change_speed(delta: int) -> int:
current_speed = clampi(current_speed + delta, 1, Global.SPEED_LIMIT)
current_speed_in_years = pow(10, current_speed - 1)
return current_speed
#endregion
@@ -146,69 +348,79 @@ func change_speed(delta: int) -> int:
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"
if !game_data.has_all(["state"
, "stats"
#, "entity_batches"
, "year",
#, "year",
]):
return false
#entity_batches = game_data["entity_batches"]
cumulative_amount = game_data["cumulative_amount"]
current_amount = game_data["current_amount"]
current_year = game_data["year"]
#cumulative_amount = _game_data["cumulative_amount"]
#current_amount = _game_data["current_amount"]
#print("loaded ", _game_data)
state = game_data["state"]
#state2 = game_data["state2"]
for item in current_amount:
items_to_update[item] = current_amount[item]
for item in state.amount:
items_to_update[item] = state.amount[item]
#print("state: ", state)
#print("stats: ", stats)
return true
func save_data() -> void:
var game_data: Dictionary = {}
game_data["year"] = current_year
game_data["cumulative_amount"] = cumulative_amount
game_data["current_amount"] = current_amount
#game_data["entity_batches"] = entity_batches
game_data["state"] = state
SaveManager.save_data("owniverse", "qwerty", game_data)
#print("saved ", game_data, "\n\n\n")
func init_enitities() -> void:
var _auto_production := []
for _entity_id in Global.OwniverseEntities:
var _entity = OwniverseEntity.new(Global.OwniverseEntities[_entity_id])
entities[_entity_id] = _entity
func init_enitities() -> Dictionary:
var _result := {
'locked_items': [],
}
#var _auto_production := []
for entity_id in Global.OwniverseEntities:
var entity = OwniverseEntity.new(Global.OwniverseEntities[entity_id])
entities[entity_id] = entity
current_amount[_entity_id] = 0
cumulative_amount[_entity_id] = 0
if _entity.group_as != "":
current_amount[_entity.group_as] = 0
cumulative_amount[_entity.group_as] = 0
#current_amount[entity_id] = 0
state.stats.total_amount[entity_id] = 0
state.amount[entity_id] = 0
if entity.lifespan > 0:
state.batches[entity] = []
add_entity_to_batch(entity, 0, 0)
if entity.group_as != "":
#current_amount[entity.group_as] = 0
state.amount[entity.group_as] = 0
state.stats.total_amount[entity.group_as] = 0
if _entity.unlock != {}:
locked_entities.append(_entity)
if entity.unlock != {}:
locked_entities.append(entity)
_result.locked_items.append(entity.id)
evolution.init_entity(_entity)
if _entity.product_per_year_type != "":
auto_production.append(_entity)
_auto_production.append(_entity.id)
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.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 != "":
if !entity_event_groups.has(entity.event_group):
entity_event_groups[entity.event_group] = []
entity_event_groups[entity.event_group].append(entity_id)
#evolution.init_batches(_auto_production)
#print("ns: ", new_state)
return _result
#endregion
+2 -1
View File
@@ -38,10 +38,11 @@ func _init(values: Dictionary) -> void:
unlock = _parse_and_string(values.unlock)
cost = _parse_and_string(values.cost)
bind = _parse_and_string(values.bind)
#print(id, " | ", cost, " | ", bind)
mass = float(values.mass)
space = int(values.space)
lifespan = float(values.lifespan)
lifespan_delta = lifespan / Global.batch_count / 2 if lifespan > 10 else lifespan
lifespan_delta = lifespan / Global.batch_count if lifespan > 10 else lifespan
auto = float(values.auto)
gamma = float(values.gamma)
blast = int(values.blast)
@@ -1,11 +1,17 @@
extends Node
class_name OwniverseEvolution
class_name State
const FLOAT_THRESHOLD: float = 1.0E14
# TODO to save !!!
var state: Dictionary = {
var data: Dictionary = {
'time': {
'timestamp': 0.0,
'year': 0.0,
},
'timestamp': 0.0,
'year': 0.0,
'speed_in_year': 0,
'energy': 1E14,
}
@@ -25,12 +31,32 @@ var evolving_entities: Array[OwniverseEntity] = []
# TODO to save !!!
var batches: Dictionary[String, Array] = {}
# TODO to save !!!
var amount: Dictionary[String, float] = {}
var gamount: Dictionary[String, float] = {}
var distribution: Dictionary[String, float] = {}
# new functions
func evolute(prev_state: State, delta: float, current_speed_in_year: float) -> float:
var _new_year: float = _add_year_delta(delta, current_speed_in_year)
if data.year == _new_year:
return data.year
return _new_year
func _add_year_delta(delta: float, current_speed_in_year: float) -> float:
var _new_year:float = floorf(data.year + delta * current_speed_in_year)
#print(data.year, " | ", _new_year, " | ", data)
return _new_year
# end of new functions
func add(entity: OwniverseEntity, year: float, amount: float):
var _batch_array: Array = batches[entity.id]
var _from_year: float = year + entity.lifespan - entity.lifespan_delta
@@ -106,11 +132,11 @@ func produce(from_year: float, to_year: float):
func produce_hs(entity_id: String, value: float) -> float:
var _to_produce: float = floorf(value)
amount[entity_id] += _to_produce
gamount[entity_id] += _to_produce
# TODO double double math
if _to_produce > state["energy"]:
_to_produce = state["energy"]
state["energy"] -= _to_produce
if _to_produce > data["energy"]:
_to_produce = data["energy"]
data["energy"] -= _to_produce
return value - _to_produce
func produce_auto() -> float:
@@ -118,7 +144,7 @@ func produce_auto() -> float:
func init_entity(entity: OwniverseEntity) -> void:
entities[entity.id] = entity
amount[entity.id] = 0.0
gamount[entity.id] = 0.0
if entity.product_per_year_type != "":
producing_entities.append(entity)
+3 -3
View File
@@ -872,8 +872,8 @@ layout_mode = 2
wait_time = 0.2
autostart = true
[node name="SaveData" type="Timer" parent="Stage" unique_id=1208861837]
wait_time = 5.0
[node name="Unlock&Save" type="Timer" parent="Stage" unique_id=1208861837]
wait_time = 2.0
autostart = true
[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/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/SaveData" to="Stage" method="_on_save_data"]
[connection signal="timeout" from="Stage/Unlock&Save" to="Stage" method="_on_unlock_and_save_timeout"]