hedgewars/ArgParsers.pas
changeset 15299 3bf780084c86
parent 14677 93429d8f6b3f
child 15300 a3823f0916b8
equal deleted inserted replaced
15298:976b3ed9b1fd 15299:3bf780084c86
    85     WriteLn(stdout, '  --locale <name of file>: Set the game language (en.txt for example)');
    85     WriteLn(stdout, '  --locale <name of file>: Set the game language (en.txt for example)');
    86     WriteLn(stdout, '');
    86     WriteLn(stdout, '');
    87     WriteLn(stdout, 'Graphics:');
    87     WriteLn(stdout, 'Graphics:');
    88     WriteLn(stdout, '  --width <width in pixels>: Set game window width');
    88     WriteLn(stdout, '  --width <width in pixels>: Set game window width');
    89     WriteLn(stdout, '  --height <height in pixels>: Set game window height');
    89     WriteLn(stdout, '  --height <height in pixels>: Set game window height');
       
    90     WriteLn(stdout, '  --maximized: Start in maximized window');
    90     WriteLn(stdout, '  --fullscreen: Start in fullscreen');
    91     WriteLn(stdout, '  --fullscreen: Start in fullscreen');
    91     WriteLn(stdout, '  --fullscreen-width <width in pixels>: Set fullscreen width');
    92     WriteLn(stdout, '  --fullscreen-width <width in pixels>: Set fullscreen width');
    92     WriteLn(stdout, '  --fullscreen-height <height in pixels>: Set fullscreen height');
    93     WriteLn(stdout, '  --fullscreen-height <height in pixels>: Set fullscreen height');
    93     WriteLn(stdout, '  --low-quality: Lowers the game quality');
    94     WriteLn(stdout, '  --low-quality: Lowers the game quality');
    94     WriteLn(stdout, '  --zoom <percent>: Start with custom zoom level');
    95     WriteLn(stdout, '  --zoom <percent>: Start with custom zoom level');
   250 end;
   251 end;
   251 
   252 
   252 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt); forward;
   253 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt); forward;
   253 
   254 
   254 function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
   255 function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
   255 const videoarray: array [0..4] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth');
   256 const videoarray: array [0..5] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--maximized', '--depth');
   256       audioarray: array [0..2] of string = ('--volume','--nomusic','--nosound');
   257       audioarray: array [0..2] of string = ('--volume','--nomusic','--nosound');
   257       otherarray: array [0..2] of string = ('--locale','--fullscreen','--showfps');
   258       otherarray: array [0..2] of string = ('--locale','--fullscreen','--showfps');
   258       mediaarray: array [0..9] of string = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
   259       mediaarray: array [0..10] of string = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--maximized', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
   259       allarray: array [0..18] 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');
   260       allarray: array [0..19] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--maximized', '--depth', '--volume','--nomusic','--nosound','--nodampen','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags');
   260       reallyAll: array[0..39] of shortstring = (
   261       reallyAll: array[0..40] of shortstring = (
   261                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
   262                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
   262                 '--height', '--frame-interval', '--volume','--nomusic', '--nosound', '--nodampen',
   263                 '--height', '--maximized', '--frame-interval', '--volume','--nomusic', '--nosound', '--nodampen',
   263                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
   264                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
   264                 '--zoom',
   265                 '--zoom',
   265   {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
   266   {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
   266   {internal}    '--internal', '--port', '--recorder', '--landpreview',
   267   {internal}    '--internal', '--port', '--recorder', '--landpreview',
   267   {misc}        '--stats-only', '--gci', '--help','--protocol', '--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags','--lua-test','--no-holiday-silliness');
   268   {misc}        '--stats-only', '--gci', '--help','--protocol', '--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags','--lua-test','--no-holiday-silliness');
   280         {--locale}               2 : cLanguageFName    := getstringParameter (arg, paramIndex, parseParameter);
   281         {--locale}               2 : cLanguageFName    := getstringParameter (arg, paramIndex, parseParameter);
   281         {--fullscreen-width}     3 : cFullscreenWidth  := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenWidth);
   282         {--fullscreen-width}     3 : cFullscreenWidth  := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenWidth);
   282         {--fullscreen-height}    4 : cFullscreenHeight := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenHeight);
   283         {--fullscreen-height}    4 : cFullscreenHeight := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenHeight);
   283         {--width}                5 : cWindowedWidth    := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenWidth);
   284         {--width}                5 : cWindowedWidth    := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenWidth);
   284         {--height}               6 : cWindowedHeight   := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenHeight);
   285         {--height}               6 : cWindowedHeight   := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenHeight);
   285         {--frame-interval}       7 : cTimerInterval    := getLongIntParameter(arg, paramIndex, parseParameter);
   286         {--maximized}            7 : cWindowedMaximized:= true;
   286         {--volume}               8 : SetVolume          ( max(getLongIntParameter(arg, paramIndex, parseParameter), 0) );
   287         {--frame-interval}       8 : cTimerInterval    := getLongIntParameter(arg, paramIndex, parseParameter);
   287         {--nomusic}              9 : SetMusic           ( false );
   288         {--volume}               9 : SetVolume          ( max(getLongIntParameter(arg, paramIndex, parseParameter), 0) );
   288         {--nosound}             10 : SetSound           ( false );
   289         {--nomusic}             10 : SetMusic           ( false );
   289         {--nodampen}            11 : SetAudioDampen     ( false );
   290         {--nosound}             11 : SetSound           ( false );
   290         {--fullscreen}          12 : cFullScreen       := true;
   291         {--nodampen}            12 : SetAudioDampen     ( false );
   291         {--showfps}             13 : cShowFPS          := true;
   292         {--fullscreen}          13 : cFullScreen       := true;
   292         {--altdmg}              14 : cAltDamage        := true;
   293         {--showfps}             14 : cShowFPS          := true;
   293         {--low-quality}         15 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
   294         {--altdmg}              15 : cAltDamage        := true;
   294         {--raw-quality}         16 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
   295         {--low-quality}         16 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
   295         {--stereo}              17 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
   296         {--raw-quality}         17 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
   296         {--nick}                18 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
   297         {--stereo}              18 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
   297         {--zoom}                19 : setZoom(arg, paramIndex, parseParameter);
   298         {--nick}                19 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
       
   299         {--zoom}                20 : setZoom(arg, paramIndex, parseParameter);
   298         {deprecated options}
   300         {deprecated options}
   299         {--depth}               20 : setDepth(paramIndex);
   301         {--depth}               21 : setDepth(paramIndex);
   300         {--set-video}           21 : parseClassicParameter(videoarray,5,paramIndex);
   302         {--set-video}           22 : parseClassicParameter(videoarray,5,paramIndex);
   301         {--set-audio}           22 : parseClassicParameter(audioarray,3,paramIndex);
   303         {--set-audio}           23 : parseClassicParameter(audioarray,3,paramIndex);
   302         {--set-other}           23 : parseClassicParameter(otherarray,3,paramIndex);
   304         {--set-other}           24 : parseClassicParameter(otherarray,3,paramIndex);
   303         {--set-multimedia}      24 : parseClassicParameter(mediaarray,10,paramIndex);
   305         {--set-multimedia}      25 : parseClassicParameter(mediaarray,10,paramIndex);
   304         {--set-everything}      25 : parseClassicParameter(allarray,14,paramIndex);
   306         {--set-everything}      26 : parseClassicParameter(allarray,14,paramIndex);
   305         {"internal" options}
   307         {"internal" options}
   306         {--internal}            26 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
   308         {--internal}            27 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
   307         {--port}                27 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
   309         {--port}                28 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
   308         {--recorder}            28 : startVideoRecording(paramIndex);
   310         {--recorder}            29 : startVideoRecording(paramIndex);
   309         {--landpreview}         29 : GameType := gmtLandPreview;
   311         {--landpreview}         30 : GameType := gmtLandPreview;
   310         {anything else}
   312         {anything else}
   311         {--stats-only}          30 : statsOnlyGame();
   313         {--stats-only}          31 : statsOnlyGame();
   312         {--gci}                 31 : GciEasterEgg();
   314         {--gci}                 32 : GciEasterEgg();
   313         {--help}                32 : DisplayUsage();
   315         {--help}                33 : DisplayUsage();
   314         {--protocol}            33 : DisplayProtocol();
   316         {--protocol}            34 : DisplayProtocol();
   315         {--no-teamtag}          34 : cTagsMask := cTagsMask and (not htTeamName);
   317         {--no-teamtag}          35 : cTagsMask := cTagsMask and (not htTeamName);
   316         {--no-hogtag}           35 : cTagsMask := cTagsMask and (not htName);
   318         {--no-hogtag}           36 : cTagsMask := cTagsMask and (not htName);
   317         {--no-healthtag}        36 : cTagsMask := cTagsMask and (not htHealth);
   319         {--no-healthtag}        37 : cTagsMask := cTagsMask and (not htHealth);
   318         {--translucent-tags}    37 : cTagsMask := cTagsMask or htTransparent;
   320         {--translucent-tags}    38 : cTagsMask := cTagsMask or htTransparent;
   319         {--lua-test}            38 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
   321         {--lua-test}            39 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
   320         {--no-holiday-silliness} 39 : cHolidaySilliness:= false;
   322         {--no-holiday-silliness} 40 : cHolidaySilliness:= false;
   321     else
   323     else
   322         begin
   324         begin
   323         //Assume the first "non parameter" is the demo file, anything else is invalid
   325         //Assume the first "non parameter" is the demo file, anything else is invalid
   324         if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
   326         if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
   325             recordFileName := cmd
   327             recordFileName := cmd
   351         cmd:= cmdarray[index];
   353         cmd:= cmdarray[index];
   352         arg:= cmdarray[paramIndex];
   354         arg:= cmdarray[paramIndex];
   353         isValid:= (cmd<>'--depth');
   355         isValid:= (cmd<>'--depth');
   354 
   356 
   355         // check if the parameter is a boolean one
   357         // check if the parameter is a boolean one
   356         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');
   358         isBool:= (cmd = '--nomusic') or (cmd = '--nosound') or (cmd = '--nodampen') or (cmd = '--maximized') 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');
   357         if isBool and (arg='0') then
   359         if isBool and (arg='0') then
   358             isValid:= false;
   360             isValid:= false;
   359         if (cmd='--nomusic') or (cmd='--nosound') or (cmd='--nodampen') then
   361         if (cmd='--nomusic') or (cmd='--nosound') or (cmd='--nodampen') then
   360             isValid:= not isValid;
   362             isValid:= not isValid;
   361 
   363