Рефактор.
This commit is contained in:
@@ -4,10 +4,10 @@ extends "res://scenes/контроль/прибор.gd"
|
||||
static var json_parser: JSON = JSON.new()
|
||||
|
||||
|
||||
func get_paths(meta: String, paths: Array):
|
||||
func get_paths_from_meta(meta: String, paths: Array, tokens: Array = ['[', ']', '.']):
|
||||
paths.clear()
|
||||
var i_chs = []
|
||||
for sep in ['[', ']', '.']:
|
||||
for sep in tokens:
|
||||
var i = 0
|
||||
while i != -1:
|
||||
i = meta.find(sep, i + 1)
|
||||
@@ -52,9 +52,9 @@ func _on_request_rtr_request_completed(result, _response_code, _headers, body: P
|
||||
map_data_to_item(json_parser.data, child, 'value0')
|
||||
map_data_to_item(json_parser.data, child, 'value1')
|
||||
for child in get_children():
|
||||
map_data_to_item(json_parser.data, child, 'state')
|
||||
map_data_to_item(json_parser.data, child, 'value0')
|
||||
map_data_to_item(json_parser.data, child, 'value1')
|
||||
map_data_to_item(json_parser.data, child, 'value2')
|
||||
|
||||
|
||||
func map_data_to_item(data, item, value_name: StringName):
|
||||
@@ -64,7 +64,7 @@ func map_data_to_item(data, item, value_name: StringName):
|
||||
if meta == '':
|
||||
return
|
||||
var paths: = Array()
|
||||
get_paths(meta, paths)
|
||||
get_paths_from_meta(meta, paths)
|
||||
var ret_val: = [null, false]
|
||||
var paths_copy = paths.duplicate(true)
|
||||
tools.get_value_by_path(data, paths, ret_val)
|
||||
|
||||
@@ -2,20 +2,20 @@ extends HTTPRequest
|
||||
|
||||
|
||||
const RESULT_STRINGS = {
|
||||
RESULT_SUCCESS: 'Request successful',
|
||||
RESULT_CHUNKED_BODY_SIZE_MISMATCH: 'CHUNKED_BODY_SIZE_MISMATCH',
|
||||
RESULT_CANT_CONNECT: 'Request failed while connecting',
|
||||
RESULT_CANT_RESOLVE: 'Request failed while resolving',
|
||||
RESULT_CONNECTION_ERROR: 'Request failed due to connection (read/write) error',
|
||||
RESULT_TLS_HANDSHAKE_ERROR: 'Request failed on TLS handshake',
|
||||
RESULT_NO_RESPONSE: 'Request does not have a response (yet)',
|
||||
RESULT_BODY_SIZE_LIMIT_EXCEEDED: 'Request exceeded its maximum size limit, see body_size_limit',
|
||||
RESULT_BODY_DECOMPRESS_FAILED: 'BODY_DECOMPRESS_FAILED',
|
||||
RESULT_REQUEST_FAILED: 'Request failed (currently unused)',
|
||||
RESULT_DOWNLOAD_FILE_CANT_OPEN: 'HTTPRequest couldn\'t open the download file',
|
||||
RESULT_DOWNLOAD_FILE_WRITE_ERROR: 'HTTPRequest couldn\'t write to the download file',
|
||||
RESULT_REDIRECT_LIMIT_REACHED: 'Request reached its maximum redirect limit, see max_redirects',
|
||||
RESULT_TIMEOUT: 'TIMEOUT' }
|
||||
RESULT_SUCCESS: 'Request successful',
|
||||
RESULT_CHUNKED_BODY_SIZE_MISMATCH: 'Chunked body size mismatch',
|
||||
RESULT_CANT_CONNECT: 'Request failed while connecting',
|
||||
RESULT_CANT_RESOLVE: 'Request failed while resolving',
|
||||
RESULT_CONNECTION_ERROR: 'Request failed due to connection (read/write) error',
|
||||
RESULT_TLS_HANDSHAKE_ERROR: 'Request failed on TLS handshake',
|
||||
RESULT_NO_RESPONSE: 'Request does not have a response (yet)',
|
||||
RESULT_BODY_SIZE_LIMIT_EXCEEDED: 'Request exceeded its maximum size limit, see body_size_limit',
|
||||
RESULT_BODY_DECOMPRESS_FAILED: 'Body decompress failed',
|
||||
RESULT_REQUEST_FAILED: 'Request failed (currently unused)',
|
||||
RESULT_DOWNLOAD_FILE_CANT_OPEN: 'HTTPRequest couldn\'t open the download file',
|
||||
RESULT_DOWNLOAD_FILE_WRITE_ERROR: 'HTTPRequest couldn\'t write to the download file',
|
||||
RESULT_REDIRECT_LIMIT_REACHED: 'Request reached its maximum redirect limit, see max_redirects',
|
||||
RESULT_TIMEOUT: 'Timeout' }
|
||||
|
||||
|
||||
var i_bort: int = 0
|
||||
@@ -28,7 +28,6 @@ func get_result_string(result: Result):
|
||||
return RESULT_STRINGS[result] if RESULT_STRINGS.has(result) else '<неизвестный код результата HTTPRequest - %d>' % result
|
||||
|
||||
|
||||
|
||||
func _ready():
|
||||
addr_left = ProjectSettings.get_setting('application/config/unit_rr_left_bort')
|
||||
addr_right = ProjectSettings.get_setting('application/config/unit_rr_right_bort')
|
||||
|
||||
Reference in New Issue
Block a user