2 * Copyright (c) 2019-2020. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.scanner.json.chessbomb;
19 import com.google.gson.annotations.SerializedName;
21 import org.hedgecode.chess.scanner.format.PGNFormat;
22 import org.hedgecode.chess.scanner.format.PGNTag;
23 import org.hedgecode.chess.scanner.format.chessbomb.GameData;
24 import org.hedgecode.chess.scanner.format.chessbomb.GameFormat;
25 import org.hedgecode.chess.scanner.format.TypeMovesFormat;
26 import org.hedgecode.chess.scanner.spi.ServiceRegistry;
31 * @author Dmitry Samoshin aka gotty
33 public class JSONGameFormat extends AbstractBaseFormat implements GameFormat {
35 @SerializedName("gameData")
36 private JSONGameData gameData;
43 return Integer.toString(
49 public GameData gameData() {
55 PGNFormat pgnFormat = ServiceRegistry.singleProvider(
58 pgnFormat.addTag(PGNTag.EVENT, gameData.room().name());
59 pgnFormat.addTag(PGNTag.DATE, pgnFormat.formatDate(gameData.game().startAt()));
60 pgnFormat.addTag(PGNTag.ROUND, gameData.game().roundSlug());
61 pgnFormat.addTag(PGNTag.WHITE, gameData.game().white().name());
62 pgnFormat.addTag(PGNTag.BLACK, gameData.game().black().name());
63 pgnFormat.addTag(PGNTag.WHITE_TITLE, gameData.game().white().title());
64 pgnFormat.addTag(PGNTag.BLACK_TITLE, gameData.game().black().title());
65 pgnFormat.addTag(PGNTag.WHITE_ELO, Integer.toString(gameData.game().whiteElo()));
66 pgnFormat.addTag(PGNTag.BLACK_ELO, Integer.toString(gameData.game().blackElo()));
67 pgnFormat.addTag(PGNTag.EVENT_DATE, pgnFormat.formatDate(gameData.room().startAt()));
68 pgnFormat.addTag(PGNTag.TIME, pgnFormat.formatTime(gameData.game().startAt()));
69 pgnFormat.addTag(PGNTag.RESULT, gameData.game().result());
70 if (gameData.moves().length > 0) {
71 pgnFormat.addTag(PGNTag.PLY_COUNT, Integer.toString(gameData.moves().length));
74 TypeMovesFormat.WRAP.format(gameData.moves())
76 return pgnFormat.format();