feat: display backend ranked profile

This commit is contained in:
Josh Creek
2026-08-31 22:44:21 +01:00
parent 62c1478913
commit fddbebb33b
6 changed files with 118 additions and 4 deletions
+19 -3
View File
@@ -13,6 +13,7 @@ const PERSIST_PATH := "user://matchmaking_state.cfg"
var base_url := DEFAULT_BASE_URL
var access_token := ""
var state: MatchmakingState
var ranked_profile: RankedProfileState
var _request: HTTPRequest
var _operation := ""
@@ -20,6 +21,7 @@ var _operation := ""
func _ready() -> void:
state = MatchmakingState.new()
ranked_profile = RankedProfileState.new()
_load_persisted_state()
state.changed.connect(_persist_state)
_request = HTTPRequest.new()
@@ -61,6 +63,10 @@ func recover_proposal(proposal_id: String) -> Error:
return _start_request("proposal_recover", HTTPClient.METHOD_GET, "/v1/proposals/" + proposal_id, {}, "")
func fetch_ranked_profile() -> Error:
return _start_request("ranked_profile", HTTPClient.METHOD_GET, "/v1/profile/ranked", {}, "")
func heartbeat(ticket_id: String, expected_revision: int) -> Error:
if ticket_id.is_empty() or expected_revision < 0:
return ERR_INVALID_PARAMETER
@@ -114,7 +120,9 @@ func _on_request_completed(result: HTTPRequest.Result, response_code: int, _head
var operation := _operation
_operation = ""
if result != HTTPRequest.RESULT_SUCCESS:
if operation == "queue_create" or operation == "queue_recover" or operation == "proposal_recover":
if operation == "ranked_profile":
ranked_profile.set_error("Ranked profile request failed")
elif operation == "queue_create" or operation == "queue_recover" or operation == "proposal_recover":
state.fail("Control-plane request failed")
else:
state.set_notice("Control-plane request failed; retrying is safe")
@@ -122,7 +130,9 @@ func _on_request_completed(result: HTTPRequest.Result, response_code: int, _head
return
var parsed = JSON.parse_string(body.get_string_from_utf8())
if not parsed is Dictionary:
if operation == "queue_create" or operation == "queue_recover" or operation == "proposal_recover":
if operation == "ranked_profile":
ranked_profile.set_error("Ranked profile returned invalid JSON")
elif operation == "queue_create" or operation == "queue_recover" or operation == "proposal_recover":
state.fail("Control-plane returned invalid JSON")
else:
state.set_notice("Control-plane returned invalid JSON; retrying is safe")
@@ -130,7 +140,9 @@ func _on_request_completed(result: HTTPRequest.Result, response_code: int, _head
return
if response_code < 200 or response_code >= 300:
var detail := String(parsed.get("error", "request rejected"))
if operation == "queue_create" or operation == "queue_recover" or operation == "proposal_recover":
if operation == "ranked_profile":
ranked_profile.set_error(detail)
elif operation == "queue_create" or operation == "queue_recover" or operation == "proposal_recover":
state.fail(detail)
else:
state.set_notice(detail)
@@ -143,6 +155,10 @@ func _on_request_completed(result: HTTPRequest.Result, response_code: int, _head
state.apply_ticket_update(normalize_ticket(payload))
elif operation.begins_with("proposal_"):
state.apply_proposal_update(payload)
elif operation == "ranked_profile":
if not ranked_profile.apply(payload):
request_failed.emit(operation, response_code, ranked_profile.error_message)
return
request_succeeded.emit(operation, payload)