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

49 lines
1.6 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_rtr 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')
const bort_to_node_name = {
'Устройство РР левого борта': 'grid_bpo_a1',
'Устройство РР правого борта': 'grid_bpo_a2'}
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
if not bort_to_node_name.has(ret_val[0]):
return
var node_name = bort_to_node_name[ret_val[0]]
var bort_node = get_node(node_name)
for item in bort_node.get_children():
node_maper.map_value_to_item(json_conv.data, item, 'state')