]> skyeroc.xyz Git - dgamelaunch/commitdiff
Add config "ifnxsleep" command
authorMichael Meyer <me@entrez.cc>
Tue, 12 Nov 2024 22:12:17 +0000 (17:12 -0500)
committerk21971 <keith.simpson1971@gmail.com>
Tue, 12 Nov 2024 22:20:32 +0000 (17:20 -0500)
For sleeping/delaying a certain amount of time if the specified file
does not exist. Intended for use in delaying games iff no save file
exists, to ease up on the server load from start scumming (especially
automated start scumming).

Sleep 5 seconds if /path/to/file.txt does not exist:

| ifnxsleep 5 "/path/to/file.txt"

config.l
dgamelaunch.h
dgl-common.c
examples/dgamelaunch.conf

index bc06d2961c7a8a14b0e79b7fb115e10e8224f0e3..6eff8efd2307a0c7762aa5c13ec1973e9811a8e0 100644 (file)
--- a/config.l
+++ b/config.l
@@ -142,6 +142,7 @@ return              { yylval.i = DGLCMD_RETURN;      return TYPE_DGLCMD0; }
 redraw         { yylval.i = DGLCMD_REDRAW;     return TYPE_DGLCMD0; }
 rawprint       { yylval.i = DGLCMD_RAWPRINT;    return TYPE_DGLCMD1; }
 sleep          { yylval.i = DGLCMD_SLEEP;       return TYPE_DGLCMD1; }
+ifnxsleep      { yylval.i = DGLCMD_IF_NX_SLEEP; return TYPE_DGLCMD2; }
 DEFINE         { return TYPE_DEFINE_GAME; }
 
 
index 2efebee08a42f0b87d370ee0bd459fc1d0d656f5..0402d2683c4e4b20a33f64b2b7a8ce2f2a8aaf2d 100644 (file)
@@ -83,7 +83,8 @@ typedef enum
     DGLCMD_SUBMENU,    /* submenu "foo" */
     DGLCMD_REDRAW,     /* redraw */
     DGLCMD_RETURN,     /* return */
-    DGLCMD_SLEEP        /* sleep */
+    DGLCMD_SLEEP,       /* sleep foo */
+    DGLCMD_IF_NX_SLEEP, /* ifnxsleep foo bar */
 } dglcmd_actions;
 
 typedef enum
index 89a342f0ed51a89e5b1ab2f40412c5795f29b42d..aa2368110ba5828a4e6de2bc9114dac5edbc7548 100644 (file)
@@ -463,6 +463,16 @@ dgl_exec_cmdqueue_w(struct dg_cmdpart *queue, int game, struct dg_user *me, char
        case DGLCMD_RETURN:
            return_from_submenu = 1;
            break;
+       case DGLCMD_IF_NX_SLEEP:
+           if (p2) {
+               FILE *tmpfile;
+               tmpfile = fopen(p2, "r");
+               if (tmpfile) {
+                   fclose(tmpfile);
+                   break;
+               }
+           }
+           /* fall through if file does not exist */
        case DGLCMD_SLEEP:
            if (p1) {
                char *end;
index b4276e303884984562071b415f6acc7c2cf691f0..187d52659b10420a2b08cbef9e7b38618cc958f2 100644 (file)
@@ -146,6 +146,8 @@ default_term = "xterm"
 #   play_if_exist "foo" "file" = start game "foo", if file "file" exists.
 #   submenu "foo"      = go to submenu "foo"
 #   return             = return from submenu
+#   sleep "foo"        = sleep for "foo" seconds
+#   ifnxsleep "foo" "file" = sleep for "foo" seconds if file "file" does not exist.
 #
 #  NOTE: edit_options-command was removed. use ifnxcp and exec to simulate it.
 #