[gnome-games] aisleriot: Add slot type argument to the add-slot function



commit 0dcaf7b8f825edb09675ffbf826b4ec67a03ff2f
Author: Christian Persch <chpe gnome org>
Date:   Fri Nov 20 18:00:10 2009 +0100

    aisleriot: Add slot type argument to the add-slot function
    
    This allows marking the slot type from the scheme code.

 aisleriot/game.c               |   49 +++++++++++++++++++++++++++++++++------
 aisleriot/game.h               |   10 ++++++++
 aisleriot/sol.scm              |   22 +++++++++---------
 libgames-support/games-debug.c |    5 ++-
 libgames-support/games-debug.h |    9 ++++---
 5 files changed, 70 insertions(+), 25 deletions(-)
---
diff --git a/aisleriot/game.c b/aisleriot/game.c
index 41fa42d..39dd9c2 100644
--- a/aisleriot/game.c
+++ b/aisleriot/game.c
@@ -35,6 +35,7 @@
 #include <clutter/clutter.h>
 #endif
 
+#include <libgames-support/games-debug.h>
 #include <libgames-support/games-runtime.h>
 #include <libgames-support/games-string-utils.h>
 
@@ -572,6 +573,8 @@ cscmi_add_slot (SCM slot_data)
   gboolean expanded_down = FALSE;
   gboolean expanded_right = FALSE;
   int expansion_depth = 0;
+  ArSlotType type = AR_SLOT_UNKNOWN;
+  SCM slot_placement, slot_type;
 
   if (game->state > GAME_BEGIN) {
     return scm_throw (scm_from_locale_symbol ("game-started"),
@@ -580,25 +583,54 @@ cscmi_add_slot (SCM slot_data)
   }
 
 #ifdef HAVE_GUILE_1_8
-#define CHECK_EXPANSION(string,object) (scm_is_true (scm_equal_p (scm_from_locale_symbol (string), object)))
+#define EQUALS_SYMBOL(string,object) (scm_is_true (scm_equal_p (scm_from_locale_symbol (string), object)))
 #else
-#define CHECK_EXPANSION(string,object) (!strcmp (string, SCM_CHARS (object)))
+#define EQUALS_SYMBOL(string,object) (!strcmp (string, SCM_CHARS (object)))
 #endif
 
-  if (CHECK_EXPANSION ("expanded", SCM_CAR (SCM_CADDR (slot_data)))) {
+  slot_placement = SCM_CADDR (slot_data);
+  if (EQUALS_SYMBOL ("expanded", SCM_CAR (slot_placement))) {
     expanded_down = TRUE;
-  } else if (CHECK_EXPANSION ("expanded-right", SCM_CAR (SCM_CADDR (slot_data)))) {
+  } else if (EQUALS_SYMBOL ("expanded-right", SCM_CAR (slot_placement))) {
     expanded_right = TRUE;
-  } else if (CHECK_EXPANSION ("partially-expanded", SCM_CAR (SCM_CADDR (slot_data)))) {
+  } else if (EQUALS_SYMBOL ("partially-expanded", SCM_CAR (slot_placement))) {
     expanded_down = TRUE;
-    expansion_depth = scm_to_int (SCM_CADDR (SCM_CADDR (slot_data)));
-  } else if (CHECK_EXPANSION ("partially-expanded-right", SCM_CAR (SCM_CADDR (slot_data)))) {
+    expansion_depth = scm_to_int (SCM_CADDR (slot_placement));
+  } else if (EQUALS_SYMBOL ("partially-expanded-right", SCM_CAR (slot_placement))) {
     expanded_right = TRUE;
-    expansion_depth = scm_to_int (SCM_CADDR (SCM_CADDR (slot_data)));
+    expansion_depth = scm_to_int (SCM_CADDR (slot_placement));
   }
 
 #undef CHECK_EXPANSION
 
+  /* 3rd argument is the slot type (optionally) */
+  slot_type = SCM_CDDDR (slot_data);
+  if (slot_type != SCM_EOL) {
+    if (EQUALS_SYMBOL ("foundation", SCM_CAR (slot_type))) {
+      type = AR_SLOT_FOUNDATION;
+    } else if (EQUALS_SYMBOL ("reserve", SCM_CAR (slot_type))) {
+      type = AR_SLOT_RESERVE;
+    } else if (EQUALS_SYMBOL ("stock", SCM_CAR (slot_type))) {
+      type = AR_SLOT_STOCK;
+    } else if (EQUALS_SYMBOL ("tableau", SCM_CAR (slot_type))) {
+      type = AR_SLOT_TABLEAU;
+    } else if (EQUALS_SYMBOL ("waste", SCM_CAR (slot_type))) {
+      type = AR_SLOT_WASTE;
+    }
+  }
+
+#undef EQUALS_SYMBOL
+
+#ifdef GNOME_ENABLE_DEBUG
+  _GAMES_DEBUG_IF (GAMES_DEBUG_SCHEME) {
+    static const char *types[] = { "unknown", "foundation", "reserve", "stock", "tableau", "waste" };
+
+    _games_debug_print (GAMES_DEBUG_SCHEME,
+                        "Adding new slot %d type %s\n",
+                        scm_to_int (SCM_CAR (slot_data)), types[type]);
+  }
+#endif /* GNOME_ENABLE_DEBUG */
+
   /* create and initialize slot */
 #if GLIB_CHECK_VERSION (2, 10, 0)
   slot = g_slice_new0 (Slot);
@@ -609,6 +641,7 @@ cscmi_add_slot (SCM slot_data)
   g_ptr_array_add (game->slots, slot);
 
   slot->id = scm_to_int (SCM_CAR (slot_data));
+  slot->type = type;
 
   slot->cards = g_byte_array_sized_new (SLOT_CARDS_N_PREALLOC);
   slot->exposed = 0;
diff --git a/aisleriot/game.h b/aisleriot/game.h
index 32691e7..2e778ea 100644
--- a/aisleriot/game.h
+++ b/aisleriot/game.h
@@ -30,8 +30,18 @@ G_BEGIN_DECLS
 
 /* A slot */
 
+typedef enum {
+  AR_SLOT_UNKNOWN,
+  AR_SLOT_FOUNDATION,
+  AR_SLOT_RESERVE,
+  AR_SLOT_STOCK,
+  AR_SLOT_TABLEAU,
+  AR_SLOT_WASTE
+} ArSlotType;
+
 typedef struct {
   int id;
+  ArSlotType type;
 
   GByteArray *cards;
 #ifdef HAVE_CLUTTER
diff --git a/aisleriot/sol.scm b/aisleriot/sol.scm
index e863819..67875aa 100644
--- a/aisleriot/sol.scm
+++ b/aisleriot/sol.scm
@@ -160,30 +160,30 @@
 
 ; The real slots come in three varieties:
 ; A slot in which only the topmost card is visible:
-(define (add-normal-slot cards)
-  (add-slot (set-tag! (new-slot cards 
-				(list 'normal (get-and-increment-position))))))
+(define (add-normal-slot cards . type)
+  (add-slot (set-tag! (new-slot cards
+				(list 'normal (get-and-increment-position)) type))))
 
 ; A slot in which all the cards are visible, arranged as an overlapped pile:
 ; (either proceeding to the right or down).
-(define (add-extended-slot cards direction)
+(define (add-extended-slot cards direction . type)
   (if (= right direction)
       (add-slot (set-tag! (new-slot cards 
 				    (list 'expanded-right 
-					  (get-and-increment-position)))))
+					  (get-and-increment-position)) type)))
       (add-slot (set-tag! (new-slot cards 
 				    (list 'expanded 
-					  (get-and-increment-position)))))))
+					  (get-and-increment-position)) type)))))
 
 ; A slot in only the n topmost cards are visible:
-(define (add-partially-extended-slot cards direction n)
+(define (add-partially-extended-slot cards direction n . type)
   (if (= right direction)
       (add-slot (set-tag! (new-slot cards 
 				    (list 'partially-expanded-right 
-					  (get-and-increment-position) n))))
+					  (get-and-increment-position) n) type)))
       (add-slot (set-tag! (new-slot cards 
 				    (list 'partially-expanded 
-					  (get-and-increment-position) n))))))
+					  (get-and-increment-position) n) type)))))
 
 ; Cards may be dealt off one slot (usually the one containing the deck)
 ; and onto a list of other slots using these procedures:
