diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-12-12 02:12:52 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-12-12 02:12:52 +0100 |
commit | a22381eff3bf2286ee27f4d15ddf4c431ea063be (patch) | |
tree | 965bdcf12e5e0cf63c88cbba1bd5a52ba474f81f /login.gd | |
parent | e3c185e05823e30eccd7728ceda2ee57cc66fd4d (diff) |
next commit
Diffstat (limited to 'login.gd')
-rw-r--r-- | login.gd | 49 |
1 files changed, 36 insertions, 13 deletions
@@ -9,24 +9,33 @@ var current_character_information: CharacterInformation func _ready() -> void: switch_screen(%Login) - #$AudioStreamPlayer2.play() + #$BackgroundMusic.play() + + # TODO: check why TextureRect doesn't work + #get_tree().root.size_changed.connect(func(): + #$Background.scale = get_viewport_rect().size / $Background.get_rect().size + #) func switch_screen(screen: Node): for node in get_children(): - if node is Control: + if node is CenterContainer: node.visible = false screen.visible = true func _on_login_pressed() -> void: - $AudioStreamPlayer.play() + $ButtonClickSound.play() Network.login_server.login(%Username.text, %Password.text) account_information = await Network.login_server.logged_in character_server_information = account_information.character_server_information + Client.account.id = account_information.account_id + + get_tree().root.add_child(Network.login_server.get_keep_alive_timer()) + for node in %CharacterServerList.get_children(): node.queue_free() @@ -41,7 +50,7 @@ func _on_login_pressed() -> void: func _on_character_server_login_pressed(character_server_info: CharacterServerInformation) -> void: - $AudioStreamPlayer.play() + $ButtonClickSound.play() Network.character_server = CharacterServer.new( character_server_info.get_server_ip(), character_server_info.server_port @@ -54,11 +63,18 @@ func _on_character_server_login_pressed(character_server_info: CharacterServerIn account_information.gender ) - var _response = await Network.character_server.logged_in - var response: CharacterServerLoginSuccessCharacterListPacket = await Network.character_server.logged_in_character_list + var response = await Network.character_server.received_packet + if response is CharacterSelectionFailedPacket: + print("character server login failed") + %ChatWindow.add_message("character server login failed") + return + + get_tree().root.add_child(Network.character_server.get_keep_alive_timer()) - for slot_idx in response.character_information.size(): - var info: CharacterInformation = response.character_information[slot_idx] + var character_list: CharacterServerLoginSuccessCharacterListPacket = await Network.character_server.logged_in_character_list + + for slot_idx in character_list.character_information.size(): + var info: CharacterInformation = character_list.character_information[slot_idx] var character = Button.new() character.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND character.text = info.name @@ -72,14 +88,14 @@ func _on_character_server_login_pressed(character_server_info: CharacterServerIn func _on_character_selected_pressed(slot_idx: int): - $AudioStreamPlayer.play() + $ButtonClickSound.play() Network.character_server.select_character(slot_idx) - var packet = await Network.character_server.selected_character - if packet is CharacterSelectionSuccessPacket: + var selected_character = await Network.character_server.selected_character + if selected_character is CharacterSelectionSuccessPacket: Network.map_server = MapServer.new( - packet.get_map_server_ip(), - packet.map_server_port + selected_character.get_map_server_ip(), + selected_character.map_server_port ) Network.map_server.login( @@ -89,5 +105,12 @@ func _on_character_selected_pressed(slot_idx: int): account_information.gender ) var _response = await Network.map_server.logged_in + + Client.character.name = current_character_information.name # TODO: switch to game :) + # TODO: check next packages to sent to server, most probably to map server + Network.map_server.received_packet.connect(func(packet: Packet): + if packet is ServerMessagePacket: + %ChatWindow.add_message(packet.message) + ) |