hedgewars/ArgParsers.pas
branchui-scaling
changeset 15663 d92eeb468dad
parent 15283 c4fd2813b127
parent 15300 a3823f0916b8
child 15845 ad43384fbbe9
equal deleted inserted replaced
15283:c4fd2813b127 15663:d92eeb468dad
    76     WriteLn(stdout, 'Use the command-line arguments to play a demo.');
    76     WriteLn(stdout, 'Use the command-line arguments to play a demo.');
    77     WriteLn(stdout, '');
    77     WriteLn(stdout, '');
    78     WriteLn(stdout, 'Usage: hwengine <path to demo file> [options]');
    78     WriteLn(stdout, 'Usage: hwengine <path to demo file> [options]');
    79     WriteLn(stdout, '');
    79     WriteLn(stdout, '');
    80     WriteLn(stdout, 'where [options] can be any of the following:');
    80     WriteLn(stdout, 'where [options] can be any of the following:');
    81     WriteLn(stdout, ' --prefix [path to folder]');
    81     WriteLn(stdout, '');
    82     WriteLn(stdout, ' --user-prefix [path to folder]');
    82     WriteLn(stdout, 'File locations:');
    83     WriteLn(stdout, ' --locale [name of language file]');
    83     WriteLn(stdout, '  --prefix <path to folder>: Set the path to the system game data folder');
    84     WriteLn(stdout, ' --nick [string]');
    84     WriteLn(stdout, '  --user-prefix <path to folder>: Set the path to the custom data folder to find game content');
    85     WriteLn(stdout, ' --fullscreen-width [fullscreen width in pixels]');
    85     WriteLn(stdout, '  --locale <name of file>: Set the game language (en.txt for example)');
    86     WriteLn(stdout, ' --fullscreen-height [fullscreen height in pixels]');
    86     WriteLn(stdout, '');
    87     WriteLn(stdout, ' --width [window width in pixels]');
    87     WriteLn(stdout, 'Graphics:');
    88     WriteLn(stdout, ' --height [window height in pixels]');
    88     WriteLn(stdout, '  --width <width in pixels>: Set game window width');
    89     WriteLn(stdout, ' --volume [sound level]');
    89     WriteLn(stdout, '  --height <height in pixels>: Set game window height');
    90     WriteLn(stdout, ' --frame-interval [milliseconds]');
    90     WriteLn(stdout, '  --maximized: Start in maximized window');
    91     Writeln(stdout, ' --stereo [value]');
    91     WriteLn(stdout, '  --fullscreen: Start in fullscreen');
    92     WriteLn(stdout, ' --raw-quality [flags]');
    92     WriteLn(stdout, '  --fullscreen-width <width in pixels>: Set fullscreen width');
    93     WriteLn(stdout, ' --low-quality');
    93     WriteLn(stdout, '  --fullscreen-height <height in pixels>: Set fullscreen height');
    94     WriteLn(stdout, ' --nomusic');
    94     WriteLn(stdout, '  --low-quality: Lowers the game quality');
    95     WriteLn(stdout, ' --nosound');
    95     WriteLn(stdout, '  --zoom <percent>: Start with custom zoom level');
    96     WriteLn(stdout, ' --fullscreen');
    96     WriteLn(stdout, '');
    97     WriteLn(stdout, ' --showfps');
    97     WriteLn(stdout, 'Audio:');
    98     WriteLn(stdout, ' --altdmg');
    98     WriteLn(stdout, '  --volume <sound level>: Set volume between 0 and 100');
    99     WriteLn(stdout, ' --no-teamtag');
    99     WriteLn(stdout, '  --nomusic: Disable music');
   100     WriteLn(stdout, ' --no-hogtag');
   100     WriteLn(stdout, '  --nosound: Disable sound effects');
   101     WriteLn(stdout, ' --no-healthtag');
   101     WriteLn(stdout, '  --nodampen: Don''t dampen sound volume when game application loses focus');
   102     WriteLn(stdout, ' --translucent-tags');
       
   103     WriteLn(stdout, ' --stats-only');
       
   104     WriteLn(stdout, ' --chat-size [default chat size in percent]');
       
   105     WriteLn(stdout, ' --help');
       
   106     WriteLn(stdout, '');
   102     WriteLn(stdout, '');
   107     WriteLn(stdout, 'HUD:');
   103     WriteLn(stdout, 'HUD:');
   108     WriteLn(stdout, '  --altdmg: Show alternative damage');
   104     WriteLn(stdout, '  --altdmg: Show alternative damage');
   109     WriteLn(stdout, '  --no-teamtag: Disable team name tags');
   105     WriteLn(stdout, '  --no-teamtag: Disable team name tags');
   110     WriteLn(stdout, '  --no-hogtag: Disable hedgehog name tags');
   106     WriteLn(stdout, '  --no-hogtag: Disable hedgehog name tags');
   131 procedure DisplayProtocol;
   127 procedure DisplayProtocol;
   132 begin
   128 begin
   133     WriteLn(stdout, IntToStr(cNetProtoVersion));
   129     WriteLn(stdout, IntToStr(cNetProtoVersion));
   134     GameType:= gmtSyntaxHelp;
   130     GameType:= gmtSyntaxHelp;
   135     helpCommandUsed:= true;
   131     helpCommandUsed:= true;
   136 end;
       
   137 
       
   138 procedure setDepth(var paramIndex: LongInt);
       
   139 begin
       
   140     WriteLn(stdout, 'WARNING: --depth is a deprecated command, which could be removed in a future version!');
       
   141     WriteLn(stdout, '         This option no longer does anything, please consider removing it.');
       
   142     WriteLn(stdout, '');
       
   143    inc(ParamIndex);
       
   144 end;
   132 end;
   145 
   133 
   146 procedure statsOnlyGame;
   134 procedure statsOnlyGame;
   147 begin
   135 begin
   148     cOnlyStats:= true;
   136     cOnlyStats:= true;
   253         UserZoom:= cMinZoomLevel;
   241         UserZoom:= cMinZoomLevel;
   254     zoom:= UserZoom;
   242     zoom:= UserZoom;
   255     ZoomValue:= UserZoom;
   243     ZoomValue:= UserZoom;
   256 end;
   244 end;
   257 
   245 
   258 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt); forward;
       
   259 
       
   260 function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
   246 function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
   261 const videoarray: array [0..4] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth');
   247 const reallyAll: array[0..35] of shortstring = (
   262       audioarray: array [0..2] of string = ('--volume','--nomusic','--nosound');
       
   263       otherarray: array [0..2] of string = ('--locale','--fullscreen','--showfps');
       
   264       mediaarray: array [0..9] of string = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
       
   265       allarray: array [0..19] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth','--volume','--nomusic','--nosound','--nodampen','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags', '--chat-size');
       
   266       reallyAll: array[0..40] of shortstring = (
       
   267                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
   248                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
   268                 '--height', '--frame-interval', '--volume','--nomusic', '--nosound', '--nodampen',
   249                 '--height', '--maximized', '--frame-interval', '--volume','--nomusic', '--nosound', '--nodampen',
   269                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
   250                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
   270                 '--zoom',
   251                 '--zoom',
   271   {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
       
   272   {internal}    '--internal', '--port', '--recorder', '--landpreview',
   252   {internal}    '--internal', '--port', '--recorder', '--landpreview',
   273   {misc}        '--stats-only', '--gci', '--help','--protocol', '--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags','--lua-test','--no-holiday-silliness','--chat-size');
   253   {misc}        '--stats-only', '--gci', '--help','--protocol', '--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags','--lua-test','--no-holiday-silliness','--chat-size');
   274 var cmdIndex: byte;
   254 var cmdIndex: byte;
   275 begin
   255 begin
   276     parseParameter:= false;
   256     parseParameter:= false;
   286         {--locale}               2 : cLanguageFName    := getstringParameter (arg, paramIndex, parseParameter);
   266         {--locale}               2 : cLanguageFName    := getstringParameter (arg, paramIndex, parseParameter);
   287         {--fullscreen-width}     3 : cFullscreenWidth  := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenWidth);
   267         {--fullscreen-width}     3 : cFullscreenWidth  := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenWidth);
   288         {--fullscreen-height}    4 : cFullscreenHeight := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenHeight);
   268         {--fullscreen-height}    4 : cFullscreenHeight := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenHeight);
   289         {--width}                5 : cWindowedWidth    := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenWidth);
   269         {--width}                5 : cWindowedWidth    := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenWidth);
   290         {--height}               6 : cWindowedHeight   := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenHeight);
   270         {--height}               6 : cWindowedHeight   := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenHeight);
   291         {--frame-interval}       7 : cTimerInterval    := getLongIntParameter(arg, paramIndex, parseParameter);
   271         {--maximized}            7 : cWindowedMaximized:= true;
   292         {--volume}               8 : SetVolume          ( max(getLongIntParameter(arg, paramIndex, parseParameter), 0) );
   272         {--frame-interval}       8 : cTimerInterval    := getLongIntParameter(arg, paramIndex, parseParameter);
   293         {--nomusic}              9 : SetMusic           ( false );
   273         {--volume}               9 : SetVolume          ( max(getLongIntParameter(arg, paramIndex, parseParameter), 0) );
   294         {--nosound}             10 : SetSound           ( false );
   274         {--nomusic}             10 : SetMusic           ( false );
   295         {--nodampen}            11 : SetAudioDampen     ( false );
   275         {--nosound}             11 : SetSound           ( false );
   296         {--fullscreen}          12 : cFullScreen       := true;
   276         {--nodampen}            12 : SetAudioDampen     ( false );
   297         {--showfps}             13 : cShowFPS          := true;
   277         {--fullscreen}          13 : cFullScreen       := true;
   298         {--altdmg}              14 : cAltDamage        := true;
   278         {--showfps}             14 : cShowFPS          := true;
   299         {--low-quality}         15 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
   279         {--altdmg}              15 : cAltDamage        := true;
   300         {--raw-quality}         16 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
   280         {--low-quality}         16 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
   301         {--stereo}              17 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
   281         {--raw-quality}         17 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
   302         {--nick}                18 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
   282         {--stereo}              18 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
   303         {--zoom}                19 : setZoom(arg, paramIndex, parseParameter);
   283         {--nick}                19 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
   304         {deprecated options}
   284         {--zoom}                20 : setZoom(arg, paramIndex, parseParameter);
   305         {--depth}               20 : setDepth(paramIndex);
       
   306         {--set-video}           21 : parseClassicParameter(videoarray,5,paramIndex);
       
   307         {--set-audio}           22 : parseClassicParameter(audioarray,3,paramIndex);
       
   308         {--set-other}           23 : parseClassicParameter(otherarray,3,paramIndex);
       
   309         {--set-multimedia}      24 : parseClassicParameter(mediaarray,10,paramIndex);
       
   310         {--set-everything}      25 : parseClassicParameter(allarray,14,paramIndex);
       
   311         {"internal" options}
   285         {"internal" options}
   312         {--internal}            26 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
   286         {--internal}            21 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
   313         {--port}                27 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
   287         {--port}                22 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
   314         {--recorder}            28 : startVideoRecording(paramIndex);
   288         {--recorder}            23 : startVideoRecording(paramIndex);
   315         {--landpreview}         29 : GameType := gmtLandPreview;
   289         {--landpreview}         24 : GameType := gmtLandPreview;
   316         {anything else}
   290         {anything else}
   317         {--stats-only}          30 : statsOnlyGame();
   291         {--stats-only}          25 : statsOnlyGame();
   318         {--gci}                 31 : GciEasterEgg();
   292         {--gci}                 26 : GciEasterEgg();
   319         {--help}                32 : DisplayUsage();
   293         {--help}                27 : DisplayUsage();
   320         {--protocol}            33 : DisplayProtocol();
   294         {--protocol}            28 : DisplayProtocol();
   321         {--no-teamtag}          34 : cTagsMask := cTagsMask and (not htTeamName);
   295         {--no-teamtag}          29 : cTagsMask := cTagsMask and (not htTeamName);
   322         {--no-hogtag}           35 : cTagsMask := cTagsMask and (not htName);
   296         {--no-hogtag}           30 : cTagsMask := cTagsMask and (not htName);
   323         {--no-healthtag}        36 : cTagsMask := cTagsMask and (not htHealth);
   297         {--no-healthtag}        31 : cTagsMask := cTagsMask and (not htHealth);
   324         {--translucent-tags}    37 : cTagsMask := cTagsMask or htTransparent;
   298         {--translucent-tags}    32 : cTagsMask := cTagsMask or htTransparent;
   325         {--lua-test}            38 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
   299         {--lua-test}            33 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
   326         {--no-holiday-silliness} 39 : cHolidaySilliness:= false;
   300         {--no-holiday-silliness} 34 : cHolidaySilliness:= false;
   327         {--chat-size}           40 : cDefaultChatScale := 1.0 * getLongIntParameter(arg, paramIndex, parseParameter) / 100;
   301         {--chat-size}           35 : cDefaultChatScale := 1.0 * getLongIntParameter(arg, paramIndex, parseParameter) / 100;
   328     else
   302     else
   329         begin
   303         begin
   330         //Assume the first "non parameter" is the demo file, anything else is invalid
   304         //Assume the first "non parameter" is the demo file, anything else is invalid
   331         if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
   305         if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
   332             recordFileName := cmd
   306             recordFileName := cmd
   337             end;
   311             end;
   338         end;
   312         end;
   339     end;
   313     end;
   340 end;
   314 end;
   341 
   315 
   342 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt);
       
   343 var index, tmpInt: LongInt;
       
   344     isBool, isValid: Boolean;
       
   345     cmd, arg, newSyntax: string;
       
   346 begin
       
   347     WriteLn(stdout, 'WARNING: You are using a deprecated command, which could be removed in a future version!');
       
   348     WriteLn(stdout, '         Consider updating to the latest syntax, which is much more flexible!');
       
   349     WriteLn(stdout, '         Run "hwegine --help" to learn it!');
       
   350     WriteLn(stdout, '');
       
   351 
       
   352     index:= 0;
       
   353     tmpInt:= 1;
       
   354     while (index < size) do
       
   355         begin
       
   356         newSyntax:= '';
       
   357         inc(paramIndex);
       
   358         cmd:= cmdarray[index];
       
   359         arg:= cmdarray[paramIndex];
       
   360         isValid:= (cmd<>'--depth');
       
   361 
       
   362         // check if the parameter is a boolean one
       
   363         isBool:= (cmd = '--nomusic') or (cmd = '--nosound') or (cmd = '--nodampen') or (cmd = '--fullscreen') or (cmd = '--showfps') or (cmd = '--altdmg') or (cmd = '--no-teamtag') or (cmd = '--no-hogtag') or (cmd = '--no-healthtag') or (cmd = '--translucent-tags');
       
   364         if isBool and (arg='0') then
       
   365             isValid:= false;
       
   366         if (cmd='--nomusic') or (cmd='--nosound') or (cmd='--nodampen') then
       
   367             isValid:= not isValid;
       
   368 
       
   369         if isValid then
       
   370             begin
       
   371             parseParameter(cmd, arg, tmpInt);
       
   372             newSyntax:= newSyntax + cmd + ' ';
       
   373             if not isBool then
       
   374                 newSyntax:= newSyntax + arg + ' ';
       
   375             end;
       
   376         inc(index);
       
   377         end;
       
   378 
       
   379     WriteLn(stdout, 'Attempted to automatically convert to the new syntax:');
       
   380     WriteLn(stdout, newSyntax);
       
   381     WriteLn(stdout, '');
       
   382 end;
       
   383 
       
   384 procedure parseCommandLine;
   316 procedure parseCommandLine;
   385 var paramIndex: LongInt;
   317 var paramIndex: LongInt;
   386     paramTotal: LongInt;
   318     paramTotal: LongInt;
   387     index, nextIndex: LongInt;
   319     index, nextIndex: LongInt;
   388     wrongParameter: boolean;
   320     wrongParameter: boolean;
   389 //var tmpInt: LongInt;
   321 //var tmpInt: LongInt;
   390 begin
   322 begin
   391 
   323 
   392     paramIndex:= {$IFDEF HWLIBRARY}0{$ELSE}1{$ENDIF};
   324     paramIndex:= {$IFDEF HWLIBRARY}0{$ELSE}1{$ENDIF};
   393     paramTotal:= ParamCount; //-1 because pascal enumeration is inclusive
   325     paramTotal:= ParamCount; //-1 because pascal enumeration is inclusive
   394     (*
       
   395     WriteLn(stdout, 'total parameters: ' + inttostr(paramTotal));
       
   396     tmpInt:= 0;
       
   397     while (tmpInt <= paramTotal) do
       
   398         begin
       
   399         WriteLn(stdout, inttostr(tmpInt) + ': ' + {$IFDEF HWLIBRARY}argv[tmpInt]{$ELSE}paramCount(tmpInt){$ENDIF});
       
   400         inc(tmpInt);
       
   401         end;
       
   402     *)
       
   403     wrongParameter:= false;
   326     wrongParameter:= false;
   404     while (paramIndex <= paramTotal) do
   327     while (paramIndex <= paramTotal) do
   405         begin
   328         begin
   406         // avoid going past the number of paramTotal (esp. w/ library)
   329         // avoid going past the number of paramTotal (esp. w/ library)
   407         index:= paramIndex;
   330         index:= paramIndex;
   440             WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '".');
   363             WriteLn(stdout, 'Attempting to play demo file "' + recordFilename + '".');
   441 
   364 
   442     if (GameType = gmtBadSyntax) then
   365     if (GameType = gmtBadSyntax) then
   443         WriteLn(stderr, 'Please use --help to see possible arguments and their usage.');
   366         WriteLn(stderr, 'Please use --help to see possible arguments and their usage.');
   444 
   367 
   445     (*
       
   446     WriteLn(stdout,'PathPrefix:     ' + PathPrefix);
       
   447     WriteLn(stdout,'UserPathPrefix: ' + UserPathPrefix);
       
   448     *)
       
   449 end;
   368 end;
   450 
   369 
   451 end.
   370 end.
   452 
   371