Added an introduction and created internal API for REST-API calls

master
Hecht 7 months ago
parent 699905b2ef
commit a325679c95

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 MiB

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dbdlo6usavqqc"
path="res://.godot/imported/Gymzaal.png-963f5a16292a195c271b39340fcd1863.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/Background/Gymzaal.png"
dest_files=["res://.godot/imported/Gymzaal.png-963f5a16292a195c271b39340fcd1863.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

@ -32,6 +32,12 @@ layout/style_list=["res://assets/Dialogic/Styles/VisualNovel.tres"]
layout/default_style="res://assets/Dialogic/Styles/VisualNovel.tres"
glossary/default_case_sensitive=true
variables={
"bg": {
"clan": "",
"community": "",
"country": "",
"username": ""
},
"dojo": "",
"newdojo": "",
"user": ""

@ -0,0 +1,78 @@
extends HTTPRequest
const Response = preload("../util/Response.gd")
var _callback : Callable
var auth_token: String
var base_address: String
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func post_http_request(url: String, request_data: String) -> Response:
return await _send_http_request_sync(url, HTTPClient.METHOD_POST, request_data)
func patch_http_request(url: String, request_data: String) -> Response:
return await _send_http_request_sync(url, HTTPClient.METHOD_PATCH, request_data)
func get_http_request(url: String, callback : Callable) -> bool:
return _send_http_request(url, HTTPClient.METHOD_GET, callback)
func get_http_request_sync(url: String) -> Response:
return await _send_http_request_sync(url, HTTPClient.METHOD_GET)
func _send_http_request_sync(url: String, method: HTTPClient.Method, request_data: String = "") -> Response:
var result: Response = Response.new()
result.status = FAILED
result.code = HTTPClient.ResponseCode.RESPONSE_BAD_REQUEST
result.data = {}
var lambda = func(response):
result.status = response.status
result.code = response.code
result.data = response.data
if !_send_http_request(url, method, lambda, request_data):
return result
await request_completed
return result
func _send_http_request(url: String, method: HTTPClient.Method, callback : Callable, request_data : String = "") -> bool:
_callback = callback
var _url = "{address}/{url}".format({"address": base_address, "url": url})
print_debug("%s request on %s with: %s" % [method, _url, request_data])
var headers = ["X-AUTH-TOKEN: %s" % auth_token, "accept: application/json"]
if method == HTTPClient.METHOD_PATCH:
headers.append("Content-Type: application/merge-patch+json")
elif method == HTTPClient.METHOD_POST:
headers.append("Content-Type: application/json")
var error = request(_url, headers, method, request_data)
return error == OK
func _on_request_completed(result, response_code, headers, body):
var response : Response = Response.new()
response.status = FAILED
response.code = response_code
response.data = {}
## Where to get the response to?
if result == HTTPRequest.RESULT_SUCCESS and response_code / 100 == 2:
response.status = OK
var json = JSON.new()
json.parse(body.get_string_from_utf8())
response.data = json.get_data()
_callback.call(response)

@ -1,68 +1,60 @@
extends Node2D
@onready var http_request = $HTTPRequest
@onready var _http_request = $HTTPRequest
# var base_address = "https://animegame.eu/api"
var base_address = "http://localhost:8000/api"
var auth_token = null
var user_name = "FooBar"
const Response = preload("../util/Response.gd")
func create_dojo(dojo_name : String):
## Maybe get the HTTPRequest via parameter?
var body = JSON.stringify({"name": dojo_name})
if http_request.get_http_client_status():
# Prevent simultaneous request!
push_error("Busy with ongoing transaction!")
return
# _create_dojo_request.request_completed.connect(self._http_request_completed)
var error = http_request.request("{address}/dojos".format({"address": base_address}), ["Content-Type: application/json", "X-AUTH-TOKEN: %s" % auth_token], HTTPClient.METHOD_POST, body)
if error != OK:
push_error("An error occurred in the HTTP request.")
else:
print("Okay?")
print("Amount of children %s" % get_child_count())
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():
print_debug("Global Scene is 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]:
print_debug("key_value[0]: %s" % key_value[0])
print_debug("key_value[1]: %s" % key_value[1])
self.auth_token = key_value[1]
# replace \-_ with /\+
print_debug("auth_token before: %s", self.auth_token)
print_debug("auth_token after: %s", self.auth_token.replace("\\", "/").replace("-", "\\").replace("_", "+"))
var chunks = Marshalls.base64_to_raw(self.auth_token.replace("\\", "/").replace("-", "\\").replace("_", "+"))
self.user_name = chunks.slice(64).get_string_from_utf8().split('|')[0]
print_debug("user name: %s" % self.user_name)
_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 _on_http_request_request_completed(_result, _response_code, headers, body):
## Where to get the response to?
print("Completed?")
var json = JSON.new()
json.parse(body.get_string_from_utf8())
var response = json.get_data()
# Will print the user agent string used by the HTTPRequest node (as recognized by httpbin.org).
print(headers)
print(response)
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

@ -1,10 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://3qgip1nsocyh"]
[gd_scene load_steps=3 format=3 uid="uid://3qgip1nsocyh"]
[ext_resource type="Script" path="res://scenes/Global/Global.gd" id="1_yoteo"]
[ext_resource type="Script" path="res://scenes/Global/APIRequest.gd" id="2_jxuea"]
[node name="Global" type="Node2D"]
script = ExtResource("1_yoteo")
[node name="HTTPRequest" type="HTTPRequest" parent="."]
script = ExtResource("2_jxuea")
[connection signal="request_completed" from="HTTPRequest" to="." method="_on_http_request_request_completed"]
[connection signal="request_completed" from="HTTPRequest" to="HTTPRequest" method="_on_request_completed"]

@ -2,11 +2,24 @@ extends Control
@onready var _global_scn = get_node("/root/Global")
const Response = preload("../util/Response.gd")
# Called when the node enters the scene tree for the first time.
func _ready():
if _global_scn.user_name:
Dialogic.VAR.user = _global_scn.user_name
var dojo : Dictionary = await _global_scn.get_dojo()
if not dojo.is_empty():
Dialogic.VAR.dojo = dojo['name']
var user : Dictionary = await _global_scn.get_user()
if user.has("properties") and user["properties"] is Dictionary:
var properties: Dictionary = user["properties"]
Dialogic.VAR.bg.clan = properties.get("bg.clan", "")
Dialogic.VAR.bg.community = properties.get("bg.community", "")
Dialogic.VAR.bg.country = properties.get("bg.country", "")
Dialogic.VAR.bg.username = properties.get("bg.username", "")
Dialogic.signal_event.connect(_on_dialogic_signal)
Dialogic.start("res://timelines/new_player_wizard.dtl")
@ -16,7 +29,24 @@ func _process(_delta):
pass
func _on_dialogic_signal(argument:String):
Dialogic.paused = true
if argument == "create_dojo":
print("Create Dojo %s" % Dialogic.VAR.newdojo)
Dialogic.paused = true
_global_scn.create_dojo(Dialogic.VAR.newdojo)
var result: Response = await _global_scn.create_dojo(Dialogic.VAR.newdojo)
if result.status == OK:
Dialogic.VAR.dojo = Dialogic.VAR.newdojo
else:
print_debug("%s failed: %s - %s" % [argument, result.code, result.data])
elif argument == "update_preferences":
var result: Response = await _global_scn.update_user_preferences({
"bg.clan": Dialogic.VAR.bg.clan,
"bg.community": Dialogic.VAR.bg.community,
"bg.country": Dialogic.VAR.bg.country,
"bg.username": Dialogic.VAR.bg.username
})
if result.status == OK:
print_debug("Update preferences was successful!")
else:
print_debug("Update preferences failed: %s - %s" % [result.code, result.data])
elif argument == "the_end":
return
Dialogic.paused = false

@ -0,0 +1,4 @@
var status : Error
var code : HTTPClient.ResponseCode
var data : Dictionary

@ -1,13 +1,52 @@
[background arg="res://assets/Background/Gymzaal.png" fade="0.0"]
join Master 0
if {dojo} != null:
if {dojo} == "":
Master: Hallo ehrwürdiger Schutzgeist {user}. Willkommen in unserem bescheidenen Dorf.
- Schutzeist, Dorf?
- Schutzgeist, Dorf?
Master: Haha, ich sehe schon das du dich noch an diese Welt gewöhnen musst. Aber keiner Sorge, ich werde dir helfen dich hier zurecht zu finden,
label SelectDojoName
Master: Zuerst, welchen Namen soll dein Dojo bekommen?
[text_input var="newdojo"]
[signal arg="create_dojo"]
if {newdojo} != "WTF":
if {dojo} != {newdojo}:
Master: Irgendwas ging schief. Probiers gleich nochmal...
jump SelectDojoName
Master: Dann werden wir nun am Aufbau von {newdojo} arbeiten!
Master: Dann werden wir nun am Aufbau von {dojo} arbeiten!
leave Master
Ich hoffe euch hat die interaktive Dojo erstellung gefallen. Keine Sorge, das Animegame wird keine Visual Novel werden. Ich dachte mir, wenn wir schon eine Game-Engine nutzen, dann können wir auch spröde Menüs damit etwas aufpeppen.
Im neue Animegame könnt ihr wieder in Turnieren gegeneinander antreten. Es wird auch eine Welt geben. Die Spieler werden in verschiedene (virtuelle) Länder aufgeteilt. Die Besten jedes dieser Länder treten gegeneinander im Weltturnier an.
Um die erste Einteilung der Spielewelt zu erleichtern haben wir ein paar Fragen an dich.
if {bg.country} == "":
Aus welchem Land kommst du?
- Deutschland
set {bg.country} = "D"
- Österreich
set {bg.country} = "A"
- Niederlande
set {bg.country} = "NL"
- Sonstiges
[text_input var="bg.country"]
if {bg.community} == "":
Von welcher Community kann man dich zuordnen?
- DBBG & NBG
set {bg.community} = "DBBG"
- Animegame 1.0
set {bg.community} = "OAG"
- Andere
[text_input var="bg.community"]
if {bg.username} == "":
Warst du im alten AG registriert?
- Ja
Unter welchem Benutzernamen kennen dich die meisten?
[text_input var="bg.username"]
- Nein
set {bg.username} = "N/A"
if {bg.clan} == "":
if {bg.username} != "N/A":
In welchem Clan warst du?
[text_input var="bg.clan"]
Vielen Dank für die Informationen!
[signal arg="update_preferences"]
Das wars leider schon wieder! \:(
[signal arg="the_end"]
[end_timeline]

Loading…
Cancel
Save