Generate basic world & recieve data on client
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
extends Node
|
||||
|
||||
signal tile_update(tile_data)
|
||||
|
||||
const KEY := "defaultkey"
|
||||
const SERVER_ENDPOINT := "nakama.cloudsumu.com"
|
||||
|
||||
@ -8,6 +10,10 @@ var _client : NakamaClient = Nakama.create_client(KEY, SERVER_ENDPOINT, 7350, "h
|
||||
var _socket : NakamaSocket
|
||||
var _precenses : Dictionary = {}
|
||||
|
||||
enum OPCODE {
|
||||
tile_update = 1
|
||||
}
|
||||
|
||||
func authenticate_async(email : String, password : String) -> NakamaException:
|
||||
var result : NakamaException = null
|
||||
|
||||
@ -36,6 +42,7 @@ func connect_to_server_async() -> NakamaException:
|
||||
_socket = Nakama.create_socket_from(_client)
|
||||
var result : NakamaAsyncResult = yield(_socket.connect_async(_session), "completed")
|
||||
if not result.is_exception():
|
||||
_socket.connect("received_match_state", self, "_on_socket_received_match_state")
|
||||
_socket.connect("closed", self, "_on_socket_closed")
|
||||
return null
|
||||
return result.exception
|
||||
@ -60,3 +67,9 @@ func join_world_async() -> Dictionary:
|
||||
|
||||
func _on_socket_closed():
|
||||
_socket = null
|
||||
|
||||
func _on_socket_received_match_state(match_state: NakamaRTAPI.MatchData):
|
||||
match match_state.op_code:
|
||||
OPCODE.tile_update:
|
||||
emit_signal("tile_update", JSON.parse(match_state.data).result)
|
||||
|
||||
|
15
client/scripts/singletons/WorldManager.gd
Normal file
15
client/scripts/singletons/WorldManager.gd
Normal file
@ -0,0 +1,15 @@
|
||||
extends Node
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
ServerConnection.connect("tile_update", self, "on_tile_update")
|
||||
yield(ServerConnection.join_world_async(), "completed")
|
||||
|
||||
func on_tile_update(tile_data):
|
||||
print(tile_data)
|
Reference in New Issue
Block a user