refactoring, send_discover_gate

This commit is contained in:
Nordup 2023-06-27 01:40:43 +04:00
parent 2bd62d2564
commit ffe477906d
18 changed files with 72 additions and 54 deletions

View file

@ -25,8 +25,8 @@ config/windows_native_icon="res://app_icon/icon.ico"
DataSaver="*res://scripts/data_saver.gd"
FileDownloader="*res://scripts/loading/file_downloader.gd"
Debug="*res://scripts/debug-log/debug.gd"
AnalyticsEvents="*res://scripts/analytics/analytics_events.gd"
Backend="*res://scripts/backend.gd"
AnalyticsEvents="*res://scripts/api/analytics/analytics_events.gd"
Backend="*res://scripts/api/backend.gd"
[debug]

View file

@ -1,9 +1,9 @@
[gd_resource type="Resource" script_class="BackendSettings" load_steps=2 format=3 uid="uid://cjcdum6fm4ta0"]
[ext_resource type="Script" path="res://scripts/resources/backend_settings.gd" id="1_oiju7"]
[ext_resource type="Script" path="res://scripts/resources/api_settings.gd" id="1_oiju7"]
[resource]
script = ExtResource("1_oiju7")
local_url = "http://127.0.0.1:8000"
remote_url = "http://95.163.241.188:8000"
host_type = 1
host_type = 0

View file

@ -7,14 +7,14 @@
[ext_resource type="PackedScene" uid="uid://kywrsqro3d5i" path="res://scenes/menu_body/world.tscn" id="4_p75rl"]
[ext_resource type="PackedScene" uid="uid://dh3owgirapji5" path="res://scenes/menu_body/search_results.tscn" id="4_phjpd"]
[ext_resource type="Script" path="res://scripts/bookmark_saver.gd" id="5_ev0ch"]
[ext_resource type="Script" path="res://scripts/analytics/analytics.gd" id="6_25d48"]
[ext_resource type="Resource" uid="uid://bewhdj6jugt6q" path="res://resources/bookmarks.tres" id="6_rupvx"]
[ext_resource type="PackedScene" uid="uid://byrcbqat0n2px" path="res://scenes/debug.tscn" id="7_3xeb8"]
[ext_resource type="Script" path="res://scripts/analytics/analytics_sender_app.gd" id="7_5328b"]
[ext_resource type="Resource" uid="uid://cjcdum6fm4ta0" path="res://resources/backend.tres" id="7_yykjj"]
[ext_resource type="Script" path="res://scripts/analytics/analytics_sender_error.gd" id="8_ah58q"]
[ext_resource type="Script" path="res://scripts/analytics/analytics_sender_gate.gd" id="9_egxpy"]
[ext_resource type="Script" path="res://scripts/api_add_gate.gd" id="14_enhvg"]
[ext_resource type="Script" path="res://scripts/api/analytics/analytics.gd" id="9_a1ttg"]
[ext_resource type="Resource" uid="uid://cjcdum6fm4ta0" path="res://resources/api_settings.tres" id="10_04o5h"]
[ext_resource type="Script" path="res://scripts/api/analytics/analytics_sender_app.gd" id="11_cwwqp"]
[ext_resource type="Script" path="res://scripts/api/analytics/analytics_sender_error.gd" id="12_rfjm7"]
[ext_resource type="Script" path="res://scripts/api/discover_gate.gd" id="13_3xhql"]
[ext_resource type="Script" path="res://scripts/api/analytics/analytics_sender_gate.gd" id="13_jout6"]
[node name="App" type="Node" node_paths=PackedStringArray("scenes_root")]
script = ExtResource("1_skc7d")
@ -24,36 +24,38 @@ search_results = ExtResource("4_phjpd")
world_scene = ExtResource("4_p75rl")
scenes_root = NodePath("Menu/VBoxContainer/Body")
[node name="Debug" parent="." instance=ExtResource("7_3xeb8")]
[node name="Window" parent="Debug" index="0"]
visible = false
[node name="BookmarkSaver" type="Node" parent="."]
script = ExtResource("5_ev0ch")
save_dir = "user://resources"
image_save_dir = "user://images"
bookmarks = ExtResource("6_rupvx")
[node name="Analytics" type="Node" parent="."]
script = ExtResource("6_25d48")
backend = ExtResource("7_yykjj")
[node name="Api" type="Node" parent="."]
[node name="SenderApp" type="Node" parent="Analytics"]
script = ExtResource("7_5328b")
[node name="Analytics" type="Node" parent="Api"]
script = ExtResource("9_a1ttg")
api = ExtResource("10_04o5h")
[node name="SenderError" type="Node" parent="Analytics"]
script = ExtResource("8_ah58q")
[node name="SenderApp" type="Node" parent="Api/Analytics"]
script = ExtResource("11_cwwqp")
[node name="SenderGate" type="Node" parent="Analytics"]
script = ExtResource("9_egxpy")
[node name="SenderError" type="Node" parent="Api/Analytics"]
script = ExtResource("12_rfjm7")
[node name="SenderGate" type="Node" parent="Api/Analytics"]
script = ExtResource("13_jout6")
gate_events = ExtResource("2_cdryv")
[node name="ApiAddGate" type="Node" parent="."]
script = ExtResource("14_enhvg")
backend = ExtResource("7_yykjj")
[node name="AddGate" type="Node" parent="Api"]
script = ExtResource("13_3xhql")
api = ExtResource("10_04o5h")
gate_events = ExtResource("2_cdryv")
[node name="Debug" parent="." instance=ExtResource("7_3xeb8")]
[node name="Window" parent="Debug" index="0"]
visible = false
[node name="Menu" parent="." instance=ExtResource("3_o1f7b")]
[editable path="Debug"]

