mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-02-15 00:34:44 +01:00
* WORK IN PROGRESS 1 * ITS ALIVE, ALIVE!!!! * clean up * WIP 1 * fix small oversight * big diff of doom * added CVAR to tile history stack size * component time * filescoped namespaces + remove redundant nametag * fix silly little mistakes * typo * TileStacksTest * bweeeeeeh :P * nuke cvar * :3 * WIP2025 * Fix submodule * It's beginning to look a lot like Christmas * It's the Most Wonderful Time of the Year * tiny fix * fixed extra spacing on yaml * slightly improve tilestacking test * Part 1 out of 2 (part 2 tomorrow) * Part 2 * add a simple tile construction test for tilestacking * guh * address reviews (no documentation yet) * documentation be upon ye * remove extra spaces * prediction fix * dirt * oops :p --------- Co-authored-by: Killerqu00 <killerqueen1777@gmail.com> Co-authored-by: Killerqu00 <47712032+Killerqu00@users.noreply.github.com> Co-authored-by: ScarKy0 <scarky0@onet.eu>
75 lines
2.9 KiB
C#
75 lines
2.9 KiB
C#
using System.Numerics;
|
|
using Content.Shared.Maps;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Map.Components;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Server.Maps;
|
|
|
|
/// <summary>
|
|
/// This system handles transferring <see cref="TileHistoryComponent"/> data when a grid is split.
|
|
/// </summary>
|
|
public sealed class TileGridSplitSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedMapSystem _maps = default!;
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<GridSplitEvent>(OnGridSplit);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Transfer tile history from the old grid to the new grids.
|
|
/// </summary>
|
|
private void OnGridSplit(ref GridSplitEvent ev)
|
|
{
|
|
if (!TryComp<TileHistoryComponent>(ev.Grid, out var oldHistory))
|
|
return;
|
|
|
|
var oldGrid = Comp<MapGridComponent>(ev.Grid);
|
|
|
|
foreach (var gridUid in ev.NewGrids)
|
|
{
|
|
// ensure the new grid has a history component and get its grid component
|
|
var newHistory = EnsureComp<TileHistoryComponent>(gridUid);
|
|
var newGrid = Comp<MapGridComponent>(gridUid);
|
|
|
|
foreach (var tile in _maps.GetAllTiles(gridUid, newGrid))
|
|
{
|
|
// calculate where this tile was on the old grid
|
|
var oldIndices = _maps.LocalToTile(ev.Grid, oldGrid, new EntityCoordinates(gridUid, new Vector2(tile.GridIndices.X + 0.5f, tile.GridIndices.Y + 0.5f)));
|
|
|
|
var chunkIndices = SharedMapSystem.GetChunkIndices(oldIndices, TileSystem.ChunkSize);
|
|
if (oldHistory.ChunkHistory.TryGetValue(chunkIndices, out var oldChunk) &&
|
|
oldChunk.History.TryGetValue(oldIndices, out var history))
|
|
{
|
|
// now we move the history from the old grid to the new grid
|
|
var newChunkIndices = SharedMapSystem.GetChunkIndices(tile.GridIndices, TileSystem.ChunkSize);
|
|
if (!newHistory.ChunkHistory.TryGetValue(newChunkIndices, out var newChunk))
|
|
{
|
|
newChunk = new TileHistoryChunk();
|
|
newHistory.ChunkHistory[newChunkIndices] = newChunk;
|
|
}
|
|
|
|
newChunk.History[tile.GridIndices] = new List<ProtoId<ContentTileDefinition>>(history);
|
|
newChunk.LastModified = _timing.CurTick;
|
|
|
|
// clean up the old history
|
|
oldChunk.History.Remove(oldIndices);
|
|
if (oldChunk.History.Count == 0)
|
|
oldHistory.ChunkHistory.Remove(chunkIndices);
|
|
else
|
|
oldChunk.LastModified = _timing.CurTick;
|
|
}
|
|
}
|
|
|
|
Dirty(gridUid, newHistory);
|
|
}
|
|
|
|
Dirty(ev.Grid, oldHistory);
|
|
}
|
|
}
|