2024-02-27 23:21:44 +01:00

63 lines
1.6 KiB
GDScript

extends Node
@export var ui: UI
func _ready():
pause(true)
connect_events()
start()
func _input(event: InputEvent):
if event.is_action_pressed("toggle_fullscreen"):
WindowManager.toggle_fullscreen(get_window())
get_viewport().set_input_as_handled()
func connect_events():
%Login.success.connect(on_login)
%Logout.success.connect(on_logout)
%Login.success.connect(ui.reconnect.hide)
%Logout.success.connect(ui.reconnect.show)
%Ping.changed.connect(ui.network.set_ping)
%Client.download_changed.connect(ui.network.set_download)
%Client.upload_changed.connect(ui.network.set_upload)
%Chat.message_received.connect(ui.chat.add_message)
ui.chat.message_submitted.connect( %Chat.send_message)
func start():
var args := OS.get_cmdline_args()
var offline := args.has("--offline")
if offline:
start_offline()
else:
start_online()
func start_offline():
Global.account.id = "test"
Global.account.name = "Local"
Global.account.auth_token = "test"
Global.player = %PlayerAdd.spawn_player(Global.account.id, Global.account.name, Vector3.ZERO)
%Login.success.emit()
func start_online():
%Login.send_login()
func pause(enabled: bool):
get_tree().paused = enabled
Audio.mute(enabled)
func on_login():
Log.info("Login succeeded.")
Log.info("ID: %s" % Global.account.id)
Log.info("Auth token: %s" % Global.account.auth_token)
#DisplayServer.window_set_position(Vector2((Global.instance_id % 2) * 960, (Global.instance_id / 2 % 2) * 540))
get_window().title = "%s - %s" % [Global.account.name, Global.account.id]
pause(false)
func on_logout():
Log.info("[%s] Logout." % Global.account.name)
pause(true)