From 24128608eb615d879a3827cef53d71112f47390c Mon Sep 17 00:00:00 2001 From: Divided by Zer0 Date: Tue, 17 Oct 2023 20:16:28 +0200 Subject: [PATCH] removed globals from the addon (#114) --- StableHordeClient.tscn => LucidCreations.tscn | 2 +- StableHordeClient.gd | 2 ++ addons/stable_horde_client/AIImageTexture.gd | 2 ++ addons/stable_horde_client/stable_horde_client.gd | 12 ++++++------ .../stable_horde_client/stable_horde_httpclient.gd | 2 ++ addons/stable_horde_client/stable_horde_login.gd | 5 ++--- addons/stable_horde_client/stable_horde_models.gd | 2 +- .../stable_horde_rate_generation.gd | 5 ++--- project.godot | 4 ++-- src/ParamBus.gd | 1 - 10 files changed, 20 insertions(+), 17 deletions(-) rename StableHordeClient.tscn => LucidCreations.tscn (99%) diff --git a/StableHordeClient.tscn b/LucidCreations.tscn similarity index 99% rename from StableHordeClient.tscn rename to LucidCreations.tscn index eb26335..895140e 100644 --- a/StableHordeClient.tscn +++ b/LucidCreations.tscn @@ -1357,7 +1357,7 @@ margin_bottom = 20.0 [node name="Title" type="Label" parent="Margin/Panel/Display/Panels/Controls/Information/HBC"] margin_right = 130.0 margin_bottom = 20.0 -text = "Stable Horde Client" +text = "Lucid Creations" [node name="Version" type="Label" parent="Margin/Panel/Display/Panels/Controls/Information/HBC"] margin_left = 134.0 diff --git a/StableHordeClient.gd b/StableHordeClient.gd index 8c3673a..137fc2a 100644 --- a/StableHordeClient.gd +++ b/StableHordeClient.gd @@ -103,6 +103,8 @@ func _ready(): select_image.connect("image_selected",self,"_on_source_image_selected") # warning-ignore:return_value_discarded EventBus.connect("kudos_calculated",self, "_on_kudos_calculated") + stable_horde_client.client_agent = "Lucid Creations:" + ToolConsts.VERSION + ":(discord)db0#1625" + stable_horde_client.aihorde_url = globals.aihorde_url _connect_hover_signals() save.connect("pressed", self, "_on_save_pressed") diff --git a/addons/stable_horde_client/AIImageTexture.gd b/addons/stable_horde_client/AIImageTexture.gd index c312587..6def5c1 100644 --- a/addons/stable_horde_client/AIImageTexture.gd +++ b/addons/stable_horde_client/AIImageTexture.gd @@ -146,7 +146,9 @@ static func sanitize_filename(filename: String) -> String: '(', ')', ' ', + '\n', ] for c in replace_chars: filename = filename.replace(c,'_') + print_debug(filename) return(filename) diff --git a/addons/stable_horde_client/stable_horde_client.gd b/addons/stable_horde_client/stable_horde_client.gd index 235e3f4..485e111 100644 --- a/addons/stable_horde_client/stable_horde_client.gd +++ b/addons/stable_horde_client/stable_horde_client.gd @@ -163,9 +163,9 @@ func generate(replacement_prompt := '', replacement_params := {}) -> void: var headers = [ "Content-Type: application/json", "apikey: " + api_key, - "Client-Agent: " + "Lucid Creations:" + ToolConsts.VERSION + ":db0#1625", + "Client-Agent: " + client_agent, ] - var error = request(globals.aihorde_url + "/api/v2/generate/async", headers, false, HTTPClient.METHOD_POST, body) + var error = request(aihorde_url + "/api/v2/generate/async", headers, false, HTTPClient.METHOD_POST, body) if error != OK: var error_msg := "Something went wrong when initiating the stable horde request" push_error(error_msg) @@ -206,17 +206,17 @@ func process_request(json_ret) -> void: func check_request_process(operation := OngoingRequestOperations.CHECK) -> void: # We do one check request per second yield(get_tree().create_timer(1), "timeout") - var url = globals.aihorde_url + "/api/v2/generate/check/" + async_request_id + var url = aihorde_url + "/api/v2/generate/check/" + async_request_id var method = HTTPClient.METHOD_GET if operation == OngoingRequestOperations.GET: - url = globals.aihorde_url + "/api/v2/generate/status/" + async_request_id + url = aihorde_url + "/api/v2/generate/status/" + async_request_id elif operation == OngoingRequestOperations.CANCEL: - url = globals.aihorde_url + "/api/v2/generate/status/" + async_request_id + url = aihorde_url + "/api/v2/generate/status/" + async_request_id method = HTTPClient.METHOD_DELETE delete_sent = true var error = request( url, - ["Client-Agent: " + "Lucid Creations:" + ToolConsts.VERSION + ":db0#1625"], + ["Client-Agent: " + client_agent], false, method) if state == States.WORKING and error != OK: diff --git a/addons/stable_horde_client/stable_horde_httpclient.gd b/addons/stable_horde_client/stable_horde_httpclient.gd index 96090bb..20b2a43 100644 --- a/addons/stable_horde_client/stable_horde_httpclient.gd +++ b/addons/stable_horde_client/stable_horde_httpclient.gd @@ -11,6 +11,8 @@ enum States { CANCELLING } # When set to true, we will abort the current generation and try to retrieve whatever images we can +export(String) var aihorde_url = "https://aihorde.net" +export(String) var client_agent = "AI Horde Godot Addon:2.7.0:db0#1625" var state : int = States.READY var service_name :String = "AI Horde" diff --git a/addons/stable_horde_client/stable_horde_login.gd b/addons/stable_horde_client/stable_horde_login.gd index 69059f8..7a6c05e 100644 --- a/addons/stable_horde_client/stable_horde_login.gd +++ b/addons/stable_horde_client/stable_horde_login.gd @@ -2,7 +2,6 @@ class_name StableHordeLogin extends StableHordeHTTPRequest signal login_successful(user_details) - var user_details: Dictionary export(String) var api_key := '0000000000' @@ -15,9 +14,9 @@ func login() -> void: state = States.WORKING var headers = [ "Content-Type: application/json", "apikey: " + api_key, - "Client-Agent: " + "Lucid Creations:" + ToolConsts.VERSION + ":db0#1625" + "Client-Agent: " + client_agent ] - var error = request(globals.aihorde_url + "/api/v2/find_user", headers, false, HTTPClient.METHOD_GET) + var error = request(aihorde_url + "/api/v2/find_user", headers, false, HTTPClient.METHOD_GET) if error != OK: var error_msg := "Something went wrong when initiating the stable horde request" push_error(error_msg) diff --git a/addons/stable_horde_client/stable_horde_models.gd b/addons/stable_horde_client/stable_horde_models.gd index ffde014..ca69b49 100644 --- a/addons/stable_horde_client/stable_horde_models.gd +++ b/addons/stable_horde_client/stable_horde_models.gd @@ -20,7 +20,7 @@ func get_models() -> void: print_debug("Models currently working. Cannot do more than 1 request at a time with the same Stable Horde Models.") return state = States.WORKING - var error = request(globals.aihorde_url + "/api/v2/status/models", [], false, HTTPClient.METHOD_GET) + var error = request(aihorde_url + "/api/v2/status/models", [], false, HTTPClient.METHOD_GET) if error != OK: var error_msg := "Something went wrong when initiating the stable horde request" push_error(error_msg) diff --git a/addons/stable_horde_client/stable_horde_rate_generation.gd b/addons/stable_horde_client/stable_horde_rate_generation.gd index dc6e8c2..b1113e3 100644 --- a/addons/stable_horde_client/stable_horde_rate_generation.gd +++ b/addons/stable_horde_client/stable_horde_rate_generation.gd @@ -3,17 +3,16 @@ extends StableHordeHTTPRequest signal generation_rated(awarded_kudos) - func submit_rating(request_id: String, ratings_payload: Dictionary) -> void: if state != States.READY: print_debug("Rating is already being processed") return state = States.WORKING var body = to_json(ratings_payload) - var url = globals.aihorde_url + "/api/v2/generate/rate/" + request_id + var url = aihorde_url + "/api/v2/generate/rate/" + request_id var headers = [ "Content-Type: application/json", - "Client-Agent: " + "Lucid Creations:" + ToolConsts.VERSION + ":(discord)db0#1625" + "Client-Agent: " + client_agent ] # print_debug(url) # print_debug(body) diff --git a/project.godot b/project.godot index ce8bdef..3fd01c8 100644 --- a/project.godot +++ b/project.godot @@ -147,8 +147,8 @@ _global_script_class_icons={ [application] config/name="Lucid Creations" -config/description="Generate images using the Stable Diffusion AI and the Stable Horde crowdsourced cluster" -run/main_scene="res://StableHordeClient.tscn" +config/description="Generate images using the Stable Diffusion AI and the AI Horde crowdsourced cluster" +run/main_scene="res://LucidCreations.tscn" config/icon="res://icon.png" config/windows_native_icon="res://icon.ico" diff --git a/src/ParamBus.gd b/src/ParamBus.gd index a9cc989..1f33bda 100644 --- a/src/ParamBus.gd +++ b/src/ParamBus.gd @@ -232,7 +232,6 @@ func get_loras() -> Array: return loras_node.selected_loras_list func get_tis() -> Array: - print_debug(tis_node.selected_tis_list) return tis_node.selected_tis_list func _on_line_edit_changed(line_edit_node) -> void: