83 lines
2.8 KiB
GDScript
83 lines
2.8 KiB
GDScript
extends Control
|
|
|
|
var cell_tag = "MIAW"
|
|
|
|
@export var player_name: Label
|
|
@export var player_rank: Label
|
|
@export var player_score: Label
|
|
@export var cell_rank: Label
|
|
@export var cell_score: Label
|
|
@export var player_request: HTTPRequest
|
|
@export var cell_request: HTTPRequest
|
|
@export var cell_name: Label
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
get_data()
|
|
pass # Replace with function body.
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
pass
|
|
|
|
func get_data():
|
|
#var http_client : HTTPClient = HTTPClient.new()
|
|
#http_client.connect_to_host("https://payphonetag.com/")
|
|
|
|
|
|
var body = JSON.stringify({"pin": "98409"})
|
|
var error = player_request.request("https://payphonetag.com/api/player-snapshot", [], HTTPClient.METHOD_POST, body)
|
|
print(error)
|
|
|
|
|
|
var body2 = JSON.stringify({"pin": "98409"})
|
|
var error2 = cell_request.request("https://payphonetag.com/api/cell/leaderboard", [], HTTPClient.METHOD_GET, body2)
|
|
print(error2)
|
|
|
|
#var fields = { }
|
|
#var query_string = http_client.query_string_from_dict(fields)
|
|
#var headers = ["pin : 98409" ,"Content-Type: application/x-www-form-urlencoded", "Content-Length: " + str(query_string.length())]
|
|
#var player_data = http_client.request(http_client.METHOD_POST, "https://payphonetag.com/api/player-snapshot", headers, '"pin" : "98409"')
|
|
|
|
#print(player_data)
|
|
|
|
# Called when the HTTP request is completed.
|
|
func player_request_completed(result, response_code, headers, body):
|
|
var json = JSON.new()
|
|
json.parse(body.get_string_from_utf8())
|
|
var response : Dictionary = json.get_data()
|
|
|
|
# Will print the user agent string used by the HTTPRequest node (as recognized by httpbin.org).
|
|
#print(response.headers["rank"])
|
|
#print(response.headers["total_score"])
|
|
print(response.get("rank"))
|
|
print(response.get("total_score"))
|
|
player_rank.text = "#" + str(int(response.get("rank")))
|
|
player_score.text = str(int(response.get("total_score")))
|
|
|
|
func cell_request_completed(result, response_code, headers, body):
|
|
var json = JSON.new()
|
|
json.parse(body.get_string_from_utf8())
|
|
var response : Array = json.get_data()
|
|
|
|
# Will print the user agent string used by the HTTPRequest node (as recognized by httpbin.org).
|
|
#print(response.headers["rank"])
|
|
#print(response.headers["total_score"])
|
|
#print(response.get("rank"))
|
|
#print(response.get("total_score"))
|
|
#print(response)
|
|
print("meow")
|
|
for i : int in range(response.size()):
|
|
if (response[i].get("CellTag") == cell_tag):
|
|
cell_name.text = response[i].get("CellName") + " [" + response[i].get("CellTag") + "]"
|
|
cell_rank.text = "#" + str(i+1)
|
|
cell_score.text = str(int(response[i].get("TotalScore")))
|
|
return
|
|
|
|
|
|
func _on_popup_menu_id_pressed(id: int) -> void:
|
|
# 0 = exit
|
|
if id == 0:
|
|
get_tree().quit()
|
|
pass # Replace with function body.
|