57 lines
1.4 KiB
GDScript
57 lines
1.4 KiB
GDScript
extends Control
|
|
|
|
const ApiClientScript := preload("res://scripts/services/api_client.gd")
|
|
|
|
const AUTO_USERNAME := "13800000001"
|
|
const AUTO_PASSWORD := "123456"
|
|
|
|
@export var main_scene: PackedScene
|
|
|
|
var _current_scene: Node
|
|
var _api_client: ApiClient
|
|
|
|
|
|
func _ready() -> void:
|
|
_api_client = ApiClientScript.new()
|
|
add_child(_api_client)
|
|
await get_tree().process_frame
|
|
_auto_login()
|
|
|
|
|
|
func _auto_login() -> void:
|
|
var login_path := str(ProjectSettings.get_setting("farm_game/api/login_path", "user/login"))
|
|
var result := await _api_client.post_json(login_path, {
|
|
"username": AUTO_USERNAME,
|
|
"password": AUTO_PASSWORD
|
|
})
|
|
if not result.get("ok", false):
|
|
push_error("Auto login failed. HTTP %s, game status %s" % [
|
|
result.get("status", 0),
|
|
result.get("game_status", "unknown")
|
|
])
|
|
return
|
|
|
|
var body = result.get("body", {})
|
|
var player_data: Dictionary = {}
|
|
if body is Dictionary and body.get("data", {}) is Dictionary:
|
|
player_data = body["data"]
|
|
_show_main_scene(player_data)
|
|
|
|
|
|
func _show_main_scene(player_data: Dictionary) -> void:
|
|
if main_scene == null:
|
|
push_error("Missing main scene.")
|
|
return
|
|
|
|
var main := main_scene.instantiate()
|
|
if main.has_method("setup"):
|
|
main.setup(player_data)
|
|
_show_scene(main)
|
|
|
|
|
|
func _show_scene(scene: Node) -> void:
|
|
if _current_scene != null:
|
|
_current_scene.queue_free()
|
|
_current_scene = scene
|
|
add_child(_current_scene)
|