From: Holger Schemel Date: Wed, 1 Mar 2023 14:34:28 +0000 (+0100) Subject: added functions to check/force using "last played level sets" sub-menu X-Git-Tag: 4.3.5.2~21 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=336c0385138bdf4ade419958d9baa59614b9e6a6;p=rocksndiamonds.git added functions to check/force using "last played level sets" sub-menu --- diff --git a/src/libgame/setup.c b/src/libgame/setup.c index ee7733fc..a09d45d6 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -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) diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 29f2f7c3..59700cf9 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -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);