Added Checkers (#6219)

This commit is contained in:
Demetre Beroshvili
2022-01-18 15:44:24 -08:00
committed by GitHub
parent d4e89ecbfd
commit facb2ea849
9 changed files with 175 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Tabletop
{
[UsedImplicitly]
public class TabletopCheckerSetup : TabletopSetup
{
[DataField("boardPrototype", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
public string CheckerBoardPrototype { get; } = "CheckerBoardTabletop";
// TODO: Un-hardcode the rest of entity prototype IDs, probably.
public override void SetupTabletop(TabletopSession session, IEntityManager entityManager)
{
var checkerboard = entityManager.SpawnEntity(CheckerBoardPrototype, session.Position.Offset(-1, 0));
session.Entities.Add(checkerboard);
SpawnPieces(session, entityManager, session.Position.Offset(-4.5f, 3.5f));
}
private void SpawnPieces(TabletopSession session, IEntityManager entityManager, MapCoordinates topLeft, float separation = 1f)
{
var (mapId, x, y) = topLeft;
// Spawn all black pieces
SpawnPieces(session, entityManager, "Black", topLeft, separation);
// Spawn all white pieces
SpawnPieces(session, entityManager, "White", new MapCoordinates(x, y - 7 * separation, mapId), separation);
// Queens
for (int i = 1; i < 4; i++)
{
EntityUid tempQualifier = entityManager.SpawnEntity("BlackCheckerQueen", new MapCoordinates(x + 9 * separation + 9f / 32, y - i * separation, mapId));
session.Entities.Add(tempQualifier);
EntityUid tempQualifier1 = entityManager.SpawnEntity("WhiteCheckerQueen", new MapCoordinates(x + 8 * separation + 9f / 32, y - i * separation, mapId));
session.Entities.Add(tempQualifier1);
}
}
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
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);
}
}
}
}
}

View File

@@ -11,3 +11,6 @@ tabletop-parchis-board-name = Parchís
## Backgammon
tabletop-backgammon-board-name = Backgammon
## Checkers
tabletop-checkers-board-name = Checkers

View File

@@ -82,5 +82,7 @@
amount: 1
- id: ParchisBoard
amount: 1
- id: CheckerBoard
amount: 1
- id: d6Dice
amount: 4

View File

@@ -0,0 +1,76 @@
# Uses the chessboard and generic pieces
- type: entity
parent: BaseItem
id: CheckerBoard
name: checkerboard
description: A checkerboard. Pieces included!
components:
- type: Sprite
sprite: Objects/Fun/Tabletop/chessboard.rsi
state: chessboard
- type: TabletopGame
boardName: tabletop-checkers-board-name
size: 338, 274
setup: !type:TabletopCheckerSetup
# Checkerboard tabletop item (item only visible in tabletop game)
- type: entity
id: CheckerBoardTabletop
name: checkerboard
abstract: true
components:
- type: Sprite
sprite: Objects/Fun/Tabletop/chessboard_tabletop.rsi
state: chessboard_tabletop
noRot: false
drawdepth: FloorTiles
- type: entity
id: BaseCheckerPiece
parent: BaseItem
abstract: true
components:
- type: TabletopDraggable
- type: Sprite
netsync: false
noRot: true
- type: Appearance
visuals:
- type: TabletopItemVisualizer
# The pieces
- type: entity
id: WhiteCheckerPiece
name: white piece
parent: BaseCheckerPiece
components:
- type: Sprite
sprite: Objects/Fun/Tabletop/checker_pieces.rsi
state: w_checker_piece
- type: entity
id: WhiteCheckerQueen
name: white queen
parent: BaseCheckerPiece
components:
- type: Sprite
sprite: Objects/Fun/Tabletop/checker_pieces.rsi
state: w_checker_queen
- type: entity
id: BlackCheckerPiece
name: black piece
parent: BaseCheckerPiece
components:
- type: Sprite
sprite: Objects/Fun/Tabletop/checker_pieces.rsi
state: b_checker_piece
- type: entity
id: BlackCheckerQueen
name: black queen
parent: BaseCheckerPiece
components:
- type: Sprite
sprite: Objects/Fun/Tabletop/checker_pieces.rsi
state: b_checker_queen

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -0,0 +1,23 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Zumorica, Fishfish458, Capnsockless",
"size": {
"x": 24,
"y": 24
},
"states": [
{
"name": "w_checker_piece"
},
{
"name": "w_checker_queen"
},
{
"name": "b_checker_piece"
},
{
"name": "b_checker_queen"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB