| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| part of solitaire; |
| |
| class SolitaireLog extends GameLog { |
| LogWriter logWriter; |
| |
| SolitaireLog() { |
| // TODO(alexfandrianto): The Game ID needs to be part of this constructor. |
| logWriter = new LogWriter(handleSyncUpdate, [0], "<game_id>/log"); |
| } |
| |
| @override |
| void setGame(Game g) { |
| this.game = g; |
| logWriter.associatedUser = this.game.playerNumber; |
| } |
| |
| void handleSyncUpdate(String key, String cmd) { |
| // In Solitaire, we can ignore the key because this is a single player game, |
| // and the Solitaire schema only has TURN_BASED moves. |
| SolitaireCommand sc = new SolitaireCommand.fromCommand(cmd); |
| this.update(sc); |
| } |
| |
| @override |
| void addToLogCb(List<GameCommand> log, GameCommand newCommand) { |
| logWriter.write(newCommand.simultaneity, newCommand.command); |
| } |
| |
| @override |
| List<GameCommand> updateLogCb( |
| List<GameCommand> current, List<GameCommand> other, int mismatchIndex) { |
| // Note: The Solitaire schema avoids all conflict, so this should never be called. |
| assert(false); |
| return current; |
| } |
| |
| @override |
| void close() { |
| logWriter.close(); |
| } |
| } |