26 lines
761 B
GDScript
26 lines
761 B
GDScript
extends Node
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
var http_request = HTTPRequest.new()
|
|
add_child(http_request)
|
|
http_request.request_completed.connect(self._http_request_completed)
|
|
|
|
self.request_completed.connect(self._http_request_completed)
|
|
var error = http_request.request("http://localhost:8765/api/games")
|
|
if error != OK:
|
|
push_error("An error occurred in the HTTP request.")
|
|
|
|
|
|
func _http_request_completed(_result, _response_code, _headers, body):
|
|
var json = JSON.new()
|
|
json.parse(body.get_string_from_utf8())
|
|
var response := json.get_data() as Array
|
|
|
|
print(response)
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
# func _process(delta: float) -> void:
|
|
# pass
|