36 lines
849 B
GDScript3
36 lines
849 B
GDScript3
|
|
class_name GameClient extends ClientNetworking
|
||
|
|
|
||
|
|
|
||
|
|
func _ready() -> void:
|
||
|
|
setup_signals()
|
||
|
|
|
||
|
|
|
||
|
|
func setup_signals() -> void:
|
||
|
|
MessageBus.subscribe("game_start_client", _start_client)
|
||
|
|
|
||
|
|
MessageBus.subscribe("game_wait_for_connection", _wait_for_connection)
|
||
|
|
MessageBus.subscribe("game_close_connection", _wait_close_connection)
|
||
|
|
|
||
|
|
func _start_client(address: String = "127.0.0.1", port: int = 8080) -> void:
|
||
|
|
if peer: return
|
||
|
|
start_client(address, port)
|
||
|
|
|
||
|
|
|
||
|
|
func client_connected_to_server() -> void:
|
||
|
|
push_warning("Connected to server!")
|
||
|
|
|
||
|
|
func close_connection() -> void:
|
||
|
|
if not peer: return
|
||
|
|
|
||
|
|
push_warning("Disconnected from, server...")
|
||
|
|
|
||
|
|
unset_client()
|
||
|
|
|
||
|
|
func client_disconnected_from_server() -> void:
|
||
|
|
push_warning("Disconnected from, server...")
|
||
|
|
|
||
|
|
func client_connection_failed_to_server() -> void:
|
||
|
|
push_warning("Connection failed!")
|
||
|
|
|
||
|
|
unset_client()
|