2024-09-22 15:47:23 +00:00
|
|
|
extends Control
|
2024-09-25 12:15:40 +00:00
|
|
|
var responses: Array
|
2024-09-10 14:33:58 +00:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
_connect_signals()
|
2024-09-25 20:07:25 +00:00
|
|
|
if class_functions.cheevos_token_state == "true":
|
2024-09-25 15:36:54 +00:00
|
|
|
#%cheevos_label.add_theme_stylebox_override()
|
|
|
|
%cheevos_label.add_theme_color_override("font_color", Color(0.941, 0.502, 1, 1))
|
|
|
|
%cheevos_label.text = "ALREADY LOGGED IN"
|
|
|
|
#%cheevos_connect_button.text = "LOGOUT"
|
2024-09-25 20:07:25 +00:00
|
|
|
else:
|
|
|
|
%cheevos_label.text = "NOT LOGGED IN"
|
2024-09-10 14:33:58 +00:00
|
|
|
func _connect_signals() -> void:
|
2024-09-17 11:19:48 +00:00
|
|
|
%sound_button.pressed.connect(class_functions.run_function.bind(%sound_button, "sound_effects"))
|
|
|
|
%update_notification_button.pressed.connect(class_functions.run_function.bind(%update_notification_button, "update_check"))
|
2024-09-14 15:31:59 +00:00
|
|
|
%volume_effects_slider.drag_ended.connect(class_functions.slider_function.bind(%volume_effects_slider))
|
2024-09-25 12:15:40 +00:00
|
|
|
%cheevos_connect_button.pressed.connect(cheevos.bind(%cheevos_connect_button))
|
2024-09-22 19:48:01 +00:00
|
|
|
%cheevos_button.button_down.connect(class_functions._do_action.bind(%cheevos_progress, %cheevos_button, class_functions.cheevos_state))
|
|
|
|
%cheevos_button.button_up.connect(class_functions._on_button_released.bind(%cheevos_progress))
|
|
|
|
%cheevos_button.pressed.connect(class_functions.run_function.bind(%cheevos_button, "cheevos"))
|
2024-09-24 19:15:47 +00:00
|
|
|
%cheevos_hardcore_button.button_down.connect(class_functions._do_action.bind(%cheevos_hardcore_progress, %cheevos_hardcore_button, class_functions.cheevos_hardcore_state))
|
|
|
|
%cheevos_hardcore_button.button_up.connect(class_functions._on_button_released.bind(%cheevos_hardcore_progress))
|
|
|
|
%cheevos_hardcore_button.pressed.connect(class_functions.run_function.bind(%cheevos_hardcore_button, "cheevos_hardcore"))
|
2024-09-24 21:05:02 +00:00
|
|
|
%reset_retrodeck_button.button_down.connect(class_functions._do_action.bind(%reset_retrodeck_progress, %reset_retrodeck_button, "mixed"))
|
|
|
|
%reset_retrodeck_button.button_up.connect(class_functions._on_button_released.bind(%reset_retrodeck_progress))
|
|
|
|
%reset_all_emulators_button.button_down.connect(class_functions._do_action.bind(%reset_all_emulators_progress, %reset_all_emulators_button, "mixed"))
|
|
|
|
%reset_all_emulators_button.button_up.connect(class_functions._on_button_released.bind(%reset_all_emulators_progress))
|
2024-09-25 20:07:25 +00:00
|
|
|
%system_button.pressed.connect(class_functions._hide_show_containers.bind(%system_button, %system_gridcontainer2))
|
|
|
|
%cheevos_collapse_button.pressed.connect(class_functions._hide_show_containers.bind(%cheevos_collapse_button, %cheevos_gridcontainer))
|
|
|
|
%future_button.pressed.connect(class_functions._hide_show_containers.bind(%future_button, %future_gridcontainer))
|
2024-09-22 13:44:18 +00:00
|
|
|
|
2024-09-25 12:15:40 +00:00
|
|
|
func _on_request_completed(_result, response_code, _headers, body) -> Array:
|
2024-09-22 13:44:18 +00:00
|
|
|
var response_text = JSON.parse_string(body.get_string_from_utf8())
|
2024-09-25 12:15:40 +00:00
|
|
|
var cheevos_token: String = ""
|
|
|
|
#print("Response Code: ", response_code)
|
|
|
|
#print("Response Body: ", response_text)
|
|
|
|
#print ("Response Success: ", response_text.Success)
|
|
|
|
#print("Response Token: ", response_text.Token)
|
|
|
|
if response_text.Success:
|
|
|
|
cheevos_token = response_text.Token
|
2024-09-22 13:44:18 +00:00
|
|
|
if response_code == 200:
|
2024-09-25 12:15:40 +00:00
|
|
|
responses = [response_code, response_text.Success, cheevos_token]
|
|
|
|
return responses
|
|
|
|
return responses
|
2024-09-22 13:44:18 +00:00
|
|
|
|
|
|
|
func cheevos(button: Button):
|
2024-09-25 12:15:40 +00:00
|
|
|
class_functions.logger("d","Attempting RA connection")
|
|
|
|
var ra_url = "https://retroachievements.org/dorequest.php?r=login&u="+%cheevos_username.text+"&p="+%cheevos_password.text
|
|
|
|
button.disabled = true
|
|
|
|
%cheevos_label.text = "ATTEMPTING LOGIN"
|
|
|
|
var http_request = HTTPRequest.new()
|
|
|
|
add_child(http_request)
|
|
|
|
http_request.request_completed.connect(self._on_request_completed)
|
|
|
|
http_request.request(ra_url)
|
|
|
|
responses = await wait_to_complete(http_request)
|
2024-10-02 12:13:27 +00:00
|
|
|
|
2024-09-25 12:15:40 +00:00
|
|
|
%cheevos_label.text = "LOGIN SUCCESS = %s" % str(responses[1]).to_upper()
|
|
|
|
button.disabled = false
|
2024-10-02 12:13:27 +00:00
|
|
|
# need to create missing fields/keys too ie chhevos token duckstation? Possibly not But do need timestamp
|
|
|
|
#data_handler.read_change_regex(class_functions.config_folder_path + "retroarch/retroarch.cfg", "cheevos_username", "bob12")
|
|
|
|
data_handler.read_change_regex(class_functions.config_folder_path + "duckstation/settings.ini", "Username", "monkeyx", false)
|
2024-09-25 12:15:40 +00:00
|
|
|
|
|
|
|
func wait_to_complete(http_request: HTTPRequest) -> Array:
|
|
|
|
await http_request.request_completed
|
|
|
|
return responses
|