From d8a4019ce12e7a70e7e844e2a4e192f17eef96ca Mon Sep 17 00:00:00 2001 From: Kirill Date: Tue, 21 Jul 2026 23:54:17 +0300 Subject: [PATCH] Refactor: restructure world entities and evolution logic; remove unused files and improve batch processing --- Autoload/Global.gd | 2 ++ world/Background/starry_sky_layer.tscn | 2 +- world/{ => owniverse}/owniverse.gd | 8 +---- world/{ => owniverse}/owniverse.gd.uid | 0 world/owniverse/owniverse_batch.gd | 32 +++++++++++++++++++ world/owniverse/owniverse_batch.gd.uid | 1 + .../owniverse_entity.gd} | 9 ++++-- .../owniverse_entity.gd.uid} | 0 .../owniverse_evolution.gd} | 16 ++++++++-- .../owniverse_evolution.gd.uid} | 0 world/world.tscn | 4 +-- 11 files changed, 59 insertions(+), 15 deletions(-) rename world/{ => owniverse}/owniverse.gd (96%) rename world/{ => owniverse}/owniverse.gd.uid (100%) create mode 100644 world/owniverse/owniverse_batch.gd create mode 100644 world/owniverse/owniverse_batch.gd.uid rename world/{entity.gd => owniverse/owniverse_entity.gd} (92%) rename world/{entity.gd.uid => owniverse/owniverse_entity.gd.uid} (100%) rename world/{evolution.gd => owniverse/owniverse_evolution.gd} (52%) rename world/{evolution.gd.uid => owniverse/owniverse_evolution.gd.uid} (100%) diff --git a/Autoload/Global.gd b/Autoload/Global.gd index 916c9a1..ac3eb9b 100644 --- a/Autoload/Global.gd +++ b/Autoload/Global.gd @@ -17,6 +17,8 @@ var OwniverseEntities: Dictionary = {} var OwniverseItems: Dictionary = {} var Templates: Dictionary = {} +var batch_count = 40 + func get_localized_item_description(item_id: String, item: String) -> String: if Locales[Locale].has(item_id): diff --git a/world/Background/starry_sky_layer.tscn b/world/Background/starry_sky_layer.tscn index 97df226..41fc6e2 100644 --- a/world/Background/starry_sky_layer.tscn +++ b/world/Background/starry_sky_layer.tscn @@ -1,6 +1,6 @@ [gd_scene format=3 uid="uid://icbk3la71t7h"] -[ext_resource type="Script" uid="uid://bq7xkdvq4iejn" path="res://world/Background/starry_sky_layer.gd" id="1_st4ay"] +[ext_resource type="Script" uid="uid://bq7xkdvq4iejn" path="res://world/background/starry_sky_layer.gd" id="1_st4ay"] [node name="StarrySkyLayer" type="Parallax2D"] scroll_offset = Vector2(1080, 1920) diff --git a/world/owniverse.gd b/world/owniverse/owniverse.gd similarity index 96% rename from world/owniverse.gd rename to world/owniverse/owniverse.gd index 5be3db1..cd7b5a4 100644 --- a/world/owniverse.gd +++ b/world/owniverse/owniverse.gd @@ -25,7 +25,6 @@ var batch_count: int = 40 var entity_batches = {} - func cycle(year_delta: float) -> void: # all owniverse activity should be called here _auto_production(year_delta) @@ -188,8 +187,7 @@ func save_data() -> void: func init_enitities() -> void: for entity_id in Global.OwniverseEntities: - var entity = OwniverseEntity.new() - entity.init_entity(Global.OwniverseEntities[entity_id]) + var entity = OwniverseEntity.new(Global.OwniverseEntities[entity_id]) entities[entity_id] = entity current_amount[entity_id] = 0 @@ -215,8 +213,4 @@ func init_enitities() -> void: 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 diff --git a/world/owniverse.gd.uid b/world/owniverse/owniverse.gd.uid similarity index 100% rename from world/owniverse.gd.uid rename to world/owniverse/owniverse.gd.uid diff --git a/world/owniverse/owniverse_batch.gd b/world/owniverse/owniverse_batch.gd new file mode 100644 index 0000000..ea33c8c --- /dev/null +++ b/world/owniverse/owniverse_batch.gd @@ -0,0 +1,32 @@ +extends Node + +class_name OwniverseBatch + +var from_year: float +var to_year: float + +var amount: float = 0 + + +func process(year: float) -> float: + var _amount: float = 0 + if year < to_year: return 0 + if year >= to_year: + _amount = amount + amount = 0 + return _amount + + _amount = clampf(amount * (year - from_year) / (to_year - from_year), 0, amount) + amount -= _amount + from_year = year + 1 + + return _amount + + +func add(delta: float) -> void: + amount += delta + + +func _init(year: float, year_delta: float) -> void: + from_year = year - year_delta + to_year = year + year_delta diff --git a/world/owniverse/owniverse_batch.gd.uid b/world/owniverse/owniverse_batch.gd.uid new file mode 100644 index 0000000..22dc595 --- /dev/null +++ b/world/owniverse/owniverse_batch.gd.uid @@ -0,0 +1 @@ +uid://cs0mllvnraida diff --git a/world/entity.gd b/world/owniverse/owniverse_entity.gd similarity index 92% rename from world/entity.gd rename to world/owniverse/owniverse_entity.gd index 0544ea6..220d3cc 100644 --- a/world/entity.gd +++ b/world/owniverse/owniverse_entity.gd @@ -8,7 +8,8 @@ var cost: Dictionary = {} var bind: Dictionary = {} var mass: float var space: int -var lifespan: int +var lifespan: float +var lifespan_cycle: float var auto: float var gamma: float var blast: int @@ -31,7 +32,7 @@ var claim: String var amount: float = 0.0 -func init_entity(values: Dictionary) -> void: +func _init(values: Dictionary) -> void: id = values.id is_visible = values.is_visible == "1" unlock = _parse_and_string(values.unlock) @@ -39,7 +40,9 @@ func init_entity(values: Dictionary) -> void: bind = _parse_and_string(values.bind) mass = float(values.mass) space = int(values.space) - lifespan = int(values.lifespan) + lifespan = float(values.lifespan) + lifespan_cycle = lifespan / Global.batch_count # need for proper math + print(id, " → ", lifespan, " | ", lifespan_cycle) auto = float(values.auto) gamma = float(values.gamma) blast = int(values.blast) diff --git a/world/entity.gd.uid b/world/owniverse/owniverse_entity.gd.uid similarity index 100% rename from world/entity.gd.uid rename to world/owniverse/owniverse_entity.gd.uid diff --git a/world/evolution.gd b/world/owniverse/owniverse_evolution.gd similarity index 52% rename from world/evolution.gd rename to world/owniverse/owniverse_evolution.gd index de8bded..79f2b4d 100644 --- a/world/evolution.gd +++ b/world/owniverse/owniverse_evolution.gd @@ -3,11 +3,23 @@ extends Node class_name OwniverseEvolution var batch_count: int = 40 -var entity_batches = {} +var batches: Dictionary[String, Array] = {} var distribution: Dictionary[String, float] = {} +func evolute(): + pass + +func add_to_batch(enitity: OwniverseEntity, amount: float, year: float) -> void: + var to_year: float = year + enitity.lifespan + var _entity_batches: Array[OwniverseBatch] = batches[enitity.id] + if _entity_batches.size() == 0 or _entity_batches[-1].to_year <= to_year: + _entity_batches.append(OwniverseBatch.new(to_year, enitity.lifespan_cycle)) + + _entity_batches[-1].add(amount) + + func update_distribution(_distribute_by: Dictionary[String, float]) -> void: distribution = {} var _total: float = 0 @@ -18,7 +30,7 @@ func update_distribution(_distribute_by: Dictionary[String, float]) -> void: distribution[id] = _value if _total == 0: return - + for id in distribution: distribution[id] /= _total diff --git a/world/evolution.gd.uid b/world/owniverse/owniverse_evolution.gd.uid similarity index 100% rename from world/evolution.gd.uid rename to world/owniverse/owniverse_evolution.gd.uid diff --git a/world/world.tscn b/world/world.tscn index 04f3325..757d563 100644 --- a/world/world.tscn +++ b/world/world.tscn @@ -1,7 +1,7 @@ [gd_scene format=3 uid="uid://bv384dpmvjv8o"] -[ext_resource type="Script" uid="uid://d2wrwichuoncd" path="res://world/Background/background.gd" id="1_ifjjt"] -[ext_resource type="PackedScene" uid="uid://icbk3la71t7h" path="res://world/Background/starry_sky_layer.tscn" id="2_behgl"] +[ext_resource type="Script" uid="uid://d2wrwichuoncd" path="res://world/background/background.gd" id="1_ifjjt"] +[ext_resource type="PackedScene" uid="uid://icbk3la71t7h" path="res://world/background/starry_sky_layer.tscn" id="2_behgl"] [ext_resource type="Script" uid="uid://iiva6x8uo0f2" path="res://stage/stage.gd" id="3_k83x5"] [ext_resource type="Texture2D" uid="uid://5f80g4i46ycl" path="res://ui/topmenu/buttons/button.burger.normal.png" id="4_b8tmp"] [ext_resource type="Texture2D" uid="uid://caia36a08wlqs" path="res://ui/topmenu/buttons/button.burger.pressed.png" id="5_en1oy"]