View file

@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://scripts/ui/search/search_results.gd" id="1_bycb5"]
[ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://resources/gate_events.res" id="2_2plpa"]
[ext_resource type="Resource" uid="uid://cjcdum6fm4ta0" path="res://resources/backend.tres" id="3_263ma"]
[ext_resource type="Resource" uid="uid://cjcdum6fm4ta0" path="res://resources/api_settings.tres" id="3_263ma"]
[node name="search_results" type="Control"]
layout_mode = 3
@ -29,7 +29,7 @@ layout_mode = 2
size_flags_horizontal = 3
script = ExtResource("1_bycb5")
gate_events = ExtResource("2_2plpa")
backend = ExtResource("3_263ma")
api = ExtResource("3_263ma")
[node name="Label" type="Label" parent="HBoxContainer/VBoxContainer"]
self_modulate = Color(1, 1, 1, 0.6)

View file

@ -1,7 +1,7 @@
extends Node
class_name Analitycs
@export var backend: BackendSettings
@export var api: ApiSettings
signal analytics_ready
@ -11,7 +11,7 @@ func _ready() -> void:
func send_event(body: Dictionary = {}) -> void:
var url = backend.analytics_event
var url = api.analytics_event
var callback = func(_result, code, _headers, _body):
if code != 200: Debug.logclr("Request send_event failed. Code " + str(code), Color.RED)
@ -20,7 +20,7 @@ func send_event(body: Dictionary = {}) -> void:
func get_user_id() -> void:
var url = backend.get_user_id + OS.get_unique_id()
var url = api.get_user_id + OS.get_unique_id()
var callback = func(_result, code, _headers, body):
if code == 200:
AnalyticsEvents.user_id = body.get_string_from_utf8()

View file

@ -0,0 +1,25 @@
extends Node
@export var api: ApiSettings
@export var gate_events: GateEvents
func _ready() -> void:
gate_events.gate_config_loaded.connect(send_discover_gate)
func send_discover_gate(c_url: String, c_gate: ConfigGate) -> void:
var body = {}
body.url = c_url
body.title = c_gate.title
body.description = c_gate.description
body.image = c_gate.image_url
body.resource_pack = c_gate.resource_pack_url
body.libraries = c_gate.libraries
var url = api.discover_gate
var callback = func(_result, code, _headers, _body):
if code != 200: Debug.logclr("Request send_discover_gate failed. Code " + str(code), Color.RED)
var err = await Backend.request(url, callback, body, HTTPClient.METHOD_POST)
if err != HTTPRequest.RESULT_SUCCESS: Debug.logclr("Cannot send request send_discover_gate", Color.RED)

View file

@ -1,17 +0,0 @@
extends Node
@export var backend: BackendSettings
@export var gate_events: GateEvents
func _ready() -> void:
gate_events.open_gate.connect(send_add_gate)
func send_add_gate(gate_url: String) -> void:
var url = backend.add_gate + gate_url.uri_encode()
var callback = func(_result, code, _headers, _body):
if code != 200: Debug.logclr("Request send_open_gate failed. Code " + str(code), Color.RED)
var err = await Backend.request(url, callback, {}, HTTPClient.METHOD_POST)
if err != HTTPRequest.RESULT_SUCCESS: Debug.logclr("Cannot send request send_open_gate", Color.RED)

View file

@ -13,6 +13,7 @@ func load_gate(config_url: String) -> void:
Debug.logclr("======== " + config_url + " ========", Color.GREEN)
var config_path: String = await FileDownloader.download(config_url)
c_gate = ConfigGate.new(config_path, config_url)
gate_events.gate_config_loaded_emit(config_url, c_gate)
var image_path = await FileDownloader.download(c_gate.image_url)
var gate = Gate.create(config_url, c_gate.title, c_gate.description, image_path, "", "")

View file

@ -1,5 +1,5 @@
extends Resource
class_name BackendSettings
class_name ApiSettings
enum HostType {
Local,
@ -19,8 +19,8 @@ var analytics_event: String :
var get_user_id: String :
get: return url + "/api/get_user_id?device_id="
var add_gate: String :
get: return url + "/api/add_gate?url="
var discover_gate: String :
get: return url + "/api/discover_gate"
var search: String :
get: return url + "/api/search?query="

View file

@ -8,6 +8,8 @@ class_name Gate
@export var description: String
@export_file("*.png", "*.jpg") var image: String
var resource_pack: String
# local path where libs downloaded
var shared_libs_dir: String

View file

@ -3,6 +3,7 @@ class_name GateEvents
signal search(query: String)
signal open_gate(url: String)
signal gate_config_loaded(url: String, config: ConfigGate)
signal gate_info_loaded(gate: Gate)
signal gate_loaded(gate: Gate)
signal gate_entered
@ -27,6 +28,10 @@ func search_emit(query: String) -> void:
search.emit(query)
func gate_config_loaded_emit(url: String, config: ConfigGate) -> void:
gate_config_loaded.emit(url, config)
func gate_info_loaded_emit(gate: Gate) -> void:
current_gate = gate
gate_info_loaded.emit(gate)

View file

@ -1,7 +1,7 @@
extends VBoxContainer
@export var gate_events: GateEvents
@export var backend: BackendSettings
@export var api: ApiSettings
var result: String
@ -31,7 +31,7 @@ func search(query: String) -> void:
func search_request(query: String):
var url = backend.search + query.uri_encode()
var url = api.search + query.uri_encode()
var callback = func(_result, code, _headers, body):
if code == 200:
result = body.get_string_from_utf8()