You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.0 KiB
61 lines
2.0 KiB
extends Node2D
|
|
|
|
@onready var _http_request = $HTTPRequest
|
|
|
|
const Response = preload("../util/Response.gd")
|
|
|
|
var user_name : String = "FooBar"
|
|
var _dojo : Dictionary = {}
|
|
var _user: Dictionary = {}
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
_http_request.base_address = "http://localhost:8000/api"
|
|
_http_request.auth_token = "_sGFrChRV6ML0eWZC2qSUZzEGNLPbAhP4dwmnWhQ5bQ9xIi2pwHWQ1CzybFPDLeK8dTNx6GgWdR-Jcz-Z9_aC0hlY2h0fDIwMjQtMDYtMTNUMTk6MTU6MzkrMDA6MDA="
|
|
|
|
for argument in OS.get_cmdline_user_args():
|
|
print_debug("argument: %s" % argument)
|
|
var key_value = argument.split("=", true, 1)
|
|
if "--token" == key_value[0]:
|
|
_http_request.auth_token = key_value[1]
|
|
elif "--env" == key_value[0]:
|
|
if key_value[1] == "dev":
|
|
_http_request.base_address = "http://localhost:8000/api"
|
|
else:
|
|
_http_request.base_address = "https://dojo.animegame.eu/api"
|
|
|
|
var tmp = _http_request.auth_token.replace("-", "/").replace("_", "+")
|
|
|
|
# replace \-_ with /\+
|
|
var chunks = Marshalls.base64_to_raw(tmp)
|
|
user_name = chunks.slice(64).get_string_from_utf8().split('|')[0]
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(_delta):
|
|
pass
|
|
|
|
func create_dojo(dojo_name : String) -> Response:
|
|
var body = JSON.stringify({"name": dojo_name})
|
|
return await _http_request.post_http_request("dojos", body)
|
|
|
|
func update_user_preferences(values: Dictionary) -> Response:
|
|
var body = JSON.stringify({"properties": values})
|
|
var user = await get_user()
|
|
return await _http_request.patch_http_request("users/%s" % user["id"], body)
|
|
|
|
func get_dojo() -> Dictionary:
|
|
if _dojo.is_empty():
|
|
var result: Response = await _http_request.get_http_request_sync("dojo")
|
|
if result.status == OK:
|
|
_dojo = result.data
|
|
|
|
return _dojo
|
|
|
|
func get_user() -> Dictionary:
|
|
if _user.is_empty():
|
|
var result = await _http_request.get_http_request_sync("users/authName/%s" % user_name)
|
|
if result.status == OK:
|
|
_user = result.data
|
|
return _user
|