@@ -525,8 +525,8 @@
 	(vector-set! deck ref2 (vector-ref deck ref1))
 	(shuffle-deck-helper deck (cons val-at-ref2 result) (+ ref1 1) (- len 1)))))
 
-(define (new-slot deck placement)
-  (list #f deck placement))
+(define (new-slot deck placement type)
+  (list #f deck placement (if (null? type) 'unknown (car type))))
 
 (define (set-tag! slot)
   (set! SLOTS (+ 1 SLOTS))
diff --git a/libgames-support/games-debug.c b/libgames-support/games-debug.c
index a424e8a..0145a8c 100644
--- a/libgames-support/games-debug.c
+++ b/libgames-support/games-debug.c
@@ -31,10 +31,11 @@ _games_debug_init (void)
 {
 #ifdef GNOME_ENABLE_DEBUG
   const GDebugKey keys[] = {
-    { "card-theme",   GAMES_DEBUG_CARD_THEME   },
-    { "card-cache",   GAMES_DEBUG_CARD_CACHE   },
     { "blocks-cache", GAMES_DEBUG_BLOCKS_CACHE },
+    { "card-cache",   GAMES_DEBUG_CARD_CACHE   },
+    { "card-theme",   GAMES_DEBUG_CARD_THEME   },
     { "runtime",      GAMES_DEBUG_RUNTIME      },
+    { "scheme",       GAMES_DEBUG_SCHEME       },
     { "sound",        GAMES_DEBUG_SOUND        },
     { "window-state", GAMES_DEBUG_WINDOW_STATE }
   };
diff --git a/libgames-support/games-debug.h b/libgames-support/games-debug.h
index bd1dcce..b9c7fe7 100644
--- a/libgames-support/games-debug.h
+++ b/libgames-support/games-debug.h
@@ -28,12 +28,13 @@ G_BEGIN_DECLS
 #define GAMES_DEBUG_LAST_RESERVED_BIT (8)
 
 typedef enum {
-  GAMES_DEBUG_CARD_THEME    = 1 << 0,
+  GAMES_DEBUG_BLOCKS_CACHE  = 1 << 0,
   GAMES_DEBUG_CARD_CACHE    = 1 << 1,
-  GAMES_DEBUG_BLOCKS_CACHE  = 1 << 2,
+  GAMES_DEBUG_CARD_THEME    = 1 << 2,
   GAMES_DEBUG_RUNTIME       = 1 << 3,
-  GAMES_DEBUG_SOUND         = 1 << 4,
-  GAMES_DEBUG_WINDOW_STATE  = 1 << 5
+  GAMES_DEBUG_SCHEME        = 1 << 4,
+  GAMES_DEBUG_SOUND         = 1 << 5,
+  GAMES_DEBUG_WINDOW_STATE  = 1 << 6
 } GamesDebugFlags;
 
 #ifdef GNOME_ENABLE_DEBUG



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