# HG changeset patch # User Jaroslav Tulach # Date 1252724428 -7200 # Node ID 89bca098e14e375937b7f61a626fb756f2ffd657 # Parent 5ea4172dcf8b53e297362187eb73851547c53b9a Time of the read game shall be lastModified of the game's file diff -r 5ea4172dcf8b -r 89bca098e14e freemarkerdor/pom.xml --- a/freemarkerdor/pom.xml Fri Sep 11 22:25:21 2009 +0200 +++ b/freemarkerdor/pom.xml Sat Sep 12 05:00:28 2009 +0200 @@ -100,7 +100,7 @@ - 1.3 + 1.4 diff -r 5ea4172dcf8b -r 89bca098e14e freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Fri Sep 11 22:25:21 2009 +0200 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Sat Sep 12 05:00:28 2009 +0200 @@ -34,7 +34,6 @@ import com.sun.jersey.api.core.ResourceConfig; import com.sun.jersey.api.view.Viewable; import com.sun.net.httpserver.HttpServer; -import cz.xelfi.quoridor.webidor.resources.Quoridor; import java.io.File; import java.io.FileInputStream; import java.io.IOException; diff -r 5ea4172dcf8b -r 89bca098e14e freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Fri Sep 11 22:25:21 2009 +0200 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Sat Sep 12 05:00:28 2009 +0200 @@ -21,7 +21,7 @@ <#assign unit="day"/> <#assign value=t?float / (24.0 * 3600000.0)/> - ${value?float?string("0")} ${unit} + ${value?float?string("0")} ${unit} <#macro game game> diff -r 5ea4172dcf8b -r 89bca098e14e webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java Fri Sep 11 22:25:21 2009 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/Game.java Sat Sep 12 05:00:28 2009 +0200 @@ -87,7 +87,7 @@ } } - public void apply(String player, Move m) throws IllegalPositionException { + public void apply(String player, Move m, Date when) throws IllegalPositionException { Player p = null; if (id.getWhite().equals(player)) { p = getBoard().getPlayers().get(0); @@ -101,7 +101,10 @@ } board = getBoard().apply(m); - id = new GameId(id.getId(), id.getWhite(), id.getBlack(), new Date(id.getStarted()), new Date(), GameStatus.valueOf(board)); + if (when == null) { + when = new Date(id.getModified()); + } + id = new GameId(id.getId(), id.getWhite(), id.getBlack(), new Date(id.getStarted()), when, GameStatus.valueOf(board)); getMoves().add(m); } diff -r 5ea4172dcf8b -r 89bca098e14e webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Fri Sep 11 22:25:21 2009 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Sat Sep 12 05:00:28 2009 +0200 @@ -127,7 +127,7 @@ throw new IllegalArgumentException("Unknown game " + id); } Move m = Move.valueOf(move); - g.apply(player, m); + g.apply(player, m, new Date()); try { storeGame(g); } catch (IOException ex) { @@ -202,9 +202,9 @@ throw new IOException("Too much moves on line: " + line); } try { - g.apply(white, Move.valueOf(moves[0])); + g.apply(white, Move.valueOf(moves[0]), null); if (moves.length == 2) { - g.apply(black, Move.valueOf(moves[1])); + g.apply(black, Move.valueOf(moves[1]), null); } } catch (IllegalPositionException ex) { throw new IOException("Wrong move: " + ex.getMessage()); diff -r 5ea4172dcf8b -r 89bca098e14e webidor/src/test/java/cz/xelfi/quoridor/webidor/GamesTest.java --- a/webidor/src/test/java/cz/xelfi/quoridor/webidor/GamesTest.java Fri Sep 11 22:25:21 2009 +0200 +++ b/webidor/src/test/java/cz/xelfi/quoridor/webidor/GamesTest.java Sat Sep 12 05:00:28 2009 +0200 @@ -71,14 +71,22 @@ File f = new File(dir, "x"); f.getParentFile().mkdirs(); FileOutputStream os = new FileOutputStream(f); - os.write("# white: W\n# black: B\n# status: IN_PROGRESS\n\n\n".getBytes("UTF-8")); + os.write("# white: W\n# black: B\n# status: IN_PROGRESS\nN S\n\n".getBytes("UTF-8")); os.close(); + Thread.sleep(1000); + + long middle = f.lastModified(); + + Thread.sleep(1000); + Games games = new Games(dir); Game g = games.getBoardInfo("x"); assertNotNull("Game found", g); assertNotNull("Board found", g.getBoard()); - assertEquals("List of moves is empty", 0, g.getMoves().size()); + assertEquals("List of moves has two", 2, g.getMoves().size()); + + assertEquals("Last move is last touch of the file", middle, g.getId().getModified()); } }