World Editor fixes

This commit is contained in:
dingo
2026-02-16 16:41:23 -05:00
parent 7e6d494e44
commit cae32f6157
5 changed files with 359 additions and 31 deletions
+17 -7
View File
@@ -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)