added functions to check/force using "last played level sets" sub-menu
authorHolger Schemel <info@artsoft.org>
Wed, 1 Mar 2023 14:34:28 +0000 (15:34 +0100)
committerHolger Schemel <info@artsoft.org>
Wed, 1 Mar 2023 15:49:02 +0000 (16:49 +0100)
src/libgame/setup.c
src/libgame/setup.h

index ee7733fcd5216b97df49d184b9a0b1e87d2b8892..a09d45d68568aa2acef429ea33ad805faf589bb0 100644 (file)
@@ -5006,33 +5006,51 @@ static void UpdateLastPlayedLevels_List(void)
   setString(&last_level_series[0], leveldir_current->identifier);
 }
 
-static TreeInfo *StoreOrRestoreLastPlayedLevels(TreeInfo *node, boolean store)
+#define LAST_PLAYED_MODE_SET                   1
+#define LAST_PLAYED_MODE_SET_FORCED            2
+#define LAST_PLAYED_MODE_GET                   3
+
+static TreeInfo *StoreOrRestoreLastPlayedLevels(TreeInfo *node, int mode)
 {
   static char *identifier = NULL;
 
-  if (store)
+  if (mode == LAST_PLAYED_MODE_SET)
   {
     setString(&identifier, (node && node->is_copy ? node->identifier : NULL));
-
-    return NULL;       // not used
   }
-  else
+  else if (mode == LAST_PLAYED_MODE_SET_FORCED)
+  {
+    setString(&identifier, (node ? node->identifier : NULL));
+  }
+  else if (mode == LAST_PLAYED_MODE_GET)
   {
     TreeInfo *node_new = getTreeInfoFromIdentifierExt(leveldir_first,
                                                      identifier,
                                                      TREE_NODE_TYPE_COPY);
     return (node_new != NULL ? node_new : node);
   }
+
+  return NULL;         // not used
 }
 
 void StoreLastPlayedLevels(TreeInfo *node)
 {
-  StoreOrRestoreLastPlayedLevels(node, TRUE);
+  StoreOrRestoreLastPlayedLevels(node, LAST_PLAYED_MODE_SET);
+}
+
+void ForcedStoreLastPlayedLevels(TreeInfo *node)
+{
+  StoreOrRestoreLastPlayedLevels(node, LAST_PLAYED_MODE_SET_FORCED);
 }
 
 void RestoreLastPlayedLevels(TreeInfo **node)
 {
-  *node = StoreOrRestoreLastPlayedLevels(*node, FALSE);
+  *node = StoreOrRestoreLastPlayedLevels(*node, LAST_PLAYED_MODE_GET);
+}
+
+boolean CheckLastPlayedLevels(void)
+{
+  return (StoreOrRestoreLastPlayedLevels(NULL, LAST_PLAYED_MODE_GET) != NULL);
 }
 
 void LoadLevelSetup_LastSeries(void)
index 29f2f7c3f86ef169f65f557acd2255c3472d333c..59700cf9cf70011ed01b71ed1e224d313ccc85e6 100644 (file)
@@ -397,7 +397,9 @@ boolean CreateUserLevelSet(char *, char *, char *, int, boolean);
 
 void UpdateLastPlayedLevels_TreeInfo(void);
 void StoreLastPlayedLevels(TreeInfo *);
+void ForcedStoreLastPlayedLevels(TreeInfo *);
 void RestoreLastPlayedLevels(TreeInfo **);
+boolean CheckLastPlayedLevels(void);
 
 void LoadLevelSetup_LastSeries(void);
 void SaveLevelSetup_LastSeries(void);