| | 1 | /* Copyright 2001, 2002 Michael J. Roberts */ |
| | 2 | /* |
| | 3 | * gameinfo.t - game information utility for tads 2 |
| | 4 | * |
| | 5 | * This header file is designed to be #include'd in a TADS game's source |
| | 6 | * file to define a simple utility function that generates a |
| | 7 | * "GameInfo.txt" file during preinit. IMPORTANT: Include this file |
| | 8 | * *before* std.t if you also include std.t. |
| | 9 | * |
| | 10 | * The GameInfo.txt file provides "card catalog" information about the |
| | 11 | * game. Automated tools, such as archive management software, can |
| | 12 | * extract the information for applications such as searching and |
| | 13 | * browsing. |
| | 14 | * |
| | 15 | * To include game information in your game, you must do the following: |
| | 16 | * |
| | 17 | * 1. Add a #include directive to your game's source code to include |
| | 18 | * this file. |
| | 19 | * |
| | 20 | * #include <gameinfo.t> |
| | 21 | * |
| | 22 | * IMPORTANT: The order of inclusion is important. If you're including |
| | 23 | * adv.t and std.t in addition to this file, you must use the following |
| | 24 | * order: |
| | 25 | * |
| | 26 | * #include <adv.t> |
| | 27 | *. #include <gameinfo.t> |
| | 28 | *. #include <std.t> |
| | 29 | * |
| | 30 | * 2. Define a function in your game called getGameInfo(). This |
| | 31 | * function should simply return a list value. The list should consist |
| | 32 | * of pairs of strings; the first string in each pair is the name of a |
| | 33 | * parameter, and the second of each pair is the value for the parameter. |
| | 34 | * For example: |
| | 35 | * |
| | 36 | *. getGameInfo: function |
| | 37 | *. { |
| | 38 | *. return ['Name', 'My Game', |
| | 39 | *. 'Byline', 'by R. Teeterwaller', |
| | 40 | *. 'Desc', 'A simple test game.]; |
| | 41 | *. } |
| | 42 | * |
| | 43 | * 3. If you're using the standard preinit() function from std.t, you |
| | 44 | * can skip this step. Otherwise, add this line to your own preinit() |
| | 45 | * function, anywhere within the function: |
| | 46 | * |
| | 47 | * writeGameInfo(getGameInfo()); |
| | 48 | * |
| | 49 | * 4. After you compile your game, use the tads resource tool to bundle |
| | 50 | * GameInfo.txt into your .gam file, just as though it were an HTML TADS |
| | 51 | * multimedia resource. If you are including other multimedia resources |
| | 52 | * in your game, simply add GameInfo.txt to the list of files you bundle. |
| | 53 | * If you don't have any other resources, add this command line to your |
| | 54 | * build script, immediately after the TADS compiler commnd line: |
| | 55 | * |
| | 56 | *. tadsrsc mygame.gam -add GameInfo.txt |
| | 57 | * |
| | 58 | * (If you're using the 32-bit Windows version, the command name is |
| | 59 | * tadsrsc32. The command name may vary on other platforms.) |
| | 60 | */ |
| | 61 | |
| | 62 | #pragma C+ |
| | 63 | |
| | 64 | /* indicate that we've included this file, for std.t's use */ |
| | 65 | #define GAMEINFO_INCLUDED |
| | 66 | |
| | 67 | /* |
| | 68 | * write the name/value pairs from the given list to the file |
| | 69 | * 'GameInfo.txt' |
| | 70 | */ |
| | 71 | writeGameInfo: function(info) |
| | 72 | { |
| | 73 | local fp; |
| | 74 | local i; |
| | 75 | local cnt; |
| | 76 | |
| | 77 | /* open the output file */ |
| | 78 | fp = fopen('GameInfo.txt', 'wt'); |
| | 79 | |
| | 80 | /* write the values */ |
| | 81 | for (i = 1, cnt = length(info) ; i <= cnt ; i += 2) |
| | 82 | { |
| | 83 | /* write the name, a colon, and the value */ |
| | 84 | fwrite(fp, info[i]); |
| | 85 | fwrite(fp, ': '); |
| | 86 | fwrite(fp, info[i+1]); |
| | 87 | fwrite(fp, '\n'); |
| | 88 | } |
| | 89 | |
| | 90 | /* done with the file */ |
| | 91 | fclose(fp); |
| | 92 | } |
| | 93 | |
| | 94 | /* |
| | 95 | * Utility function to retrieve today's date in format YYY-MM-DD. |
| | 96 | */ |
| | 97 | getGameInfoToday: function |
| | 98 | { |
| | 99 | local dt; |
| | 100 | local mm, dd; |
| | 101 | |
| | 102 | /* |
| | 103 | * get the current time/date information - if this is called during |
| | 104 | * preinit, it will give the date on which the game was compiled, |
| | 105 | * which can be used as a simple way of keeping the release date |
| | 106 | * field in the game information automatically updated |
| | 107 | */ |
| | 108 | dt = gettime(GETTIME_DATE_AND_TIME); |
| | 109 | |
| | 110 | /* |
| | 111 | * get the month, and make sure it's at least two digits, adding a |
| | 112 | * leading zero if necessary |
| | 113 | */ |
| | 114 | mm = cvtstr(dt[2]); |
| | 115 | if (length(mm) == 1) |
| | 116 | mm = '0' + mm; |
| | 117 | |
| | 118 | /* get the day of the month, and make sure it's at least two digits */ |
| | 119 | dd = cvtstr(dt[3]); |
| | 120 | if (length(dd) == 1) |
| | 121 | dd = '0' + dd; |
| | 122 | |
| | 123 | /* build the return string in YYYY-MM-DD format */ |
| | 124 | return cvtstr(dt[1]) + '-' + mm + '-' + dd; |
| | 125 | } |