wip
This commit is contained in:
@@ -67,14 +67,15 @@ internal class JoinSuccessHandler : Handler
|
||||
var ownerId = buffer.ReadString();
|
||||
var min = buffer.ReadUShort();
|
||||
var max = buffer.ReadUShort();
|
||||
var map = buffer.ReadString();
|
||||
var sceneName = buffer.ReadString();
|
||||
|
||||
var scene = new RagonScene(_client, _playerCache, _entityCache);
|
||||
var scene = new RagonScene(_client, _playerCache, _entityCache, sceneName);
|
||||
var roomInfo = new RagonRoomInformation(roomId, localId, ownerId, min, max);
|
||||
var room = new RagonRoom(_client, _entityCache, _playerCache, roomInfo, scene);
|
||||
|
||||
_playerCache.SetOwnerAndLocal(ownerId, localId);
|
||||
_client.AssignRoom(room);
|
||||
_listenerList.OnLevel(map);
|
||||
|
||||
_listenerList.OnSceneRequest(sceneName);
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,8 @@ internal class SceneLoadHandler: Handler
|
||||
var room = _client.Room;
|
||||
|
||||
room.Cleanup();
|
||||
room.Update(sceneName);
|
||||
|
||||
_listenerList.OnLevel(sceneName);
|
||||
_listenerList.OnSceneRequest(sceneName);
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,9 @@ internal class SnapshotHandler : Handler
|
||||
entity.Attach(_client, entityId, entityType, hasAuthority, player);
|
||||
}
|
||||
|
||||
_listenerList.OnJoined();
|
||||
if (_client.Status != RagonStatus.ROOM)
|
||||
_listenerList.OnJoined();
|
||||
|
||||
_listenerList.OnSceneLoaded();
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,11 @@ namespace Ragon.Client
|
||||
IRagonFailedListener,
|
||||
IRagonJoinListener,
|
||||
IRagonLeftListener,
|
||||
IRagonLevelListener,
|
||||
IRagonSceneListener,
|
||||
IRagonOwnershipChangedListener,
|
||||
IRagonPlayerJoinListener,
|
||||
IRagonPlayerLeftListener
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -16,7 +16,7 @@
|
||||
|
||||
namespace Ragon.Client;
|
||||
|
||||
public interface IRagonLevelListener
|
||||
public interface IRagonSceneListener
|
||||
{
|
||||
void OnLevel(RagonClient client, string sceneName);
|
||||
void OnSceneLoaded(RagonClient client);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Ragon.Client;
|
||||
|
||||
public interface IRagonSceneRequestListener
|
||||
{
|
||||
void OnRequestScene(RagonClient client, string sceneName);
|
||||
}
|
||||
@@ -162,7 +162,7 @@ namespace Ragon.Client
|
||||
public void AddListener(IRagonFailedListener listener) => _listenerList.Add(listener);
|
||||
public void AddListener(IRagonJoinListener listener) => _listenerList.Add(listener);
|
||||
public void AddListener(IRagonLeftListener listener) => _listenerList.Add(listener);
|
||||
public void AddListener(IRagonLevelListener listener) => _listenerList.Add(listener);
|
||||
public void AddListener(IRagonSceneListener listener) => _listenerList.Add(listener);
|
||||
public void AddListener(IRagonOwnershipChangedListener listener) => _listenerList.Add(listener);
|
||||
public void AddListener(IRagonPlayerJoinListener listener) => _listenerList.Add(listener);
|
||||
public void AddListener(IRagonPlayerLeftListener listener) => _listenerList.Add(listener);
|
||||
@@ -173,7 +173,7 @@ namespace Ragon.Client
|
||||
public void RemoveListener(IRagonFailedListener listener) => _listenerList.Remove(listener);
|
||||
public void RemoveListener(IRagonJoinListener listener) => _listenerList.Remove(listener);
|
||||
public void RemoveListener(IRagonLeftListener listener) => _listenerList.Remove(listener);
|
||||
public void RemoveListener(IRagonLevelListener listener) => _listenerList.Remove(listener);
|
||||
public void RemoveListener(IRagonSceneListener listener) => _listenerList.Remove(listener);
|
||||
public void RemoveListener(IRagonOwnershipChangedListener listener) => _listenerList.Remove(listener);
|
||||
public void RemoveListener(IRagonPlayerJoinListener listener) => _listenerList.Remove(listener);
|
||||
public void RemoveListener(IRagonPlayerLeftListener listener) => _listenerList.Remove(listener);
|
||||
|
||||
@@ -26,7 +26,8 @@ namespace Ragon.Client
|
||||
private readonly List<IRagonFailedListener> _failedListeners = new();
|
||||
private readonly List<IRagonJoinListener> _joinListeners = new();
|
||||
private readonly List<IRagonLeftListener> _leftListeners = new();
|
||||
private readonly List<IRagonLevelListener> _levelListeners = new();
|
||||
private readonly List<IRagonSceneListener> _sceneListeners = new();
|
||||
private readonly List<IRagonSceneRequestListener> _sceneRequestListeners = new();
|
||||
private readonly List<IRagonOwnershipChangedListener> _ownershipChangedListeners = new();
|
||||
private readonly List<IRagonPlayerJoinListener> _playerJoinListeners = new();
|
||||
private readonly List<IRagonPlayerLeftListener> _playerLeftListeners = new();
|
||||
@@ -44,7 +45,7 @@ namespace Ragon.Client
|
||||
_failedListeners.Add(listener);
|
||||
_joinListeners.Add(listener);
|
||||
_leftListeners.Add(listener);
|
||||
_levelListeners.Add(listener);
|
||||
_sceneListeners.Add(listener);
|
||||
_ownershipChangedListeners.Add(listener);
|
||||
_playerJoinListeners.Add(listener);
|
||||
_playerLeftListeners.Add(listener);
|
||||
@@ -59,7 +60,7 @@ namespace Ragon.Client
|
||||
_failedListeners.Remove(listener);
|
||||
_joinListeners.Remove(listener);
|
||||
_leftListeners.Remove(listener);
|
||||
_levelListeners.Remove(listener);
|
||||
_sceneListeners.Remove(listener);
|
||||
_ownershipChangedListeners.Remove(listener);
|
||||
_playerJoinListeners.Remove(listener);
|
||||
_playerLeftListeners.Remove(listener);
|
||||
@@ -80,6 +81,11 @@ namespace Ragon.Client
|
||||
_authorizationListeners.Add(listener);
|
||||
}
|
||||
|
||||
public void Add(IRagonSceneRequestListener listener)
|
||||
{
|
||||
_sceneRequestListeners.Add(listener);
|
||||
}
|
||||
|
||||
public void Add(IRagonConnectionListener listener)
|
||||
{
|
||||
_connectionListeners.Add(listener);
|
||||
@@ -100,9 +106,9 @@ namespace Ragon.Client
|
||||
_leftListeners.Add(listener);
|
||||
}
|
||||
|
||||
public void Add(IRagonLevelListener listener)
|
||||
public void Add(IRagonSceneListener listener)
|
||||
{
|
||||
_levelListeners.Add(listener);
|
||||
_sceneListeners.Add(listener);
|
||||
}
|
||||
|
||||
public void Add(IRagonOwnershipChangedListener listener)
|
||||
@@ -120,6 +126,11 @@ namespace Ragon.Client
|
||||
_playerLeftListeners.Add(listener);
|
||||
}
|
||||
|
||||
public void Remove(IRagonSceneRequestListener listener)
|
||||
{
|
||||
_delayedActions.Add(() => _sceneRequestListeners.Remove(listener));
|
||||
}
|
||||
|
||||
public void Remove(IRagonAuthorizationListener listener)
|
||||
{
|
||||
_delayedActions.Add(() => _authorizationListeners.Remove(listener));
|
||||
@@ -146,9 +157,9 @@ namespace Ragon.Client
|
||||
_delayedActions.Add(() => _leftListeners.Remove(listener));
|
||||
}
|
||||
|
||||
public void Remove(IRagonLevelListener listener)
|
||||
public void Remove(IRagonSceneListener listener)
|
||||
{
|
||||
_delayedActions.Add(() => _levelListeners.Remove(listener));
|
||||
_delayedActions.Add(() => _sceneListeners.Remove(listener));
|
||||
}
|
||||
|
||||
public void Remove(IRagonOwnershipChangedListener listener)
|
||||
@@ -208,10 +219,16 @@ namespace Ragon.Client
|
||||
listener.OnPlayerJoined(_client, player);
|
||||
}
|
||||
|
||||
public void OnLevel(string sceneName)
|
||||
public void OnSceneLoaded()
|
||||
{
|
||||
foreach (var listener in _levelListeners)
|
||||
listener.OnLevel(_client, sceneName);
|
||||
foreach (var listener in _sceneListeners)
|
||||
listener.OnSceneLoaded(_client);
|
||||
}
|
||||
|
||||
public void OnSceneRequest(string sceneName)
|
||||
{
|
||||
foreach (var listener in _sceneRequestListeners)
|
||||
listener.OnRequestScene(_client, sceneName);
|
||||
}
|
||||
|
||||
public void OnJoined()
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace Ragon.Client
|
||||
public string Id => _information.RoomId;
|
||||
public int MinPlayers => _information.Min;
|
||||
public int MaxPlayers => _information.Max;
|
||||
public string Scene => _scene.Name;
|
||||
|
||||
public IReadOnlyList<RagonPlayer> Players => _playerCache.Players;
|
||||
public RagonPlayer Local => _playerCache.Local;
|
||||
@@ -51,7 +52,12 @@ namespace Ragon.Client
|
||||
_playerCache.Cleanup();
|
||||
}
|
||||
|
||||
public void LoadScene(string map) => _scene.Load(map);
|
||||
internal void Update(string sceneName)
|
||||
{
|
||||
_scene.Update(sceneName);
|
||||
}
|
||||
|
||||
public void LoadScene(string sceneName) => _scene.Load(sceneName);
|
||||
public void SceneLoaded() => _scene.SceneLoaded();
|
||||
|
||||
public void CreateEntity(RagonEntity entity) => CreateEntity(entity, null);
|
||||
|
||||
@@ -20,24 +20,33 @@ namespace Ragon.Client;
|
||||
|
||||
public class RagonScene
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
|
||||
private readonly RagonClient _client;
|
||||
private readonly RagonEntityCache _entityCache;
|
||||
private readonly RagonPlayerCache _playerCache;
|
||||
|
||||
public RagonScene(RagonClient client, RagonPlayerCache playerCache, RagonEntityCache entityCache)
|
||||
public RagonScene(RagonClient client, RagonPlayerCache playerCache, RagonEntityCache entityCache, string sceneName)
|
||||
{
|
||||
Name = sceneName;
|
||||
|
||||
_client = client;
|
||||
_playerCache = playerCache;
|
||||
_entityCache = entityCache;
|
||||
}
|
||||
|
||||
internal void Load(string map)
|
||||
internal void Update(string scene)
|
||||
{
|
||||
Name = scene;
|
||||
}
|
||||
|
||||
internal void Load(string sceneName)
|
||||
{
|
||||
var buffer = _client.Buffer;
|
||||
|
||||
buffer.Clear();
|
||||
buffer.WriteOperation(RagonOperation.LOAD_SCENE);
|
||||
buffer.WriteString(map);
|
||||
buffer.WriteString(sceneName);
|
||||
|
||||
var sendData = buffer.ToArray();
|
||||
_client.Reliable.Send(sendData);
|
||||
|
||||
@@ -29,9 +29,9 @@ namespace Ragon.Client
|
||||
_buffer = buffer;
|
||||
}
|
||||
|
||||
public void CreateOrJoin(string map, int minPlayers, int maxPlayers)
|
||||
public void CreateOrJoin(string sceneName, int minPlayers, int maxPlayers)
|
||||
{
|
||||
var parameters = new RagonRoomParameters() {Map = map, Min = minPlayers, Max = maxPlayers};
|
||||
var parameters = new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers};
|
||||
CreateOrJoin(parameters);
|
||||
}
|
||||
|
||||
@@ -46,14 +46,14 @@ namespace Ragon.Client
|
||||
_client.Reliable.Send(sendData);
|
||||
}
|
||||
|
||||
public void Create(string map, int minPlayers, int maxPlayers)
|
||||
public void Create(string sceneName, int minPlayers, int maxPlayers)
|
||||
{
|
||||
Create(null, new RagonRoomParameters() {Map = map, Min = minPlayers, Max = maxPlayers});
|
||||
Create(null, new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers});
|
||||
}
|
||||
|
||||
public void Create(string roomId, string map, int minPlayers, int maxPlayers)
|
||||
public void Create(string roomId, string sceneNa, int minPlayers, int maxPlayers)
|
||||
{
|
||||
Create(roomId, new RagonRoomParameters() {Map = map, Min = minPlayers, Max = maxPlayers});
|
||||
Create(roomId, new RagonRoomParameters() {Scene = sceneNa, Min = minPlayers, Max = maxPlayers});
|
||||
}
|
||||
|
||||
public void Create(string roomId, RagonRoomParameters parameters)
|
||||
|
||||
Reference in New Issue
Block a user