[aisleriot] games: api: Fix undo/redo



commit 18f60ef9c10288d9a1f661f275ec755f3165690b
Author: Otto Wallenius <owalleni gmail com>
Date:   Wed Oct 16 18:01:11 2019 +0200

    games: api: Fix undo/redo
    
    Current status message and status message history is saved and
    restored in api.scm in the same way as game score.
    
    Fixes bug 744679.

 games/api.scm | 16 ++++++++++------
 src/game.c    |  4 ++--
 2 files changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/games/api.scm b/games/api.scm
index 309c1371..764a1ab9 100644
--- a/games/api.scm
+++ b/games/api.scm
@@ -734,6 +734,11 @@
 (define-public (add-to-score! delta)
   (set-score! (+ (get-score) delta)))
 
+(define-public (set-statusbar-message message)
+  (set! STATUSBAR-MESSAGE message)
+  (set-statusbar-message-c message)
+)
+
 ;; INTERNAL procedures
 
 ; global variables
@@ -755,6 +760,7 @@
 (define-public LEFT-SLOTS '())
 (define-public RIGHT-SLOTS '())
 (define-public SCORE 0)
+(define-public STATUSBAR-MESSAGE "")
 
 ; called from C:
 (define-public (start-game)
@@ -779,13 +785,9 @@
        (set-cards! slot-id (car card-positions))
        (return-cards (cdr card-positions) (+ 1 slot-id))))
 
-(define-public (give-status-message)
-  #t)
-
 (define-public (eval-move move)
   (return-cards (caddr move) 0)
-  ((car move) (cadr move))
-  (give-status-message))
+  ((car move) (cadr move)))
 
 ; called from C:
 (define-public (undo)
@@ -814,7 +816,8 @@
 (define-public (undo-func data)
   (set-score! (car data))
   (set! FLIP-COUNTER (cadr data))
-  (restore-variables variable-list (caddr data)))
+  (set-statusbar-message (caddr data))
+  (restore-variables variable-list (cadddr data)))
 ;(register-undo-function undo-func '(score FLIP-COUNTER))
             
 (define-public (snapshot-board slot-id moving-slot old-cards)
@@ -831,6 +834,7 @@
 (define-public (record-move slot-id old-cards)
   (set! MOVE (list undo-func 
                    (list (get-score) FLIP-COUNTER 
+                         STATUSBAR-MESSAGE
                          (save-variables variable-list))
                    (snapshot-board 0 slot-id old-cards))))
 
diff --git a/src/game.c b/src/game.c
index 4d795848..a7febcb5 100644
--- a/src/game.c
+++ b/src/game.c
@@ -1030,7 +1030,7 @@ cscm_init (void *data G_GNUC_UNUSED)
   /* Let the scheme side of things know about our C functions. */
   scm_c_define_gsubr ("set-feature-word!", 1, 0, 0, scm_set_feature_word);
   scm_c_define_gsubr ("get-feature-word", 0, 0, 0, scm_get_feature_word);
-  scm_c_define_gsubr ("set-statusbar-message", 1, 0, 0,
+  scm_c_define_gsubr ("set-statusbar-message-c", 1, 0, 0,
                       scm_set_statusbar_message);
   scm_c_define_gsubr ("reset-surface", 0, 0, 0, scm_reset_surface);
   scm_c_define_gsubr ("add-slot", 1, 0, 0, cscmi_add_slot);
@@ -1054,7 +1054,7 @@ cscm_init (void *data G_GNUC_UNUSED)
 
   scm_c_export ("set-feature-word!", 
                 "get-feature-word", 
-                "set-statusbar-message",
+                "set-statusbar-message-c",
                 "reset-surface",
                 "add-slot", 
                 "get-slot", 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]