chore: automatic lint

master
Dominique Merle 4 years ago
parent a19261edd7
commit 615bd2275b

@ -28,7 +28,7 @@ func methods() -> PoolStringArray:
return output
func setup(assertions, yielder, testcase, director,
signal_watcher, parameters, recorder):
signal_watcher, parameters, recorder):
asserts = assertions
direct = director
_testcase = testcase

@ -29,112 +29,112 @@ var __log := false
# public
func set_logging(state: bool) -> void:
__log = state
__log = state
func connect_to_host(host: String, port: int) -> bool:
_host = host
_port = port
_host = host
_port = port
__websocket_client.set_verify_ssl_enabled(false)
__websocket_client.set_verify_ssl_enabled(false)
var result: int = __websocket_client.connect_to_url(str(_host, ':', _port))
var result: int = __websocket_client.connect_to_url(str(_host, ':', _port))
__websocket_peer = __websocket_client.get_peer(1)
__websocket_peer.set_write_mode(WebSocketPeer.WRITE_MODE_TEXT)
__websocket_peer = __websocket_client.get_peer(1)
__websocket_peer.set_write_mode(WebSocketPeer.WRITE_MODE_TEXT)
set_process(true)
set_process(true)
return result == OK
return result == OK
func send_command(command: String) -> void:
command_queue.append(command)
command_queue.append(command)
# private
func _log(text: String) -> void:
if __log:
prints('[%s] %s' % [__get_time_str(), text])
if __log:
prints('[%s] %s' % [__get_time_str(), text])
func __get_time_str() -> String:
var time = OS.get_time()
return str(time.hour, ':', time.minute, ':', time.second)
var time = OS.get_time()
return str(time.hour, ':', time.minute, ':', time.second)
func __send_command(command: String) -> int:
var result: int = __websocket_peer.put_packet(command.to_utf8())
var result: int = __websocket_peer.put_packet(command.to_utf8())
return result
return result
func __process_commands() -> void:
var next_command_time: bool = __time_passed - __last_command_time >= COMMAND_WAIT_TIMEOUT
var next_command_time: bool = __time_passed - __last_command_time >= COMMAND_WAIT_TIMEOUT
if command_queue.empty() or not next_command_time:
return
if command_queue.empty() or not next_command_time:
return
__send_command(command_queue.pop_front() as String)
__send_command(command_queue.pop_front() as String)
__last_command_time = __time_passed
__last_command_time = __time_passed
func __process_incoming_data() -> void:
var available_packets_count := __websocket_peer.get_available_packet_count()
var available_packets_count := __websocket_peer.get_available_packet_count()
var received_string: String = ''
while available_packets_count > 0:
var packet = __websocket_peer.get_packet()
received_string += packet.get_string_from_utf8()
var received_string: String = ''
while available_packets_count > 0:
var packet = __websocket_peer.get_packet()
received_string += packet.get_string_from_utf8()
available_packets_count -= 1
available_packets_count -= 1
if received_string:
_log('>> %s' % received_string)
if received_string:
_log('>> %s' % received_string)
emit_signal('response_received', received_string)
emit_signal('response_received', received_string)
func __parse_server_message(data):
pass
pass
func __initialize_http_request_queue() -> void:
http_request_queue = HttpRequestQueue.new()
add_child(http_request_queue)
http_request_queue = HttpRequestQueue.new()
add_child(http_request_queue)
# hooks
func _ready() -> void:
set_process(false)
set_process(false)
__initialize_http_request_queue()
__initialize_http_request_queue()
func _process(delta: float) -> void:
__time_passed += delta
__time_passed += delta
if __websocket_client.get_connection_status() != connection_status:
connection_status = __websocket_client.get_connection_status()
if __websocket_client.get_connection_status() != connection_status:
connection_status = __websocket_client.get_connection_status()
if connection_status == WebSocketClient.CONNECTION_CONNECTING:
_log('Connecting to server...')
if connection_status == WebSocketClient.CONNECTION_CONNECTING:
_log('Connecting to server...')
if connection_status == WebSocketClient.CONNECTION_CONNECTED:
_log('Connected.')
if connection_status == WebSocketClient.CONNECTION_CONNECTED:
_log('Connected.')
if connection_status == WebSocketClient.CONNECTION_DISCONNECTED:
_log('Disconnected.')
if connection_status == WebSocketClient.CONNECTION_DISCONNECTED:
_log('Disconnected.')
var is_connecting: bool = connection_status == WebSocketClient.CONNECTION_CONNECTING
var is_connected: bool = connection_status == WebSocketClient.CONNECTION_CONNECTED
var is_connecting: bool = connection_status == WebSocketClient.CONNECTION_CONNECTING
var is_connected: bool = connection_status == WebSocketClient.CONNECTION_CONNECTED
if is_connecting or is_connected:
__websocket_client.poll()
if is_connecting or is_connected:
__websocket_client.poll()
var is_peer_connected: bool = __websocket_peer.is_connected_to_host()
var is_peer_connected: bool = __websocket_peer.is_connected_to_host()
if is_peer_connected and __time_passed > CONNECT_WAIT_TIMEOUT:
__process_commands()
if is_peer_connected and __time_passed > CONNECT_WAIT_TIMEOUT:
__process_commands()
__process_incoming_data()
__process_incoming_data()
# events
func _on_http_response_received(content_type: String, data: PoolByteArray) -> void:
emit_signal("http_response_received", content_type, data)
emit_signal("http_response_received", content_type, data)
func _on_http_response_failed(error_code: int) -> void:
emit_signal("http_response_failed", error_code)
emit_signal("http_response_failed", error_code)

Loading…
Cancel
Save