World Editor fixes
This commit is contained in:
@@ -11,6 +11,13 @@ public sealed class WorldEditDeltaHub
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, ConcurrentDictionary<Guid, Channel<string>>> _subscribers = new();
|
||||
|
||||
/// <summary>
|
||||
/// Fired for every delta publish, regardless of chunk key.
|
||||
/// Parameters: (chunkKey, deltaJson).
|
||||
/// Used by WorldHandler to forward live edits to game clients.
|
||||
/// </summary>
|
||||
public event Action<string, string>? OnDeltaPublished;
|
||||
|
||||
public WorldEditSubscription Subscribe(string key)
|
||||
{
|
||||
var channel = Channel.CreateUnbounded<string>(new UnboundedChannelOptions
|
||||
@@ -28,16 +35,19 @@ public sealed class WorldEditDeltaHub
|
||||
|
||||
public void Publish(string key, object payload)
|
||||
{
|
||||
if (!_subscribers.TryGetValue(key, out var bucket) || bucket.Count == 0)
|
||||
var json = JsonSerializer.Serialize(payload);
|
||||
|
||||
// Notify channel-based subscribers (admin editor WebSocket streams)
|
||||
if (_subscribers.TryGetValue(key, out var bucket) && bucket.Count > 0)
|
||||
{
|
||||
return;
|
||||
foreach (var (_, channel) in bucket)
|
||||
{
|
||||
channel.Writer.TryWrite(json);
|
||||
}
|
||||
}
|
||||
|
||||
var json = JsonSerializer.Serialize(payload);
|
||||
foreach (var (_, channel) in bucket)
|
||||
{
|
||||
channel.Writer.TryWrite(json);
|
||||
}
|
||||
// Notify global listeners (game client delta forwarding)
|
||||
OnDeltaPublished?.Invoke(key, json);
|
||||
}
|
||||
|
||||
private void Unsubscribe(string key, Guid id)
|
||||
|
||||
Reference in New Issue
Block a user