Доработка сохранения

This commit is contained in:
lepshiy
2025-02-05 16:37:42 +03:00
parent f5b0a39a87
commit 3801a0c28d
3 changed files with 119 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=52 format=3 uid="uid://cvor2jm4xk3ha"]
[gd_scene load_steps=53 format=3 uid="uid://cvor2jm4xk3ha"]
[ext_resource type="Script" path="res://scripts/PRD.gd" id="1_v273n"]
[ext_resource type="Texture2D" uid="uid://cdxdluvyb5uei" path="res://table/on.png" id="2_dv7xx"]
@@ -155,6 +155,9 @@ shader_parameter/color4 = Color(0, 0, 0, 0)
shader_parameter/opacity = 0.218
shader_parameter/turn = 0.785
[sub_resource type="Theme" id="Theme_yblys"]
CheckBox/font_sizes/font_size = 14
[node name="Node2D" type="Node2D"]
script = ExtResource("1_v273n")
@@ -1029,6 +1032,14 @@ offset_right = 1102.0
offset_bottom = 226.0
text = "Темп"
[node name="save_other" type="CheckBox" parent="."]
offset_left = 2.0
offset_top = 799.0
offset_right = 215.0
offset_bottom = 827.0
theme = SubResource("Theme_yblys")
text = "Сохранить все настройки"
[connection signal="pressed" from="Background/side_panel/select_prd" to="." method="_on_prd_select"]
[connection signal="pressed" from="Background/side_panel/select_control" to="." method="_on_control_button"]
[connection signal="pressed" from="Background/side_panel/select_ems_g" to="." method="_on_emsg_select"]

View File

@@ -31,6 +31,10 @@ gdscript/warnings/unused_signal=0
window/size/viewport_width=1900
window/size/viewport_height=940
[editor]
run/main_run_args="-- testsave-path"
[rendering]
renderer/rendering_method="gl_compatibility"

View File

@@ -10,9 +10,25 @@ var node_select2: Node
var flag_yau_control: bool
var CONTROL_TABLE: Array
var isa_from_yau07b: Dictionary = {}
var JSOON = JSON.new()
var status_pribor = null
var save_path = "D://PRD-TU-MP550//"
var need_port: Array = [
0x122,
0x124,
0x126,
0x128,
0x12A
]
func _ready() -> void:
# Считывание аргументов с консоли (путь сохранения)
var args = OS.get_cmdline_user_args()
for i in range(args.size()):
if args[i] == "testsave-path" and i + 1 < args.size():
save_path = args[i + 1]
break
# Таблица УКП_1
node_select1 = $TabContainer/PRD/body_grid/litera_2_4_6/table_ukp_1
draw_tabl(node_select1, Constants.ROWS_REGS_DATA, Constants.ROWS_REGS_DATA.size())
@@ -91,6 +107,11 @@ func _ready() -> void:
node_select_device.get_node2(0,0).text = 'ПРИБОР'
node_select_device.set_columns_min_size([100, 100])
# Получаем имя выбранного прибора
if Constants.ADDRESSES.size() > 0:
get_select_device.select(0)
status_pribor = get_select_device.get_item_text(0).strip_edges().substr(4)
## Заполненение списка модуляции УМ
for key in Constants.OUT_x128:
node_select_yau_07b.get_node2(1, 2).add_item(key)
@@ -128,6 +149,7 @@ func _ready() -> void:
node_select_fs_1.get_node2(1, 4).get_child(1, false).connect('toggled', Callable(self, '_on_get_status_1'))
node_select_fs_2.get_node2(1, 4).get_child(1, false).connect('toggled', Callable(self, '_on_get_status_2'))
func draw_control_panel_prd(mode) -> void:
for node_path in Constants.NODE_MAP:
var index = Constants.NODE_MAP[node_path]
@@ -200,7 +222,6 @@ func _on_data_fs_1(fs_1_data):
#$read.text = str(fs_1_data.hex_encode())
func _on_data_fs_2(fs_2_data):
var node_select_fs_2 = $TabContainer/PRD/body_grid/litera_3_5_7/fs_control
var GRP = fs_2_data.decode_u8(0x0)
@@ -287,14 +308,90 @@ func _on_emsg_select() -> void:
func _on_mfs_select() -> void:
set_tab_and_buttons(3, 'select_fs')
func _on_save_config():
print('Тебе сюда')
var da = DirAccess.open(save_path)
var base_path = save_path + "save//"
if da == null:
return
else:
da.dir_exists(base_path)
da.make_dir_recursive(base_path)
var file_dialog = FileDialog.new()
file_dialog.title = "Сохранить файл как"
file_dialog.set_size(Vector2(600, 400))
file_dialog.mode = FileDialog.FILE_MODE_SAVE_FILE
file_dialog.current_dir = base_path
file_dialog.set_current_file("ЭМС-Г" + "-" + status_pribor)
file_dialog.connect("file_selected", Callable(self, "_save_selected_file"))
add_child(file_dialog)
file_dialog.popup_centered()
func _save_selected_file(file_path: String):
var data = Constants.EMS_G_PORT_DATA_HOLDER
var param_ems_g: Dictionary = {}
var other_data: Dictionary = {}
# Формируем словари
for item in data:
var regist: Dictionary = {}
regist[0x122] = item[0]
for key in item[1]:
if key in need_port:
regist[key] = item[1][key]
else:
other_data[key] = item[1]
param_ems_g[item[0]] = regist
var item_id = item[0]
# Переменные для сохранения
var ems_g_file = file_path
var ems_g_path = save_path + ems_g_file
var other_name = "others" + "-" + status_pribor
var other_path = save_path + other_name
var other_names = other_name
var other_counter = 1
var dir = DirAccess.open(file_path.get_base_dir())
# Сохранение данных ЭМС-Г
var file = FileAccess.open(ems_g_file, FileAccess.WRITE)
if file != null:
file.store_string(JSON.stringify(param_ems_g))
file.close()
# Сохранение данных других
var save_other = $save_other.is_pressed()
if save_other:
while dir.file_exists(other_names):
other_names = other_name + "_" + str(other_counter)
other_path = save_path + other_names
other_counter += 1
var other_file = FileAccess.open(other_path, FileAccess.WRITE)
if other_file != null:
other_file.store_string(JSON.stringify(other_data))
other_file.close()
func _on_file_selected(file_path: String):
var file = FileAccess.open(file_path, FileAccess.READ)
# Проверка на открытие/чтение файла
if file != OK:
return
var file_content = file.get_as_text()
file.close()
var json = JSON.new()
var data = json.parse(file_content)
# Проверка на разбор содержимого файла
if data.error != OK:
return
Constants.EMS_G_PORT_DATA_HOLDER = data.result
func _on_load_config():
print('тебе сюда')
var file_dialog = FileDialog.new()
var base_path = save_path + "save//"
file_dialog.set_title("Выберите файл")
file_dialog.set_size(Vector2(600, 400))
file_dialog.access = FileDialog.ACCESS_FILESYSTEM
file_dialog.current_dir = base_path
add_child(file_dialog)
file_dialog.popup_centered()
func set_tab_and_buttons(tab_index: int, button_name: String) -> void: