Refactor code structure for improved readability and maintainability; removed redundant code blocks and optimized existing functions.

This commit is contained in:
Kirill
2026-05-05 23:49:12 +03:00
parent fc86261a9d
commit df563bf1b1
44 changed files with 350 additions and 312 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://icbk3la71t7h"]
[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)
+9 -43
View File
@@ -4,6 +4,7 @@ class_name OwniverseEntity
var id: String
var is_visible: bool = false
var unlock: Dictionary = {}
var is_unlocked: bool = false
var cost: Dictionary = {}
var bind: Dictionary = {}
var mass: float
@@ -18,15 +19,7 @@ var output_or: Dictionary = {}
var output_and: Dictionary = {}
var destroy_level: int
var degradation: Dictionary = {}
#deg_mass: "",
#deg_h: "",
#He": "",
#Met": "",
var planets: Dictionary = {}
#var habitable: "",
#var rocky: "",
#var gas giant: "",
#var asteroids: "",
var count_as: String
var group_as: String
var event_group: String
@@ -34,43 +27,15 @@ var space_bonus: float
var civ_bonus: float
var claim: String
var SCD: Dictionary = {
"id": "SCD",
"is_visible": "1",
"unlock": "Star:300",
"cost": "",
"bind": "Star:1000",
"mass": "",
"space": "",
"lifespan": "10000000",
"auto": "", "gamma": "",
"blast": "",
"life_product": "",
"voids": "",
"output": "",
"destroy_level": "",
"deg_mass": "",
"H": "",
"He": "",
"Met": "",
"planets": "",
"habitable": "",
"rocky": "",
"gas giant": "",
"asteroids": "",
"count_as": "",
"group_as": "SC",
"event_group": "SC",
"space_bonus": "0.1",
"civ_bonus": "4",
"claim": "C2.3"
}
var amount: float = 0.0
func init_entity(values: Dictionary) -> bool:
id = values.id
is_visible = values.is_visible == "1"
unlock = _parse_and_string(values.unlock)
if "prime" == values.unlock:
is_unlocked = true
cost = _parse_and_string(values.cost)
bind = _parse_and_string(values.bind)
mass = float(values.mass)
@@ -111,10 +76,11 @@ func _parse_or_string(source_line: String) -> Dictionary:
func _parse_and_string(source_line: String) -> Dictionary:
var result = {}
if source_line.contains("&"):
var first_split = source_line.split("&")
for elem in first_split:
var second_split = elem.split(":")
var first_split = source_line.split("&")
for elem in first_split:
var second_split = elem.split(":")
if len(second_split) == 2:
result[second_split[0]] = float(second_split[1])
return result
+36 -6
View File
@@ -5,13 +5,46 @@ var g_datetime: float = 0
var g_speed: int = 1
var g_speed_in_years = 1
var g_entities: Dictionary[String, OwniverseEntity] = {}
var entities: Dictionary[String, OwniverseEntity] = {}
var items_to_update: Dictionary[String, float] = {}
var cumulative_amount: Dictionary[String, float] = {}
#region Production
func produce(item_id: String, amount: int) -> void:
if item_id == "S" or item_id == 'H':
entities[item_id].amount += 1
_process_enitity(item_id, amount)
func automated_production() -> void:
pass
# add to all lists
func _process_enitity(item_id: String, amount: int) -> void:
items_to_update[item_id] = entities[item_id].amount
func _count_cumulative(item_id: String, amount: int) -> void:
if cumulative_amount.has(item_id):
cumulative_amount[item_id] += amount
else:
cumulative_amount[item_id] = amount
#endregion
func init_enitities() -> void:
for entity_id in Global.OwniverseEntities:
var entity = OwniverseEntity.new()
entity.init_entity(Global.OwniverseEntities[entity_id])
g_entities[entity_id] = entity
entities[entity_id] = entity
func add_time_delta(delta) -> float:
var year_delta:float = delta * g_speed_in_years
@@ -21,11 +54,8 @@ func add_time_delta(delta) -> float:
g_datetime += year_delta
return g_datetime
func change_speed(delta: int) -> int:
g_speed = clamp(g_speed + delta, 1, Global.SPEED_LIMIT)
g_speed_in_years = pow(10, g_speed-1)
return g_speed
func hello():
print("ello")
BIN
View File
Binary file not shown.
Binary file not shown.