[bknr-cvs] r1893 - in branches/xml-class-rework/projects/mah-jongg: src website

bknr at bknr.net bknr at bknr.net
Tue Mar 7 06:01:12 UTC 2006


Author: hhubner
Date: 2006-03-07 01:01:12 -0500 (Tue, 07 Mar 2006)
New Revision: 1893

Modified:
   branches/xml-class-rework/projects/mah-jongg/src/game.lisp
   branches/xml-class-rework/projects/mah-jongg/website/game.css
   branches/xml-class-rework/projects/mah-jongg/website/game.xsl
Log:
Add Button to undo last game entered.


Modified: branches/xml-class-rework/projects/mah-jongg/src/game.lisp
===================================================================
--- branches/xml-class-rework/projects/mah-jongg/src/game.lisp	2006-03-07 05:58:42 UTC (rev 1892)
+++ branches/xml-class-rework/projects/mah-jongg/src/game.lisp	2006-03-07 06:01:12 UTC (rev 1893)
@@ -54,13 +54,14 @@
 (defclass game ()
   ((winner :reader winner :initarg :winner)
    (east :reader east :initarg :east)
+   (undo-timestamp :reader undo-timestamp :initarg :undo-timestamp)
    (results :reader results :initarg :results :documentation "List ((<player> <score>) (...))")))
 
 (defmethod print-object ((game game) stream)
   (print-unreadable-object (game stream :type t)
     (format stream "WINNER: ~S" (name (winner game)))))
 
-(deftransaction make-game (winner results)
+(deftransaction make-game (undo-timestamp winner results)
   (let* ((all-results (mapcar #'(lambda (name-score) (list (find-player (car name-score)) (cadr name-score))) results))
          (winner (find-player winner))
          (east (find-if #'east-p (players *round*)))
@@ -78,6 +79,7 @@
       (rotate-winds)
       (setf (east-win-count *round*) 0))
     (car (push (make-instance 'game
+                              :undo-timestamp undo-timestamp
                               :winner winner
                               :east east
                               :results all-results)
@@ -85,6 +87,8 @@
 
 (defun round-as-xml ()
   (with-element "round"
+    (when (games *round*)
+      (attribute "undo-timestamp" (undo-timestamp (first (games *round*)))))
     (dolist (player (players *round*))
       (with-slots (name wind score) player
         (with-element "player"
@@ -92,7 +96,7 @@
           (attribute "wind" (string-downcase wind))
           (attribute "score" score))))
     (dolist (game (reverse (games *round*)))
-      (with-slots (winner east results) game
+      (with-slots (winner east results undo-timestamp) game
         (with-element "game"
           (dolist (player (players *round*))
             (with-element "score"
@@ -108,12 +112,15 @@
 
 (defun handle-game (req ent)
   (when (eq :post (request-method req))
-    (with-query-params (req action east north west south winner)
+    (with-query-params (req action undo-timestamp east north west south winner)
       (ecase (make-keyword-from-string action)
+        (:undo
+         (restore (parse-integer undo-timestamp)))
         (:make-round
          (make-round east north west south))
         (:make-game
-         (make-game (name (wind->player (make-keyword-from-string winner)))
+         (make-game (1- (get-universal-time))
+                    (name (wind->player (make-keyword-from-string winner)))
                     (mapcar #'(lambda (wind) (list (name (wind->player wind))
                                                    (parse-integer (query-param req (symbol-name wind)))))
                             '(:east :north :west :south))))

Modified: branches/xml-class-rework/projects/mah-jongg/website/game.css
===================================================================
--- branches/xml-class-rework/projects/mah-jongg/website/game.css	2006-03-07 05:58:42 UTC (rev 1892)
+++ branches/xml-class-rework/projects/mah-jongg/website/game.css	2006-03-07 06:01:12 UTC (rev 1893)
@@ -60,7 +60,7 @@
         text-align: right;
 }
 
-#end-round-button {
+#control-buttons {
         position: fixed;
         right: 20px;
         bottom: 20px;

Modified: branches/xml-class-rework/projects/mah-jongg/website/game.xsl
===================================================================
--- branches/xml-class-rework/projects/mah-jongg/website/game.xsl	2006-03-07 05:58:42 UTC (rev 1892)
+++ branches/xml-class-rework/projects/mah-jongg/website/game.xsl	2006-03-07 06:01:12 UTC (rev 1893)
@@ -90,7 +90,13 @@
       </tr>
      </tbody>
     </table>
-    <button type="submit" name="action" id="end-round-button" value="clear-round">End Round</button>
+    <div id="control-buttons">
+     <xsl:if test="@undo-timestamp != ''">
+      <input type="hidden" name="undo-timestamp" value="{@undo-timestamp}"/>
+      <button type="submit" name="action" value="undo">Undo Last Game</button>
+     </xsl:if>
+     <button type="submit" name="action" value="clear-round">End Round</button>
+    </div>
    </form>
   </body>
  </xsl:template>




More information about the Bknr-cvs mailing list