Move server calls to MusicServerClient and give players stable ids
Server requests move out of Settings into a new MusicServerClient autoload with one function per endpoint. It sends requests through a swappable HttpTransport so tests can fake the server, and it frees its HTTPRequest nodes after use. Players now have a UUID that never changes. Their position in Settings.player_array is only used for the Alt+<number> keybinds. Previously the position doubled as the id, so removing a player made points and wins land on the wrong player, and could delete another player's point from a song. Also fixes: - format_time showed 59.6 seconds as "00:60" - searches containing regex characters such as "Q*bert" broke search - SongObject and PlayerObject were Nodes that were never freed; they are now RefCounted - search matching is split out of the UI code into find_matches()
This commit is contained in:
1 parent
ab338b0696
commit
56e9fe66d3
18 files changed
+281
-162
No files matched your search
-60
@@ -30,66 +30,6 @@ var character_select_open: bool = false
|
||||
|
||||
var version: String = "1.9.0"
|
||||
|
||||
func make_request2(address: String, func_name: Callable, expect_data: bool) -> void:
|
||||
var error_handling: Callable = func(_result: int, response_code: int, _headers: PackedStringArray, body: PackedByteArray) -> void:
|
||||
print("request done to address: ", default_path + address + " response_code: ", response_code)
|
||||
if response_code == 200:
|
||||
print("func_name: ", func_name.get_method())
|
||||
if !expect_data:
|
||||
func_name.call()
|
||||
else:
|
||||
var json: JSON = JSON.new()
|
||||
var error: int = json.parse(body.get_string_from_utf8())
|
||||
if error == OK:
|
||||
var data_received = json.get_data()
|
||||
print("data_received type: ", type_string(typeof(data_received)))
|
||||
if typeof(data_received) == TYPE_ARRAY:
|
||||
func_name.call(data_received)
|
||||
elif func_name != null:
|
||||
func_name.call(data_received)
|
||||
else:
|
||||
print("data_received type: ", type_string(typeof(body)))
|
||||
func_name.call(body)
|
||||
|
||||
var http_request: HTTPRequest = HTTPRequest.new()
|
||||
add_child(http_request)
|
||||
http_request.request_completed.connect(error_handling)
|
||||
|
||||
# Perform a GET request. The URL below returns JSON as of writing.
|
||||
print("address: ", default_path + address)
|
||||
var request_error: int = http_request.request(default_path + address)
|
||||
if request_error != OK:
|
||||
push_error("An error occurred in the HTTP request.")
|
||||
|
||||
func make_request3(address: String) -> void:
|
||||
var error_handling: Callable = func(_result: int, response_code: int, _headers: PackedStringArray, _body: PackedByteArray) -> void:
|
||||
print("request done to address: ", default_path + address + " response_code: ", response_code)
|
||||
if response_code != 200:
|
||||
print("Error: " + str(response_code))
|
||||
|
||||
var http_request: HTTPRequest = HTTPRequest.new()
|
||||
add_child(http_request)
|
||||
http_request.request_completed.connect(error_handling)
|
||||
# Perform a GET request. The URL below returns JSON as of writing.
|
||||
var request_error: int = http_request.request(default_path + address)
|
||||
if request_error != OK:
|
||||
push_error("An error occurred in the HTTP request.")
|
||||
|
||||
func make_put_request(address: String) -> void:
|
||||
var error_handling: Callable = func(_result: int, response_code: int, _headers: PackedStringArray, _body: PackedByteArray) -> void:
|
||||
print("request done to address: ", default_path + address + " response_code: ", response_code)
|
||||
if response_code != 200:
|
||||
print("Error: " + str(response_code))
|
||||
|
||||
var http_request: HTTPRequest = HTTPRequest.new()
|
||||
add_child(http_request)
|
||||
http_request.request_completed.connect(error_handling)
|
||||
# Perform a GET request. The URL below returns JSON as of writing.
|
||||
var headers: PackedStringArray = ["Content-Type: application/json"]
|
||||
var request_error: int = http_request.request(default_path + address, headers, HTTPClient.METHOD_PUT)
|
||||
if request_error != OK:
|
||||
push_error("An error occurred in the HTTP request.")
|
||||
|
||||
func delete_children(node: Node) -> void:
|
||||
for n: Node in node.get_children():
|
||||
node.remove_child(n)
|
||||
|
||||
Reference in new issue
Block a user