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.format;
19 import java.text.DateFormat;
20 import java.text.SimpleDateFormat;
22 import com.google.gson.annotations.SerializedName;
24 import org.hedgecode.chess.scanner.entity.PGNTag;
25 import org.hedgecode.chess.scanner.format.GameData;
26 import org.hedgecode.chess.scanner.format.GameFormat;
31 * @author Dmitry Samoshin aka gotty
33 public class JSONGameFormat extends AbstractPGNFormat implements GameFormat {
35 private final DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd");
36 private final DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
38 @SerializedName("gameData")
39 private JSONGameData gameData;
46 return Integer.toString(
47 gameData().game().id()
52 public GameData gameData() {
57 protected void assignPGN() {
58 addTag(PGNTag.EVENT, gameData.room().name());
59 addTag(PGNTag.DATE, dateFormat.format(gameData.game().startAt()));
60 addTag(PGNTag.ROUND, gameData.game().roundSlug());
61 addTag(PGNTag.WHITE, gameData.game().white().name());
62 addTag(PGNTag.BLACK, gameData.game().black().name());
63 addTag(PGNTag.WHITE_TITLE, gameData.game().white().title());
64 addTag(PGNTag.BLACK_TITLE, gameData.game().black().title());
65 addTag(PGNTag.WHITE_ELO, Integer.toString(gameData.game().white().elo()));
66 addTag(PGNTag.BLACK_ELO, Integer.toString(gameData.game().black().elo()));
67 addTag(PGNTag.TIME, timeFormat.format(gameData.game().startAt()));
68 addTag(PGNTag.RESULT, gameData.game().result());
70 addMoves(gameData.formatMoves());