Files
uarep-ctl/scenes/pribor-afsp/pribor-afsp.gd

67 lines
2.8 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@tool
class_name pribor_afsp extends 'res://scenes/контроль/прибор.gd'
@export var prefix_path: String = 'DeviceDescripton[DeviceName]'
static var json_conv: JSON = JSON.new()
static var node_maper = load('res://scenes/контроль/node-maper.gd')
func _on_request_completed(result, _response_code, headers, body: PackedByteArray):
if result != 0:
var rs = $request.get_result_string(result)
log.error('\"%s\"' % rs)
return
var json_str: String = body.get_string_from_utf8()
if not json_str:
push_error('не удаётся получить строку utf8 из данных (%s)' % headers)
return
var rc = json_conv.parse(json_str)
if rc != Error.OK:
var err = json_conv.get_error_message()
push_error('разбор json прерван - \"%s\" (%s)' % [err, headers])
return
var pp = []
tools.map_solid_to_array(prefix_path, pp)
var ret_val = [null, false, 0]
var pp_copy = pp.duplicate(true)
tools.get_value_by_path(json_conv.data, pp, ret_val)
if not ret_val[1]:
push_error('путь %s не найден (%s)' % [pp_copy, ret_val[2]])
return
var this_afsp_name: StringName = $bort.get_meta('DeviceName', '')
var received_afsp_name: StringName = ret_val[0]
if this_afsp_name != received_afsp_name:
return
for child in $bort.get_node('konverter/grid').get_children():
node_maper.map_value_to_item(json_conv.data, child, 'value0')
node_maper.map_value_to_item(json_conv.data, child, 'value1')
node_maper.map_value_to_item(json_conv.data, child, 'value2')
node_maper.map_error_codes_to_item(json_conv.data, child, 'state', 0)
for child in $bort.get_node('antenna1/grid').get_children():
node_maper.map_value_to_item(json_conv.data, child, 'value0')
node_maper.map_value_to_item(json_conv.data, child, 'value1')
node_maper.map_error_codes_to_item(json_conv.data, child, 'state', 0)
for child in $bort.get_node('antenna2/grid').get_children():
node_maper.map_value_to_item(json_conv.data, child, 'value0')
node_maper.map_value_to_item(json_conv.data, child, 'value1')
node_maper.map_error_codes_to_item(json_conv.data, child, 'state', 0)
for child in $bort.get_children():
node_maper.map_value_to_item(json_conv.data, child, 'value0')
node_maper.map_value_to_item(json_conv.data, child, 'value1')
node_maper.map_error_codes_to_item(json_conv.data, child, 'state', 0)
## Вызывается при клике мыши на элементе.
## [param block_a] - Кликнутый элемент.
func _on_item_pressed(block_a: Control):
var metas = block_a.get_meta_list()
for n in metas:
var v = block_a.get_meta(n)
print_debug('%s:%s' % [n, v])