mlpcardgame/Scenes/Global/Server.gd

18 lines
634 B
GDScript3
Raw Permalink Normal View History

extends Node
const RoomListAPI = Remote.Host + "api/v1/lobby/room/list"
func get_rooms(cbObj: Object, cbFn: String):
var req := HTTPRequest.new()
req.use_threads = !OS.has_feature("HTML5")
add_child(req)
req.connect("request_completed", self, "_get_completed", [cbObj, cbFn])
req.request(RoomListAPI)
func _get_completed(result: int, response_code: int, headers: PoolStringArray, body: PoolByteArray, cbObj: Object, cbFn: String):
# Cache result for later
if result != HTTPRequest.RESULT_SUCCESS:
cbObj.call(cbFn, result, body)
var obj = parse_json(body.get_string_from_utf8())
# Call callback
cbObj.call(cbFn, OK, obj)