Refactor code structure for improved readability and maintainability

This commit is contained in:
Kirill
2026-04-05 23:26:43 +03:00
parent 81fe51ff4e
commit 094726a793
8 changed files with 1246 additions and 1140 deletions
+17
View File
@@ -23,17 +23,34 @@ var Locales: Dictionary = {}
var Locale = "en"
var Entities: Dictionary = {}
var Templates: Dictionary = {}
func get_localized_item_description(entity_id: String, item: String) -> String:
if Locales[Locale].has(entity_id):
return Locales[Locale][entity_id][item]
return ""
func get_description(item_id: String, values: Array = []) -> String:
if !Templates[Locale].has(item_id):
return ""
#print(Templates[Locale])
var description: String = Templates[Locale][item_id]["text"]
var value = 0
for item in values:
description.replace("value"+str(value), str(item))
return description
func _ready() -> void:
Entities = _read_from_csv("res://Autoload/entities.csv")
Locales["en"] = _read_from_csv("res://Autoload/locale.en.csv")
Locales["ru"] = _read_from_csv("res://Autoload/locale.ru.csv")
Templates["en"] = _read_from_csv("res://Autoload/templates.en.csv")
func _read_from_csv(file_path: String) -> Dictionary:
if not FileAccess.file_exists(file_path):
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+27 -38
View File
@@ -37,13 +37,13 @@ const SWIPE_DELAY = 2000 # msec
@onready var date_time: Label = $StageRows/TopMenu/InfoPanel/DateTime
@onready var g_speed_icons: Array = [
$StageRows/TopMenu/InfoPanel/Speed/Speed1,
$StageRows/TopMenu/InfoPanel/Speed/Speed2,
$StageRows/TopMenu/InfoPanel/Speed/Speed3,
$StageRows/TopMenu/InfoPanel/Speed/Speed4,
$StageRows/TopMenu/InfoPanel/Speed/Speed5,
$StageRows/TopMenu/InfoPanel/Speed/Speed6,
$StageRows/TopMenu/InfoPanel/Speed/Speed7,
$StageRows/TopMenu/InfoPanel/Speed/Speed1,
$StageRows/TopMenu/InfoPanel/Speed/Speed2,
$StageRows/TopMenu/InfoPanel/Speed/Speed3,
$StageRows/TopMenu/InfoPanel/Speed/Speed4,
$StageRows/TopMenu/InfoPanel/Speed/Speed5,
$StageRows/TopMenu/InfoPanel/Speed/Speed6,
$StageRows/TopMenu/InfoPanel/Speed/Speed7,
$StageRows/TopMenu/InfoPanel/Speed/Speed8
]
@@ -51,7 +51,6 @@ const SWIPE_DELAY = 2000 # msec
@onready var g_time_plus: TextureButton = $StageRows/TopMenu/TimePlus
var g_tween: Tween = null
var g_dragged_start: Vector2 = Vector2.ZERO
var g_scroll_start: int = 0
@@ -73,37 +72,38 @@ var owniverse = Owniverse.new()
func set_datetime(value: String):
date_time.text = value
func on_putton_pressed(button_name: String):
#emit_signal("button_pressed", button_name)
print(button_name)
#SaveManager.save_settings()
#SaveManager.ch()
#print(Global.filename)
#func _on_speed_change(delta: int) -> void:
#print(delta)
func _on_indicator_pressed(indicator_name: String, page: int = 0):
_set_description(indicator_name, page)
func entity_activated(entity: OwniverseEntity) -> void:
_control_page(entity)
_set_description(entity)
_set_entity_description(entity)
func _set_description(entity: OwniverseEntity) -> void:
func _set_entity_description(entity: OwniverseEntity) -> void:
var description: String = "[b]" \
+ Global.get_localized_item_description(entity.entity_name, "label") \
+ "[/b]" \
+ "\n" \
+"[/b]" \
+"\n" \
+ Global.get_localized_item_description(entity.entity_name, "description")
var desc_page = clamp(entity.entity_page, 0, 4)
g_entity_descriptions[desc_page].text = description
pass
func _set_description(item_name: String, page: int) -> void:
var description = Global.get_description(item_name + ".Name")
description += "\n"
description += Global.get_description(item_name + ".Description")
g_entity_descriptions[page].text = description
func _control_page(entity: OwniverseEntity) -> void:
if !ActiveEntities.has(entity.entity_page):
ActiveEntities[entity.entity_page] = null
var current_entity:OwniverseEntity = ActiveEntities[entity.entity_page]
var current_entity: OwniverseEntity = ActiveEntities[entity.entity_page]
if current_entity == entity:
return
@@ -159,7 +159,7 @@ func _check_counters(delta: float) -> Array:
func _do_actions(actions: Array) -> void:
for action: String in actions:
match action:
"swipe":
"swipe":
_swipe_to_nearest_page()
@@ -176,12 +176,11 @@ func _swipe_to_nearest_page() -> void:
return
g_tween = stage_page_scroller.get_tree().create_tween()
g_tween.tween_property(stage_page_scroller, "scroll_horizontal",
g_tween.tween_property(stage_page_scroller, "scroll_horizontal",
new_page * PAGE_WIDTH, SWIPE_DURATION).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT)
func _input(event: InputEvent) -> void:
if event is InputEventScreenDrag:
stage_page_scroller.scroll_horizontal = clamp(
stage_page_scroller.scroll_horizontal - PAGE_COUNT * event.screen_relative.x,
@@ -199,9 +198,6 @@ func _input(event: InputEvent) -> void:
func _ready() -> void:
_init_entities()
func _on_button_pressed(extra_param): # теперь 1 параметр
print("Кнопка нажата! Параметр:", extra_param)
func _process(delta: float) -> void:
# Update date
@@ -221,15 +217,6 @@ func _on_report_button_pressed() -> void:
print("r")
pass # Replace with function body.
func _on_time_minus_pressed() -> void:
_change_speed(-1)
func _on_time_plus_pressed() -> void:
_change_speed(+1)
func _change_speed(delta: int) -> void:
var speed: int = owniverse.change_speed(delta)
var ind: int = 1
@@ -249,3 +236,5 @@ func _change_speed(delta: int) -> void:
g_time_minus.texture_normal = load(SPEED_TEXTURE_NAME_TEMPLATE % str(speed - 1))
g_time_plus.texture_normal = load(SPEED_TEXTURE_NAME_TEMPLATE % str(speed + 1))
func _on_topmenu_button_pressed(ButtonName) -> void:
print(ButtonName)
+3 -3
View File
@@ -8,7 +8,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="../../Documents/Owad/Owniverse.I/Builds/owniverse.II.20260401.exe"
export_path="../../Documents/Owad/Owniverse.I/Builds/owniverse.0.6.7.exe"
patches=PackedStringArray()
patch_delta_encoding=false
patch_delta_compression_level_zstd=19
@@ -80,7 +80,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="../../Sync/Owad/Owniverse.I/Builds/owniverse.0.6.7-123.aab"
export_path="../../Documents/Owad/Owniverse.I/Builds/owniverse.0.6.8-124.aab"
patches=PackedStringArray()
patch_delta_encoding=false
patch_delta_compression_level_zstd=19
@@ -110,7 +110,7 @@ architectures/armeabi-v7a=false
architectures/arm64-v8a=true
architectures/x86=false
architectures/x86_64=false
version/code=123
version/code=124
version/name=""
package/unique_name="com.KIDGameProduction.Owniverse"
package/name="Owniverse"
+1 -1
View File
@@ -15,7 +15,7 @@ compatibility/default_parent_skeleton_in_mesh_instance_3d=true
[application]
config/name="Owniverse"
config/version="0.6.7"
config/version="0.6.8"
run/main_scene="uid://bv384dpmvjv8o"
config/features=PackedStringArray("4.6", "Mobile")
config/icon="res://icon.svg"
+12 -4
View File
@@ -823,7 +823,15 @@ offset_bottom = 1024.0
[node name="CommandProcessor" type="Node" parent="." unique_id=2069361293]
script = ExtResource("5_036b0")
[connection signal="pressed" from="Stage/StageRows/TopMenu/BurgerButton" to="Stage" method="_on_burger_button_pressed"]
[connection signal="pressed" from="Stage/StageRows/TopMenu/TimeMinus" to="Stage" method="_on_time_minus_pressed"]
[connection signal="pressed" from="Stage/StageRows/TopMenu/TimePlus" to="Stage" method="_on_time_plus_pressed"]
[connection signal="pressed" from="Stage/StageRows/TopMenu/ReportButton" to="Stage" method="_on_report_button_pressed"]
[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]]
[connection signal="pressed" from="Stage/StageRows/TopMenu/ReportButton" to="Stage" method="_on_topmenu_button_pressed" binds= ["Report"]]
[connection signal="pressed" from="Stage/StageRows/PageScroller/HBoxContainer/ResourcePage/ResourceHeader/EnergyIndicator" to="Stage" method="_on_indicator_pressed" binds= ["Energy", 1]]
[connection signal="pressed" from="Stage/StageRows/PageScroller/HBoxContainer/ResourcePage/ResourceHeader/DensityIndicator" to="Stage" method="_on_indicator_pressed" binds= ["Density", 1]]
[connection signal="pressed" from="Stage/StageRows/PageScroller/HBoxContainer/StarPage/StarHeader/BurnabilityIndicator" to="Stage" method="_on_indicator_pressed" binds= ["Burnability", 2]]
[connection signal="pressed" from="Stage/StageRows/PageScroller/HBoxContainer/StarPage/StarHeader/ExplosivenessIndicator" to="Stage" method="_on_indicator_pressed" binds= ["Explosiveness", 2]]
[connection signal="pressed" from="Stage/StageRows/PageScroller/HBoxContainer/StructurePage/StructureHeader/EnergyIndicator" to="Stage" method="_on_indicator_pressed" binds= ["Energy", 3]]
[connection signal="pressed" from="Stage/StageRows/PageScroller/HBoxContainer/StructurePage/StructureHeader/DensityIndicator" to="Stage" method="_on_indicator_pressed" binds= ["Density", 3]]
[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]]
-2
View File
@@ -19,7 +19,5 @@ func change_speed(delta: int) -> int:
return g_speed
func hello():
print("ello")