diff --git a/game/autoload/Server.gd b/game/autoload/Server.gd index bb827dbb..56552c15 100644 --- a/game/autoload/Server.gd +++ b/game/autoload/Server.gd @@ -56,6 +56,10 @@ func start_hosting(p_port : int = 0) -> int: var peer : NetworkedMultiplayerENet = NetworkedMultiplayerENet.new() var err : int = peer.create_server(p_port, 32) + + if err: + return err + get_tree().set_network_peer(peer) _connected_to_server() @@ -185,7 +189,7 @@ remotesync func cspawn_player(info : Dictionary, sid : int, pos : Vector3): Logger.verbose("NetworkManager cspawn_player") if sid == get_tree().get_network_unique_id(): - local_player_master.player = ESS.get_ess_entity_spawner().spawn_player(info["selected_class"] as int, pos, info["name"] as String, str(sid), sid) + local_player_master.player = ESS.entity_spawner.spawn_player(info["selected_class"] as int, pos, info["name"] as String, str(sid), sid) call_deferred("set_terrarin_player") if get_tree().is_network_server() and not splayers_dict.has(sid): @@ -195,7 +199,7 @@ remotesync func cspawn_player(info : Dictionary, sid : int, pos : Vector3): var pm : PlayerMaster = PlayerMaster.new() pm.sid = sid - pm.player = ESS.get_ess_entity_spawner().spawn_networked_player(info["selected_class"] as int, pos, info["name"] as String, str(sid), sid) + pm.player = ESS.entity_spawner.spawn_networked_player(info["selected_class"] as int, pos, info["name"] as String, str(sid), sid) if get_tree().is_network_server() and not splayers_dict.has(sid): splayers_dict[sid] = pm @@ -209,11 +213,11 @@ func upload_character(data : String) -> void: rpc_id(1, "sreceive_upload_character", data) master func sreceive_upload_character(data: String) -> void: - ESS.get_ess_entity_spawner().spawn_networked_player_from_data(data, Vector3(0, 10, 0), multiplayer.get_rpc_sender_id()) - + ESS.entity_spawner.load_uploaded_character(data, Vector3(0, 10, 0), multiplayer.get_rpc_sender_id()) + func set_terrarin_player(): Logger.verbose("NetworkManager cspawn_player") - var terrarin : TerraWorld = get_node("/root/GameScene/VoxelWorld") + var terrarin : TerraWorld = get_node("/root/main/World") terrarin.set_player(local_player_master.player.get_body() as Spatial) diff --git a/game/player/bs_entity_spawner.gd b/game/player/bs_entity_spawner.gd index 8502619b..1ccd2d0a 100644 --- a/game/player/bs_entity_spawner.gd +++ b/game/player/bs_entity_spawner.gd @@ -52,11 +52,11 @@ func on_network_peer_packet(id : int, packet : PoolByteArray) ->void: func spawn_for(player : Entity, target: Entity) -> void: Logger.info("spawnfor " + target.name) -# rpc_id(player.get_network_master(), "creceive_spawn_for", to_json(target.to_dict()), target.name, target.translation) + rpc_id(player.get_network_master(), "creceive_spawn_for", to_json(target.to_dict()), target.name, target.translation) func despawn_for(player : Entity, target: Entity) -> void: Logger.info("despawnfor " + target.name) -# rpc_id(player.get_network_master(), "creceive_despawn_for", target.get_path()) + rpc_id(player.get_network_master(), "creceive_despawn_for", target.get_path()) remote func creceive_spawn_for(data: String, global_name : String, position: Vector3) -> Entity: var createinfo : EntityCreateInfo = EntityCreateInfo.new() @@ -112,6 +112,22 @@ func load_player(file_name : String, position : Vector3, network_owner : int) -> return createinfo.created_entity +func load_uploaded_character(data : String, position : Vector3, network_owner : int) -> Entity: + var createinfo : EntityCreateInfo = EntityCreateInfo.new() + + createinfo.guid = _next_entity_guid + _next_entity_guid += 1 +# createinfo.player_name = name + createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_PLAYER + createinfo.entity_player_type = EntityEnums.ENTITY_PLAYER_TYPE_PLAYER + createinfo.serialized_data = parse_json(data) + createinfo.transform.origin = position + createinfo.networked = false + Logger.info("Player spawned ") + ESS.request_entity_spawn(createinfo) + + return createinfo.created_entity + func spawn_player_for_menu(class_id : int, name : String, parent : Node) -> Entity: var createinfo : EntityCreateInfo = EntityCreateInfo.new() var cls : EntityData = ESS.resource_db.get_entity_data(class_id) diff --git a/game/scenes/MainScene.gd b/game/scenes/MainScene.gd index 2e3924cf..092010d5 100644 --- a/game/scenes/MainScene.gd +++ b/game/scenes/MainScene.gd @@ -107,4 +107,6 @@ func show_loading_screen() -> void: func hide_loading_screen() -> void: _loading_screen.hide() - + +func switch_scene_to_world() -> void: + switch_scene(StartSceneTypes.WORLD)