Cover menu in the soundtrack popup ("Change cover"):
- Choose picture uploads a JPEG, PNG or WebP picture (up to 10 MB).
- Pick by ID uses a game's cover on SteamGridDB or an anime's on AniList.
- Remove cover deletes it, so the server searches for a new one.
- The server's reason is shown when it refuses a change.
After a change the new cover time is fetched, and the popup, the
statistics card and the quiz show the new cover.
Quiz: once the answer is shown, the soundtrack's cover shows to the left of
the titles. Cover and titles are centered together, left and right and up
and down, and each title keeps to two lines. Cover times come from the
soundtrack list, and songs keep their soundtrack's UUID, also in saves.
Requests can now send any body with its content type, and every 2xx answer
counts as success. Cover frames are 2:3 like the server's covers. Small
copies of real covers are used by the tests and screenshots.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
1.7 KiB
GDScript
51 lines
1.7 KiB
GDScript
class_name HttpTransport
|
|
extends RefCounted
|
|
## Sends HTTP requests for [code]MusicServerClient[/code] using [HTTPRequest] nodes.
|
|
##
|
|
## Tests subclass this to answer requests without a network connection.
|
|
|
|
## Seconds before a request is given up and reported as failed. This covers the whole
|
|
## download, so it is generous enough for long songs on a slow connection.
|
|
|
|
var timeout_seconds: float = 120.0
|
|
var _owner: Node
|
|
|
|
|
|
func _init(owner: Node) -> void:
|
|
_owner = owner
|
|
|
|
|
|
## Requests [param url] and calls [param on_complete] with
|
|
## [code](response_code: int, body: PackedByteArray, headers: PackedStringArray)[/code],
|
|
## the headers as [code]"Name: value"[/code] lines. Connection errors and timeouts are
|
|
## reported with response code 0 and no headers. [param headers], which name the
|
|
## [param body]'s type, are sent as-is.
|
|
func request(
|
|
url: String,
|
|
method: int,
|
|
on_complete: Callable,
|
|
headers: PackedStringArray = PackedStringArray(),
|
|
body: PackedByteArray = PackedByteArray(),
|
|
) -> void:
|
|
var http_request: HTTPRequest = HTTPRequest.new()
|
|
http_request.timeout = timeout_seconds
|
|
_owner.add_child(http_request)
|
|
http_request.request_completed.connect(
|
|
func(
|
|
result: int,
|
|
response_code: int,
|
|
response_headers: PackedStringArray,
|
|
response_body: PackedByteArray,
|
|
) -> void:
|
|
http_request.queue_free()
|
|
if result != HTTPRequest.RESULT_SUCCESS:
|
|
on_complete.call(0, response_body, PackedStringArray())
|
|
return
|
|
on_complete.call(response_code, response_body, response_headers)
|
|
)
|
|
var error: int = http_request.request_raw(url, headers, method, body)
|
|
if error != OK:
|
|
http_request.queue_free()
|
|
push_error("Could not send request to %s (error %d)" % [url, error])
|
|
on_complete.call(0, PackedByteArray(), PackedStringArray())
|