refactor checkerboard (#18359)
This commit is contained in:
@@ -9,73 +9,95 @@ namespace Content.Server.Tabletop
|
|||||||
public sealed partial class TabletopCheckerSetup : TabletopSetup
|
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)
|
public override void SetupTabletop(TabletopSession session, IEntityManager entityManager)
|
||||||
{
|
{
|
||||||
var checkerboard = entityManager.SpawnEntity(BoardPrototype, session.Position.Offset(-1, 0));
|
session.Entities.Add(
|
||||||
|
entityManager.SpawnEntity(BoardPrototype, session.Position.Offset(-1, 0))
|
||||||
session.Entities.Add(checkerboard);
|
);
|
||||||
|
|
||||||
SpawnPieces(session, entityManager, session.Position.Offset(-4.5f, 3.5f));
|
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
|
Span<EntityUid> pieces = stackalloc EntityUid[42];
|
||||||
SpawnPieces(session, entityManager, "Black", topLeft, separation);
|
var pieceIndex = 0;
|
||||||
|
|
||||||
// Spawn all white pieces
|
// Pieces
|
||||||
SpawnPieces(session, entityManager, "White", new MapCoordinates(x, y - 7 * separation, mapId), separation);
|
for (var offsetY = 0; offsetY < 3; offsetY++)
|
||||||
|
|
||||||
// Queens
|
|
||||||
for (int i = 1; i < 4; i++)
|
|
||||||
{
|
{
|
||||||
EntityUid tempQualifier = entityManager.SpawnEntity("BlackCheckerQueen", new MapCoordinates(x + 9 * separation + 9f / 32, y - (i - 1) * separation, mapId));
|
var checker = offsetY % 2;
|
||||||
session.Entities.Add(tempQualifier);
|
|
||||||
|
|
||||||
EntityUid tempQualifier1 = entityManager.SpawnEntity("WhiteCheckerQueen", new MapCoordinates(x + 8 * separation + 9f / 32, y - (i - 1) * separation, mapId));
|
for (var offsetX = 0; offsetX < 8; offsetX += 2)
|
||||||
session.Entities.Add(tempQualifier1);
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
));
|
|
||||||
|
|
||||||
spares.Add(
|
|
||||||
entityManager.SpawnEntity("WhiteCheckerPiece",
|
|
||||||
new MapCoordinates(x + 8 * separation + 9f / 32, y - step * separation, mapId)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
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++)
|
|
||||||
{
|
|
||||||
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
|
// Prevents an extra piece on the middle row
|
||||||
if (x_offset + j > 8) continue;
|
if (checker + offsetX > 8) continue;
|
||||||
|
|
||||||
EntityUid tempQualifier4 = entityManager.SpawnEntity(color + "CheckerPiece", new MapCoordinates(x + (j + x_offset) * separation, y + i * reversed * separation, mapId));
|
pieces[pieceIndex] = entityManager.SpawnEntity(
|
||||||
session.Entities.Add(tempQualifier4);
|
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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,15 @@
|
|||||||
size: 338, 274
|
size: 338, 274
|
||||||
setup:
|
setup:
|
||||||
!type:TabletopCheckerSetup
|
!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)
|
# Checkerboard tabletop item (item only visible in tabletop game)
|
||||||
- type: entity
|
- type: entity
|
||||||
id: CheckerBoardTabletop
|
id: *checkerboard
|
||||||
name: checkerboard
|
name: checkerboard
|
||||||
parent: BaseBoardTabletop
|
parent: BaseBoardTabletop
|
||||||
noSpawn: true
|
noSpawn: true
|
||||||
@@ -28,8 +32,8 @@
|
|||||||
|
|
||||||
# The pieces
|
# The pieces
|
||||||
- type: entity
|
- type: entity
|
||||||
id: WhiteCheckerPiece
|
id: *pieceWhite
|
||||||
name: white piece
|
name: white checker piece
|
||||||
parent: BaseTabletopPiece
|
parent: BaseTabletopPiece
|
||||||
components:
|
components:
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
@@ -37,17 +41,17 @@
|
|||||||
state: w_checker_piece
|
state: w_checker_piece
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: WhiteCheckerQueen
|
id: *crownWhite
|
||||||
name: white queen
|
name: white checker crown
|
||||||
parent: BaseTabletopPiece
|
parent: BaseTabletopPiece
|
||||||
components:
|
components:
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Fun/Tabletop/checker_pieces.rsi
|
sprite: Objects/Fun/Tabletop/checker_pieces.rsi
|
||||||
state: w_checker_queen
|
state: w_checker_crown
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: BlackCheckerPiece
|
id: *pieceBlack
|
||||||
name: black piece
|
name: black checker piece
|
||||||
parent: BaseTabletopPiece
|
parent: BaseTabletopPiece
|
||||||
components:
|
components:
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
@@ -55,10 +59,10 @@
|
|||||||
state: b_checker_piece
|
state: b_checker_piece
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: BlackCheckerQueen
|
id: *crownBlack
|
||||||
name: black queen
|
name: black checker crown
|
||||||
parent: BaseTabletopPiece
|
parent: BaseTabletopPiece
|
||||||
components:
|
components:
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Objects/Fun/Tabletop/checker_pieces.rsi
|
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_piece"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "w_checker_queen"
|
"name": "w_checker_crown"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "b_checker_piece"
|
"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