Skip to content

Commit

Permalink
Remove outdated Player serialization from Board. (terraforming-mars#2367
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kberg authored Jan 15, 2021
1 parent cf30ab8 commit 1cad8b4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 110 deletions.
5 changes: 1 addition & 4 deletions src/boards/Board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,7 @@ export abstract class Board {
}

public static deserializeSpace(serialized: SerializedSpace, players: Array<Player>): ISpace {
// TODO(kberg): Remove Player by 2021-01-15
const playerSpace : PlayerId | Player | undefined = serialized.player;
const playerId: PlayerId | undefined =
(typeof playerSpace === 'string') ? playerSpace : playerSpace?.id;
const playerId: PlayerId | undefined = serialized.player;
const player = players.find((p) => p.id === playerId);
const space = {
id: serialized.id,
Expand Down
5 changes: 2 additions & 3 deletions src/boards/SerializedBoard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IAdjacencyBonus} from '../ares/IAdjacencyBonus';
import {ITile} from '../ITile';
import {Player, PlayerId} from '../Player';
import {PlayerId} from '../Player';
import {SpaceBonus} from '../SpaceBonus';
import {SpaceType} from '../SpaceType';
import {SpaceId} from './ISpace';
Expand All @@ -13,8 +13,7 @@ export interface SerializedSpace {
id: SpaceId;
spaceType: SpaceType;
tile?: ITile;
// TODO(kberg): Remove by 2021-01-15
player?: Player | PlayerId;
player?: PlayerId;
bonus: Array<SpaceBonus>;
adjacency?: IAdjacencyBonus,
x: number;
Expand Down
103 changes: 0 additions & 103 deletions tests/boards/Board.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,109 +248,6 @@ describe('Board', function() {
}
};

it('deserialize-backward compatible', () => {
const player1 = new Player('name-1', Color.RED, false, 0, 'name-1-id');
const player2 = new Player('name-2', Color.YELLOW, false, 0, 'name-2-id');
const json = {
'spaces': [
{
'id': '01',
'spaceType': 'colony',
'bonus': [],
'x': -1,
'y': -1,
'player': {
'name': 'name-1',
'color': 'blue',
'beginner': false,
'handicap': 0,
'usedUndo': false,
'id': 'name-1-id',
},
'tile': {
'tileType': 2,
},
},
{
'id': '03',
'spaceType': 'land',
'bonus': [
1,
1,
],
'x': 4,
'y': 0,
'player': {
'name': 'name-2',
'color': 'green',
'beginner': false,
'handicap': 0,
'usedUndo': false,
'id': 'name-2-id',
},
'tile': {
'tileType': 0,
},
},
{
'id': '04',
'spaceType': 'ocean',
'bonus': [
1,
1,
],
'x': 5,
'y': 0,
'tile': {
'tileType': 1,
},
},
{
'id': '05',
'spaceType': 'land',
'bonus': [],
'x': 6,
'y': 0,
},
],
} as SerializedBoard;
const board = new TestBoard(Board.deserializeSpaces(json.spaces, [player1, player2]));
expect(board.getSpaceById('01')!.player).eq(player1);
expect(board.getSpaceById('03')!.player).eq(player2);

const serialized = board.serialize();
const boardJson = {
'spaces': [
{
'id': '01',
'spaceType': 'colony', 'adjacency': undefined, 'bonus': [],
'x': -1, 'y': -1, 'player': 'name-1-id',
'tile': {'tileType': 2},
},
{
'id': '03',
'spaceType': 'land', 'adjacency': undefined, 'bonus': [1, 1],
'x': 4, 'y': 0, 'player': 'name-2-id',
'tile': {'tileType': 0},
},
{
'id': '04',
'spaceType': 'ocean', 'adjacency': undefined, 'bonus': [1, 1],
'x': 5, 'y': 0, 'player': undefined,
'tile': {'tileType': 1},
},
{
'id': '05',
'spaceType': 'land', 'adjacency': undefined, 'bonus': [],
'x': 6, 'y': 0, 'player': undefined,
'tile': undefined,
},
],
};
expect(serialized).deep.eq(boardJson);
});


it('deserialize', () => {
const boardJson = {
'spaces': [
Expand Down

0 comments on commit 1cad8b4

Please sign in to comment.