CatStation/Content.Shared/Tabletop/TabletopCheckerSetup.cs
riccardi48 95a5f7c7de
Table top prediction (#44348)
* TabletopSystem-move-to-shared

* final refactor

* Update TabletopHologramComponent.cs

* Update AdminVerbSystem.Smites.cs

* merge

* line

* prediction fix

* Fix the scrunkly

* Also noticed this

---------

Co-authored-by: Pok245 <113675512+Pok27@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2026-06-27 11:17:13 +00:00

102 lines
3.5 KiB
C#

using JetBrains.Annotations;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Tabletop;
[UsedImplicitly]
public sealed partial class TabletopCheckerSetup : TabletopSetup
{
[DataField(customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string PrototypePieceWhite = default!;
[DataField(customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string PrototypeCrownWhite = default!;
[DataField(customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string PrototypePieceBlack = default!;
[DataField(customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string PrototypeCrownBlack = default!;
public override void SetupTabletop(TabletopSession session, IEntityManager entityManager)
{
session.Entities.Add(
entityManager.SpawnEntity(BoardPrototype, session.Position.Offset(-1, 0))
);
SpawnPieces(session, entityManager, session.Position.Offset(-4.5f, 3.5f));
}
private void SpawnPieces(TabletopSession session, IEntityManager entityManager, MapCoordinates left)
{
static float GetOffset(float offset) => offset * 1f /* separation */;
var pieces = new EntityUid[42];
var pieceIndex = 0;
// Pieces.
for (var offsetY = 0; offsetY < 3; offsetY++)
{
var checker = offsetY % 2;
for (var offsetX = 0; offsetX < 8; offsetX += 2)
{
// Prevents an extra piece on the middle row.
if (checker + offsetX > 8) continue;
pieces[pieceIndex] = entityManager.SpawnEntity(
PrototypePieceBlack,
left.Offset(GetOffset(offsetX + (1 - checker)), GetOffset(offsetY * -1))
);
pieces[pieceIndex] = entityManager.SpawnEntity(
PrototypePieceWhite,
left.Offset(GetOffset(offsetX + checker), GetOffset(offsetY - 7))
);
pieceIndex += 2;
}
}
const int numCrowns = 3;
const float overlap = 0.25f;
const float xOffset = 9f / 32;
const float xOffsetBlack = 9 + xOffset;
const float xOffsetWhite = 8 + xOffset;
// Crowns.
for (var i = 0; i < numCrowns; i++)
{
var step = -(overlap * i);
pieces[pieceIndex] = entityManager.SpawnEntity(
PrototypeCrownBlack,
left.Offset(GetOffset(xOffsetBlack), GetOffset(step))
);
pieces[pieceIndex + 1] = entityManager.SpawnEntity(
PrototypeCrownWhite,
left.Offset(GetOffset(xOffsetWhite), GetOffset(step))
);
pieceIndex += 2;
}
// Spares.
for (var i = 0; i < 6; i++)
{
var step = -(overlap * (numCrowns + 2) + overlap * i);
pieces[pieceIndex] = entityManager.SpawnEntity(
PrototypePieceBlack,
left.Offset(GetOffset(xOffsetBlack), GetOffset(step))
);
pieces[pieceIndex] = entityManager.SpawnEntity(
PrototypePieceWhite,
left.Offset(GetOffset(xOffsetWhite), GetOffset(step))
);
pieceIndex += 2;
}
for (var i = 0; i < pieces.Length; i++)
{
session.Entities.Add(pieces[i]);
}
}
}