Refactor code structure for improved readability and maintainability

This commit is contained in:
Kirill
2026-05-31 10:57:44 +03:00
parent edb5ec9dfa
commit c21048add3
12 changed files with 179 additions and 194 deletions
+12 -21
View File
@@ -2,10 +2,9 @@ extends Node2D
@export_group("Visual Settings")
@export var STARRY_SKY_LAYER: PackedScene
@export var Star_Count: int = 2000: set = set_star_count
@export var Star_Count: int = 2000
@export var Background_Image_Size: Vector2 = Vector2(1080, 1920):
set = set_Background_Image_Size
@export var Background_Image_Size: Vector2 = Vector2(1080, 1920)
@export var Background_Layers: Array [StarrySkyLayer]
var Stars_by_Layers: Dictionary = {}
@@ -59,10 +58,11 @@ func _ready() -> void:
initiate_layers()
randomize_parallax()
generate_layers()
randomize_parallax(0)
func _process(delta: float) -> void:
if randi_range(0, 1000) == 0:
randomize_parallax()
#func _process(delta: float) -> void:
#if randi_range(0, 1000) == 0:
#randomize_parallax()
func _draw() -> void:
draw_rect(Rect2(Vector2.ZERO, Background_Image_Size), BACKGROUND_COLOR)
@@ -71,8 +71,8 @@ func generate_layers():
var max_rnd_seed = STAR_COLOR_DISTRIBUTION[-1][0]
for ind1 in range(Star_Count):
var star_coords = Vector2(randi_range(0, Background_Image_Size.x),
randi_range(0, Background_Image_Size.y))
var star_coords = Vector2(randf_range(0, Background_Image_Size.x),
randf_range(0, Background_Image_Size.y))
var rnd_seed = randi_range(0, max_rnd_seed)
for item:Array in STAR_COLOR_DISTRIBUTION:
var item_seed = item[0]
@@ -94,10 +94,12 @@ func initiate_layers():
var new_star_layer:StarrySkyLayer = STARRY_SKY_LAYER.instantiate()
add_child(new_star_layer)
new_star_layer.Background_Image_Size = Background_Image_Size
#new_star_layer.autoscroll = (ind1 + 1) * DEFAULT_AUTOSCROL
Background_Layers.append(new_star_layer)
func randomize_parallax():
func randomize_parallax(chance: int = 120):
if randi_range(0, chance) != 0:
return
var x_offset = 0
var y_offset = 0
if _random_sign() == 1:
@@ -119,14 +121,3 @@ func _random_sign() -> int:
return [1, -1].pick_random()
#endregion
#region Сеттеры для автоматического обновления
func set_Background_Image_Size(value: Vector2):
Background_Image_Size = value
queue_redraw()
func set_star_count(value: int):
Star_Count = value
queue_redraw()
#endregion
+5 -9
View File
@@ -23,8 +23,9 @@ func cycle(delta: float) -> void:
func produce(item_id: String, amount: int) -> void:
if item_id == "S" or item_id == 'H':
entities[item_id].amount += 1
#if item_id == "S" or item_id == 'H':
#entities[item_id].amount += 1
entities[item_id].amount += amount
var entity: OwniverseEntity = entities[item_id]
_process_enitity(entity, amount)
@@ -54,15 +55,10 @@ func _check_locked_items() -> void:
for elem in entity.unlock:
if cumulative_amount[elem] < entity.unlock[elem]:
continue
print(entity.id, " ", elem, ":", entity.unlock[elem])
#print(entity.id, " ", elem, ":", entity.unlock[elem])
unlock_item.emit(entity.id)
locked_entities.erase(entity)
# unlock here
return
return # SIC!
#endregion
+16 -8
View File
@@ -49,6 +49,9 @@
script = ExtResource("1_ifjjt")
STARRY_SKY_LAYER = ExtResource("2_behgl")
[node name="Timer" type="Timer" parent="Background" unique_id=188844703]
autostart = true
[node name="Stage" type="Control" parent="." unique_id=1485959841]
custom_minimum_size = Vector2(1080, 1920)
layout_mode = 3
@@ -214,7 +217,7 @@ layout_mode = 2
layout_mode = 2
[node name="Description" type="RichTextLabel" parent="Stage/StageRows/PageScroller/HBoxContainer/ForcePage" unique_id=1934400572]
custom_minimum_size = Vector2(0, 670)
custom_minimum_size = Vector2(0, 384)
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/normal_font = ExtResource("14_o7xkw")
@@ -227,8 +230,6 @@ theme_override_font_sizes/bold_italics_font_size = 42
theme_override_font_sizes/italics_font_size = 42
theme_override_font_sizes/mono_font_size = 42
bbcode_enabled = true
text = "Forces"
fit_content = true
horizontal_alignment = 1
[node name="Border" parent="Stage/StageRows/PageScroller/HBoxContainer/ForcePage" unique_id=519355296 instance=ExtResource("12_58wjt")]
@@ -350,7 +351,7 @@ texture = ExtResource("23_bcq5b")
layout_mode = 2
[node name="Description" type="RichTextLabel" parent="Stage/StageRows/PageScroller/HBoxContainer/ResourcePage" unique_id=1171833]
custom_minimum_size = Vector2(0, 670)
custom_minimum_size = Vector2(0, 384)
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/normal_font = ExtResource("14_o7xkw")
@@ -363,7 +364,6 @@ theme_override_font_sizes/bold_italics_font_size = 42
theme_override_font_sizes/italics_font_size = 42
theme_override_font_sizes/mono_font_size = 42
bbcode_enabled = true
fit_content = true
horizontal_alignment = 1
[node name="Border" parent="Stage/StageRows/PageScroller/HBoxContainer/ResourcePage" unique_id=1268799323 instance=ExtResource("12_58wjt")]
@@ -470,7 +470,7 @@ texture = ExtResource("28_upe80")
layout_mode = 2
[node name="Description" type="RichTextLabel" parent="Stage/StageRows/PageScroller/HBoxContainer/StarPage" unique_id=1195874488]
custom_minimum_size = Vector2(0, 670)
custom_minimum_size = Vector2(0, 384)
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/normal_font = ExtResource("14_o7xkw")
@@ -604,7 +604,7 @@ texture = ExtResource("23_bcq5b")
layout_mode = 2
[node name="Description" type="RichTextLabel" parent="Stage/StageRows/PageScroller/HBoxContainer/StructurePage" unique_id=414749774]
custom_minimum_size = Vector2(0, 670)
custom_minimum_size = Vector2(0, 384)
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/normal_font = ExtResource("14_o7xkw")
@@ -745,7 +745,7 @@ texture = ExtResource("41_mi6gc")
layout_mode = 2
[node name="Description" type="RichTextLabel" parent="Stage/StageRows/PageScroller/HBoxContainer/LifePage" unique_id=454792539]
custom_minimum_size = Vector2(0, 670)
custom_minimum_size = Vector2(0, 384)
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/normal_font = ExtResource("14_o7xkw")
@@ -822,6 +822,13 @@ offset_top = 512.0
offset_right = 1080.0
offset_bottom = 1024.0
[node name="Border" parent="Stage/StageRows" unique_id=145801370 instance=ExtResource("12_58wjt")]
layout_mode = 2
[node name="HBoxContainer" type="HBoxContainer" parent="Stage/StageRows" unique_id=1880020851]
custom_minimum_size = Vector2(0, 184)
layout_mode = 2
[node name="ItemAmountUpdate" type="Timer" parent="Stage" unique_id=1953928024]
wait_time = 0.2
autostart = true
@@ -829,6 +836,7 @@ autostart = true
[node name="CommandProcessor" type="Node" parent="." unique_id=2069361293]
script = ExtResource("42_1s1fv")
[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]]