Реализация сохранения/загрузки файлов

This commit is contained in:
lepshiy
2025-02-04 15:38:16 +03:00
parent 35196b731f
commit b361b692c6
7 changed files with 132 additions and 16 deletions

View File

@@ -10,9 +10,28 @@ 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//save//"
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
print("путь сохранения: ", save_path)
# Таблица УКП_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())
@@ -31,15 +50,20 @@ func _ready() -> void:
var node_select_device = $TabContainer/PRD/select_dev
draw_tabl(node_select_device, Constants.SELECT_DEVICE, Constants.SELECT_DEVICE.size())
var get_select_device = node_select_device.get_node2(1, 0)
get_select_device.connect('item_selected', Callable(self, 'on_device_selected'))
# Заполнение адресов
for i_addr in Constants.ADDRESSES.size():
get_select_device.add_item(Constants.ADDRESSES[i_addr][0])
get_select_device.set_item_metadata(i_addr, Constants.ADDRESSES[i_addr].slice(1,7))
get_select_device.set_item_metadata(i_addr, Constants.ADDRESSES[i_addr].slice(1, 7))
get_select_device.connect('item_selected', Callable(self, 'on_btn_select'))
node_select_device.get_node2(0,0).text = 'ПРИБОР'
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.RAY_DICT:
$TabContainer/PRD/body_grid/litera_2_4_6/yau_07b/Ray_set_1.add_item(key)
@@ -57,6 +81,11 @@ func _ready() -> void:
Network.connect('yau_read_isa', Callable(self, '_on_read_isa'))
func on_device_selected(selected_index: int) -> void:
var get_select_device = $TabContainer/PRD/select_dev.get_node2(1, 0)
status_pribor = get_select_device.get_item_text(selected_index).strip_edges().substr(4)
func draw_control_panel_prd(mode) -> void:
for node_path in Constants.NODE_MAP:
var index = Constants.NODE_MAP[node_path]
@@ -95,7 +124,6 @@ func _on_read_isa(unit_isa_ports: Dictionary) -> void:
if len(Constants.EMS_G_PORT_DATA_HOLDER) == 32:
emit_signal('read_ems_g_finish')
$ISA.text = 'ISA: ' + str(len(Constants.EMS_G_PORT_DATA_HOLDER))
if isa_data.has(Constants.BASE_PORTS.UG+6):
$TabContainer/PRD/body_grid/litera_2_4_6/PSK/ray_1.material.set('shader_parameter/turn', 0.735 + 0.025 * (isa_data[0x106] & 0x7))
if isa_data.has(Constants.BASE_PORTS.UG+8):
@@ -166,12 +194,81 @@ func _on_mfs_select() -> void:
func _on_save_config():
print('Тебе сюда')
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 = save_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()
file_dialog.set_title("Выберите файл")
file_dialog.set_size(Vector2(600, 400))
file_dialog.current_dir = save_path
file_dialog.access = FileDialog.ACCESS_FILESYSTEM
add_child(file_dialog)
file_dialog.popup_centered()
func set_tab_and_buttons(tab_index: int, button_name: String) -> void:
@@ -190,7 +287,7 @@ func on_btn_select(intem_from_sector: int) -> void:
Network.on_command_change_device(meta)
flag_mode = meta[2]
draw_control_panel_prd(flag_mode)
status_pribor = get_select_device.get_item_text(intem_from_sector).strip_edges().substr(4)
func fill_item(node: Node, i_column: int, i_row: int, arr: Dictionary, select: int = 0) -> void:
var optionbutton = node.get_node2(i_column, i_row) as OptionButton

View File

@@ -9,11 +9,11 @@ func _on_read_ems_g():
Constants.EMS_G_PORT_DATA_HOLDER.clear()
for i_input in 16:
Network.write_port_isa(Constants.BASE_PORTS.EMS_G+2, 1+i_input)
Network.read_port_isa([Constants.BASE_PORTS.EMS_G+0xA])
Network.read_port_isa([Constants.BASE_PORTS.EMS_G+2, Constants.BASE_PORTS.EMS_G+4, Constants.BASE_PORTS.EMS_G+6, Constants.BASE_PORTS.EMS_G+8,Constants.BASE_PORTS.EMS_G+0xA])
for i_output in range(46, 62):
Network.write_port_isa(Constants.BASE_PORTS.EMS_G+2, 1+i_output)
Network.read_port_isa([Constants.BASE_PORTS.EMS_G+4, Constants.BASE_PORTS.EMS_G+8])
Network.read_port_isa([Constants.BASE_PORTS.EMS_G+2, Constants.BASE_PORTS.EMS_G+4, Constants.BASE_PORTS.EMS_G+6, Constants.BASE_PORTS.EMS_G+8,Constants.BASE_PORTS.EMS_G+0xA])
func _on_sync():