mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 13:02:06 -08:00
improved replays - can now skip forward 10 moves or let the client play through the moves
This commit is contained in:
parent
6d4c3aa8d9
commit
f5c3494723
12 changed files with 142 additions and 20 deletions
|
|
@ -858,6 +858,26 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void skipForward(final UUID gameId, final String sessionId, final int moves) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
try {
|
||||
callExecutor.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
ReplayManager.getInstance().skipForward(gameId, userId, moves);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerState getServerState() throws MageException {
|
||||
try {
|
||||
return new ServerState(
|
||||
|
|
|
|||
|
|
@ -68,5 +68,10 @@ public class ReplayManager {
|
|||
public void previousPlay(UUID gameId, UUID userId) {
|
||||
replaySessions.get(gameId.toString() + userId.toString()).previous();
|
||||
}
|
||||
|
||||
public void skipForward(UUID gameId, UUID userId, int moves) {
|
||||
replaySessions.get(gameId.toString() + userId.toString()).next(moves);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,14 @@ public class ReplaySession implements GameCallback {
|
|||
updateGame(replay.next(), replay.getGame());
|
||||
}
|
||||
|
||||
public synchronized void previous() {
|
||||
public synchronized void next(int moves) {
|
||||
for (int i = 0; i < moves; i++) {
|
||||
replay.next();
|
||||
}
|
||||
updateGame(replay.next(), replay.getGame());
|
||||
}
|
||||
|
||||
public synchronized void previous() {
|
||||
updateGame(replay.previous(), replay.getGame());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue