class_name BugbotServerAPI extends Resource enum BugbotServerError { OK, THREAD_NULL, THREAD_BUSY, API_RESPONSE_ERROR } enum BugbotTagArray { VERSION, HARDWARE, OS, COMPONENT, SEVERITY, MAX } const DEFAULT_SHOW_UNRESOLVED_BUGS : bool = true const DEFAULT_SHOW_IN_PROGRESS_BUGS : bool = true const DEFAULT_SHOW_RESOLVED_BUGS : bool = false const UNRESOLVED_TAG : StringName = &"UNRESOLVED" const IN_PROGRESS_TAG : StringName = &"IN_PROGRESS" const RESOLVED_TAG : StringName = &"RESOLVED" var __bugbot_server_thread : Thread func _init(): __bugbot_server_thread = Thread.new() func _return_list_of_bugs(map_name:String, callback:Callable) -> int: return __start_thread_with_callback(__return_list_of_bugs_thread.bind(map_name, callback)) func _prepare_form(callback:Callable) -> int: return __start_thread_with_callback(__prepare_form_thread.bind(callback)) func _send_form_data(data:Dictionary, map_name:String, bug_position:Vector3, bug_normal:Vector3, callback:Callable) -> int: return __start_thread_with_callback(__send_form_data_thread.bind(data, map_name, bug_position, bug_normal, callback)) static func _create_new_server_api() -> BugbotServerAPI: match ProjectSettings.get_setting("bugbot/reporting/bug_report_platform", BugReportPlatform.BUGZILLA): BugReportPlatform.BUGZILLA: return BugbotServerBugzillaAPI.new() BugReportPlatform.GITEA: return BugbotServerGiteaAPI.new() BugReportPlatform.JIRA: return BugbotServerJiraAPI.new() return BugbotServerAPI.new() func __connect_to_server(http_client:HTTPClient, server:String) -> int: var server_and_port : PackedStringArray = server.rsplit(":",true,1) var server_domain : String = server_and_port[0] var port : int = int(server_and_port[1]) http_client.connect_to_host(server_domain if port > 0 else server, port if port > 0 else -1) while http_client.get_status() == HTTPClient.STATUS_CONNECTING or http_client.get_status() == HTTPClient.STATUS_RESOLVING: http_client.poll() return http_client.get_status() func __get_http_client_chunk_response(http_client:HTTPClient) -> String: if http_client.has_response(): var response_body : PackedByteArray = PackedByteArray() while http_client.get_status() == HTTPClient.STATUS_BODY: http_client.poll() var chunk : PackedByteArray = http_client.read_response_body_chunk() if chunk.size() > 0: response_body += chunk return response_body.get_string_from_utf8() return "" func __start_thread_with_callback(thread_function:Callable) -> int: if not __bugbot_server_thread: printerr("Server thread is null.") return BugbotServerError.THREAD_NULL if __bugbot_server_thread.is_started(): printerr("Server thread is currently busy.") return BugbotServerError.THREAD_BUSY; __bugbot_server_thread = Thread.new() __bugbot_server_thread.start(thread_function) return BugbotServerError.OK func __validate_server_response(_response:Variant) -> int: return Error.OK func _current_server_api() -> String: return "" func _get_project_name() -> String: return "" func __build_url_string(_api_suffix:String) -> String: return "" func __create_header_data(content_length:int = -1) -> Array: return [] func __return_list_of_bugs_thread(map_name:String, callback:Callable) -> void: print("Insert list of ", _current_server_api(), " bugs here.") callback.call_deferred([]) __bugbot_server_thread.call_deferred("wait_to_finish") func __prepare_form_thread(callback:Callable) -> void: print("Prepare ", _current_server_api(), " form here.") callback.call_deferred([]) __bugbot_server_thread.call_deferred("wait_to_finish") func __send_form_data_thread(data:Dictionary, map_name:String, bug_position:Vector3, bug_normal:Vector3, callback:Callable) -> void: print("Send ", _current_server_api(), " form data here.") callback.call_deferred([]) __bugbot_server_thread.call_deferred("wait_to_finish")