From 5990393e31195fb3a6431c377d02e62baa62328c Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Sun, 15 Jan 2023 13:56:20 +1300 Subject: [PATCH] Fix decal error (#13471) Fixes https://github.com/space-wizards/space-station-14/issues/13466 --- Content.Client/Decals/DecalSystem.cs | 18 ++++++++------- Content.Server/Decals/DecalSystem.cs | 1 - Content.Shared/Decals/SharedDecalSystem.cs | 26 +++++++++++++++------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Content.Client/Decals/DecalSystem.cs b/Content.Client/Decals/DecalSystem.cs index 782512c744..8d599bebdb 100644 --- a/Content.Client/Decals/DecalSystem.cs +++ b/Content.Client/Decals/DecalSystem.cs @@ -13,6 +13,8 @@ namespace Content.Client.Decals [Dependency] private readonly SpriteSystem _sprites = default!; private DecalOverlay _overlay = default!; + + // TODO move this data to the component public readonly Dictionary>> DecalRenderIndex = new(); private readonly Dictionary> _decalZIndexIndex = new(); @@ -25,8 +27,6 @@ namespace Content.Client.Decals SubscribeLocalEvent(OnHandleState); SubscribeNetworkEvent(OnChunkUpdate); - SubscribeLocalEvent(OnGridInitialize); - SubscribeLocalEvent(OnGridRemoval); } public void ToggleOverlay() @@ -41,16 +41,18 @@ namespace Content.Client.Decals } } - private void OnGridRemoval(GridRemovalEvent ev) + protected override void OnCompRemove(EntityUid uid, DecalGridComponent component, ComponentRemove args) { - DecalRenderIndex.Remove(ev.EntityUid); - _decalZIndexIndex.Remove(ev.EntityUid); + DecalRenderIndex.Remove(uid); + _decalZIndexIndex.Remove(uid); + base.OnCompRemove(uid, component, args); } - private void OnGridInitialize(GridInitializeEvent ev) + protected override void OnCompAdd(EntityUid uid, DecalGridComponent component, ComponentAdd args) { - DecalRenderIndex[ev.EntityUid] = new(); - _decalZIndexIndex[ev.EntityUid] = new(); + DecalRenderIndex[uid] = new(); + _decalZIndexIndex[uid] = new(); + base.OnCompAdd(uid, component, args); } public override void Shutdown() diff --git a/Content.Server/Decals/DecalSystem.cs b/Content.Server/Decals/DecalSystem.cs index a9cb902676..0b082c6353 100644 --- a/Content.Server/Decals/DecalSystem.cs +++ b/Content.Server/Decals/DecalSystem.cs @@ -29,7 +29,6 @@ namespace Content.Server.Decals [Dependency] private readonly ChunkingSystem _chunking = default!; [Dependency] private readonly IConfigurationManager _conf = default!; [Dependency] private readonly IGameTiming _timing = default!; - [Dependency] private readonly IDependencyCollection _dependencies = default!; private readonly Dictionary> _dirtyChunks = new(); private readonly Dictionary>> _previousSentChunks = new(); diff --git a/Content.Shared/Decals/SharedDecalSystem.cs b/Content.Shared/Decals/SharedDecalSystem.cs index e7e21ad379..01a93044a9 100644 --- a/Content.Shared/Decals/SharedDecalSystem.cs +++ b/Content.Shared/Decals/SharedDecalSystem.cs @@ -1,6 +1,4 @@ using System.Diagnostics.CodeAnalysis; -using Robust.Shared; -using Robust.Shared.Configuration; using Robust.Shared.Map; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; @@ -13,6 +11,7 @@ namespace Content.Shared.Decals [Dependency] protected readonly IPrototypeManager PrototypeManager = default!; [Dependency] protected readonly IMapManager MapManager = default!; + // TODO move this data to the component protected readonly Dictionary> ChunkIndex = new(); // Note that this constant is effectively baked into all map files, because of how they save the grid decal component. @@ -25,22 +24,33 @@ namespace Content.Shared.Decals base.Initialize(); SubscribeLocalEvent(OnGridInitialize); + SubscribeLocalEvent(OnCompAdd); + SubscribeLocalEvent(OnCompRemove); } private void OnGridInitialize(GridInitializeEvent msg) { - var comp = EntityManager.EnsureComponent(msg.EntityUid); - ChunkIndex[msg.EntityUid] = new(); - foreach (var (indices, decals) in comp.ChunkCollection.ChunkCollection) + EnsureComp(msg.EntityUid); + } + + protected virtual void OnCompRemove(EntityUid uid, DecalGridComponent component, ComponentRemove args) + { + ChunkIndex.Remove(uid); + } + + protected virtual void OnCompAdd(EntityUid uid, DecalGridComponent component, ComponentAdd args) + { + var index = ChunkIndex[uid] = new(); + foreach (var (indices, decals) in component.ChunkCollection.ChunkCollection) { - foreach (var uid in decals.Decals.Keys) + foreach (var decalUid in decals.Decals.Keys) { - ChunkIndex[msg.EntityUid][uid] = indices; + index[decalUid] = indices; } } } - protected DecalGridComponent.DecalGridChunkCollection? DecalGridChunkCollection(EntityUid gridEuid, DecalGridComponent? comp = null) + protected DecalGridChunkCollection? DecalGridChunkCollection(EntityUid gridEuid, DecalGridComponent? comp = null) { if (!Resolve(gridEuid, ref comp)) return null;