refactor checkerboard (#18359)
This commit is contained in:
@@ -9,74 +9,96 @@ namespace Content.Server.Tabletop
|
||||
public sealed partial class TabletopCheckerSetup : TabletopSetup
|
||||
{
|
||||
|
||||
// TODO: Un-hardcode the rest of entity prototype IDs, probably.
|
||||
[DataField("prototypePieceWhite", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string PrototypePieceWhite = default!;
|
||||
|
||||
[DataField("prototypeCrownWhite", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string PrototypeCrownWhite = default!;
|
||||
|
||||
[DataField("prototypePieceBlack", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string PrototypePieceBlack = default!;
|
||||
|
||||
[DataField("prototypeCrownBlack", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string PrototypeCrownBlack = default!;
|
||||
|
||||
public override void SetupTabletop(TabletopSession session, IEntityManager entityManager)
|
||||
{
|
||||
var checkerboard = entityManager.SpawnEntity(BoardPrototype, session.Position.Offset(-1, 0));
|
||||
|
||||
session.Entities.Add(checkerboard);
|
||||
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 topLeft, float separation = 1f)
|
||||
private void SpawnPieces(TabletopSession session, IEntityManager entityManager, MapCoordinates left)
|
||||
{
|
||||
var (mapId, x, y) = topLeft;
|
||||
static float GetOffset(float offset) => offset * 1f /* separation */;
|
||||
|
||||
// Spawn all black pieces
|
||||
SpawnPieces(session, entityManager, "Black", topLeft, separation);
|
||||
Span<EntityUid> pieces = stackalloc EntityUid[42];
|
||||
var pieceIndex = 0;
|
||||
|
||||
// Spawn all white pieces
|
||||
SpawnPieces(session, entityManager, "White", new MapCoordinates(x, y - 7 * separation, mapId), separation);
|
||||
|
||||
// Queens
|
||||
for (int i = 1; i < 4; i++)
|
||||
// Pieces
|
||||
for (var offsetY = 0; offsetY < 3; offsetY++)
|
||||
{
|
||||
EntityUid tempQualifier = entityManager.SpawnEntity("BlackCheckerQueen", new MapCoordinates(x + 9 * separation + 9f / 32, y - (i - 1) * separation, mapId));
|
||||
session.Entities.Add(tempQualifier);
|
||||
var checker = offsetY % 2;
|
||||
|
||||
EntityUid tempQualifier1 = entityManager.SpawnEntity("WhiteCheckerQueen", new MapCoordinates(x + 8 * separation + 9f / 32, y - (i - 1) * separation, mapId));
|
||||
session.Entities.Add(tempQualifier1);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
var spares = new List<EntityUid>();
|
||||
for (var i = 1; i < 7; i++)
|
||||
{
|
||||
var step = 3 + 0.25f * (i - 1);
|
||||
spares.Add(
|
||||
entityManager.SpawnEntity("BlackCheckerPiece",
|
||||
new MapCoordinates(x + 9 * separation + 9f / 32, y - step * separation, mapId)
|
||||
));
|
||||
const int NumCrowns = 3;
|
||||
const float Overlap = 0.25f;
|
||||
const float xOffset = 9f / 32;
|
||||
const float xOffsetBlack = 9 + xOffset;
|
||||
const float xOffsetWhite = 8 + xOffset;
|
||||
|
||||
spares.Add(
|
||||
entityManager.SpawnEntity("WhiteCheckerPiece",
|
||||
new MapCoordinates(x + 8 * separation + 9f / 32, y - step * separation, mapId)
|
||||
));
|
||||
// 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;
|
||||
}
|
||||
session.Entities.UnionWith(spares);
|
||||
}
|
||||
|
||||
private void SpawnPieces(TabletopSession session, IEntityManager entityManager, string color, MapCoordinates left, float separation = 1f)
|
||||
{
|
||||
var (mapId, x, y) = left;
|
||||
// If white is being placed it must go from bottom->up
|
||||
var reversed = (color == "White") ? 1 : -1;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
// Spares
|
||||
for (var i = 0; i < 6; i++)
|
||||
{
|
||||
var x_offset = i % 2;
|
||||
if (reversed == -1) x_offset = 1 - x_offset; // Flips it
|
||||
|
||||
for (int j = 0; j < 8; j += 2)
|
||||
{
|
||||
// Prevents an extra piece on the middle row
|
||||
if (x_offset + j > 8) continue;
|
||||
|
||||
EntityUid tempQualifier4 = entityManager.SpawnEntity(color + "CheckerPiece", new MapCoordinates(x + (j + x_offset) * separation, y + i * reversed * separation, mapId));
|
||||
session.Entities.Add(tempQualifier4);
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,15 @@
|
||||
size: 338, 274
|
||||
setup:
|
||||
!type:TabletopCheckerSetup
|
||||
boardPrototype: CheckerBoardTabletop
|
||||
boardPrototype: &checkerboard CheckerBoardTabletop
|
||||
prototypePieceWhite: &pieceWhite CheckerPieceWhite
|
||||
prototypeCrownWhite: &crownWhite CheckerCrownWhite
|
||||
prototypePieceBlack: &pieceBlack CheckerPieceBlack
|
||||
prototypeCrownBlack: &crownBlack CheckerCrownBlack
|
||||
|
||||
# Checkerboard tabletop item (item only visible in tabletop game)
|
||||
- type: entity
|
||||
id: CheckerBoardTabletop
|
||||
id: *checkerboard
|
||||
name: checkerboard
|
||||
parent: BaseBoardTabletop
|
||||
noSpawn: true
|
||||
@@ -28,8 +32,8 @@
|
||||
|
||||
# The pieces
|
||||
- type: entity
|
||||
id: WhiteCheckerPiece
|
||||
name: white piece
|
||||
id: *pieceWhite
|
||||
name: white checker piece
|
||||
parent: BaseTabletopPiece
|
||||
components:
|
||||
- type: Sprite
|
||||
@@ -37,17 +41,17 @@
|
||||
state: w_checker_piece
|
||||
|
||||
- type: entity
|
||||
id: WhiteCheckerQueen
|
||||
name: white queen
|
||||
id: *crownWhite
|
||||
name: white checker crown
|
||||
parent: BaseTabletopPiece
|
||||
components:
|
||||
- type: Sprite
|
||||
sprite: Objects/Fun/Tabletop/checker_pieces.rsi
|
||||
state: w_checker_queen
|
||||
state: w_checker_crown
|
||||
|
||||
- type: entity
|
||||
id: BlackCheckerPiece
|
||||
name: black piece
|
||||
id: *pieceBlack
|
||||
name: black checker piece
|
||||
parent: BaseTabletopPiece
|
||||
components:
|
||||
- type: Sprite
|
||||
@@ -55,10 +59,10 @@
|
||||
state: b_checker_piece
|
||||
|
||||
- type: entity
|
||||
id: BlackCheckerQueen
|
||||
name: black queen
|
||||
id: *crownBlack
|
||||
name: black checker crown
|
||||
parent: BaseTabletopPiece
|
||||
components:
|
||||
- type: Sprite
|
||||
sprite: Objects/Fun/Tabletop/checker_pieces.rsi
|
||||
state: b_checker_queen
|
||||
state: b_checker_crown
|
||||
|
||||
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
@@ -11,13 +11,13 @@
|
||||
"name": "w_checker_piece"
|
||||
},
|
||||
{
|
||||
"name": "w_checker_queen"
|
||||
"name": "w_checker_crown"
|
||||
},
|
||||
{
|
||||
"name": "b_checker_piece"
|
||||
},
|
||||
{
|
||||
"name": "b_checker_queen"
|
||||
"name": "b_checker_crown"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Reference in New Issue
Block a user