Compare commits
2 Commits
ec21282ba0
...
6294730bf8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6294730bf8 | ||
|
|
f407578a44 |
@@ -26,8 +26,6 @@ func _ready() -> void:
|
||||
|
||||
# Обработка полученного ответа от rtr
|
||||
func _on_response_received(response: String, success: bool) -> void:
|
||||
var unit_instance = network.get_unit_instance(unit_name)
|
||||
|
||||
if not success:
|
||||
log.error('Ошибка запроса или нет связи: %s' % response)
|
||||
_reset_ui_to_zero()
|
||||
@@ -68,28 +66,28 @@ func _on_response_received(response: String, success: bool) -> void:
|
||||
func _update_ui(json_data: Dictionary) -> void:
|
||||
# Конвертер
|
||||
for child in $bort.get_node('konverter/grid').get_children():
|
||||
node_maper.map_value_to_item(json_data, child, 'value0')
|
||||
node_maper.map_value_to_item(json_data, child, 'value1')
|
||||
node_maper.map_value_to_item(json_data, child, 'value2')
|
||||
node_maper.map_error_codes_to_item(json_data, child, 'state', 0)
|
||||
node_maper.map_value_to_item_animated(json_data, child, 'value0')
|
||||
node_maper.map_value_to_item_animated(json_data, child, 'value1')
|
||||
node_maper.map_value_to_item_animated(json_data, child, 'value2')
|
||||
node_maper.map_error_codes_to_item_animated(json_data, child, 'state', 0)
|
||||
|
||||
# Антенна 1
|
||||
for child in $bort.get_node('antenna1/grid').get_children():
|
||||
node_maper.map_value_to_item(json_data, child, 'value0')
|
||||
node_maper.map_value_to_item(json_data, child, 'value1')
|
||||
node_maper.map_error_codes_to_item(json_data, child, 'state', 0)
|
||||
node_maper.map_value_to_item_animated(json_data, child, 'value0')
|
||||
node_maper.map_value_to_item_animated(json_data, child, 'value1')
|
||||
node_maper.map_error_codes_to_item_animated(json_data, child, 'state', 0)
|
||||
|
||||
# Антенна 2
|
||||
for child in $bort.get_node('antenna2/grid').get_children():
|
||||
node_maper.map_value_to_item(json_data, child, 'value0')
|
||||
node_maper.map_value_to_item(json_data, child, 'value1')
|
||||
node_maper.map_error_codes_to_item(json_data, child, 'state', 0)
|
||||
node_maper.map_value_to_item_animated(json_data, child, 'value0')
|
||||
node_maper.map_value_to_item_animated(json_data, child, 'value1')
|
||||
node_maper.map_error_codes_to_item_animated(json_data, child, 'state', 0)
|
||||
|
||||
# Остальные элементы
|
||||
for child in $bort.get_children():
|
||||
node_maper.map_value_to_item(json_data, child, 'value0')
|
||||
node_maper.map_value_to_item(json_data, child, 'value1')
|
||||
node_maper.map_error_codes_to_item(json_data, child, 'state', 0)
|
||||
node_maper.map_value_to_item_animated(json_data, child, 'value0')
|
||||
node_maper.map_value_to_item_animated(json_data, child, 'value1')
|
||||
node_maper.map_error_codes_to_item_animated(json_data, child, 'state', 0)
|
||||
|
||||
|
||||
# Сброс всех UI элементов в 0 (при отсутствии данных)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
extends Node
|
||||
|
||||
|
||||
static func map_value_to_item(data, item, value_name: StringName):
|
||||
var meta = item.get_meta(value_name, '')
|
||||
if meta == '':
|
||||
@@ -17,7 +16,6 @@ static func map_value_to_item(data, item, value_name: StringName):
|
||||
else:
|
||||
push_error('не найден путь %s (%s) для $%s.%s (%s)' % [paths_copy, ret_val[2], item.name, value_name, item.tooltip_text])
|
||||
|
||||
|
||||
static func map_error_codes_to_item(data, item, value_name: StringName, value_init: int):
|
||||
var metas = item.get_meta(value_name, '')
|
||||
if not (metas is Array):
|
||||
@@ -38,3 +36,54 @@ static func map_error_codes_to_item(data, item, value_name: StringName, value_in
|
||||
item.set(value_name, test_res)
|
||||
else:
|
||||
item.set(value_name, value_init)
|
||||
|
||||
# Плавное обновление с анимацией
|
||||
static func map_value_to_item_animated(data, item, value_name: StringName):
|
||||
var meta = item.get_meta(value_name, '')
|
||||
if meta == '' or not (meta is String):
|
||||
return
|
||||
|
||||
var paths: = Array()
|
||||
tools.map_solid_to_array(meta, paths)
|
||||
var ret_val: = [null, false, 0]
|
||||
tools.get_value_by_path(data, paths, ret_val)
|
||||
|
||||
if ret_val[1]:
|
||||
_animate_property(item, value_name, ret_val[0])
|
||||
else:
|
||||
push_error('не найден путь для $%s.%s' % [item.name, value_name])
|
||||
|
||||
static func map_error_codes_to_item_animated(data, item, value_name: StringName, value_init: int):
|
||||
var metas = item.get_meta(value_name, '')
|
||||
if not (metas is Array):
|
||||
return
|
||||
|
||||
var paths: = Array()
|
||||
var values: = Array()
|
||||
for meta in metas:
|
||||
tools.map_solid_to_array(meta, paths)
|
||||
var ret_val: = [null, false, 0]
|
||||
tools.get_value_by_path(data, paths, ret_val)
|
||||
if ret_val[1]:
|
||||
values.append(ret_val[0])
|
||||
else:
|
||||
push_error('не найден путь для $%s.%s' % [item.name, value_name])
|
||||
|
||||
var target_value: int
|
||||
if values.size() == metas.size():
|
||||
target_value = 1 if values.count(true) == values.size() else 2
|
||||
else:
|
||||
target_value = value_init
|
||||
|
||||
_animate_property(item, value_name, target_value)
|
||||
|
||||
static func _animate_property(item, property: StringName, target_value):
|
||||
var current = item.get(property)
|
||||
if current == target_value:
|
||||
return
|
||||
|
||||
# Исправление: преобразуем StringName в String для NodePath
|
||||
var tween = item.create_tween()
|
||||
tween.set_trans(Tween.TRANS_QUINT)
|
||||
tween.set_ease(Tween.EASE_OUT)
|
||||
tween.tween_property(item, NodePath(String(property)), target_value, 0.3)
|
||||
|
||||
@@ -175,6 +175,7 @@ func _on_request_completed(result: int, response_code: int, _headers: PackedStri
|
||||
_on_request_finished()
|
||||
else:
|
||||
var error_msg = 'HTTP ошибка %d: %s' % [response_code, get_result_string(result)]
|
||||
print_debug(error_msg)
|
||||
_save_error(error_msg)
|
||||
|
||||
# Обновляем статус online (ошибка)
|
||||
|
||||
Reference in New Issue
Block a user