hedgewars/ArgParsers.pas
changeset 13628 d5e029b84e16
parent 13506 36f3f77e9b1b
child 13722 6cdb12449be7
equal deleted inserted replaced
13627:605767bbd022 13628:d5e029b84e16
    88     Writeln(stdout, ' --stereo [value]');
    88     Writeln(stdout, ' --stereo [value]');
    89     WriteLn(stdout, ' --raw-quality [flags]');
    89     WriteLn(stdout, ' --raw-quality [flags]');
    90     WriteLn(stdout, ' --low-quality');
    90     WriteLn(stdout, ' --low-quality');
    91     WriteLn(stdout, ' --nomusic');
    91     WriteLn(stdout, ' --nomusic');
    92     WriteLn(stdout, ' --nosound');
    92     WriteLn(stdout, ' --nosound');
       
    93     WriteLn(stdout, ' --nodampen');
    93     WriteLn(stdout, ' --fullscreen');
    94     WriteLn(stdout, ' --fullscreen');
    94     WriteLn(stdout, ' --showfps');
    95     WriteLn(stdout, ' --showfps');
    95     WriteLn(stdout, ' --altdmg');
    96     WriteLn(stdout, ' --altdmg');
    96     WriteLn(stdout, ' --no-teamtag');
    97     WriteLn(stdout, ' --no-teamtag');
    97     WriteLn(stdout, ' --no-hogtag');
    98     WriteLn(stdout, ' --no-hogtag');
   214 function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
   215 function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
   215 const videoarray: array [0..4] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth');
   216 const videoarray: array [0..4] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth');
   216       audioarray: array [0..2] of string = ('--volume','--nomusic','--nosound');
   217       audioarray: array [0..2] of string = ('--volume','--nomusic','--nosound');
   217       otherarray: array [0..2] of string = ('--locale','--fullscreen','--showfps');
   218       otherarray: array [0..2] of string = ('--locale','--fullscreen','--showfps');
   218       mediaarray: array [0..9] of string = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
   219       mediaarray: array [0..9] of string = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
   219       allarray: array [0..17] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth','--volume','--nomusic','--nosound','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags');
   220       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');
   220       reallyAll: array[0..35] of shortstring = (
   221       reallyAll: array[0..36] of shortstring = (
   221                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
   222                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
   222                 '--height', '--frame-interval', '--volume','--nomusic', '--nosound',
   223                 '--height', '--frame-interval', '--volume','--nomusic', '--nosound', '--nodampen',
   223                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
   224                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
   224   {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
   225   {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
   225   {internal}    '--internal', '--port', '--recorder', '--landpreview',
   226   {internal}    '--internal', '--port', '--recorder', '--landpreview',
   226   {misc}        '--stats-only', '--gci', '--help','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags','--lua-test');
   227   {misc}        '--stats-only', '--gci', '--help','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags','--lua-test');
   227 var cmdIndex: byte;
   228 var cmdIndex: byte;
   243         {--height}               6 : cWindowedHeight   := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenHeight);
   244         {--height}               6 : cWindowedHeight   := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenHeight);
   244         {--frame-interval}       7 : cTimerInterval    := getLongIntParameter(arg, paramIndex, parseParameter);
   245         {--frame-interval}       7 : cTimerInterval    := getLongIntParameter(arg, paramIndex, parseParameter);
   245         {--volume}               8 : SetVolume          ( max(getLongIntParameter(arg, paramIndex, parseParameter), 0) );
   246         {--volume}               8 : SetVolume          ( max(getLongIntParameter(arg, paramIndex, parseParameter), 0) );
   246         {--nomusic}              9 : SetMusic           ( false );
   247         {--nomusic}              9 : SetMusic           ( false );
   247         {--nosound}             10 : SetSound           ( false );
   248         {--nosound}             10 : SetSound           ( false );
   248         {--fullscreen}          11 : cFullScreen       := true;
   249         {--nodampen}            11 : SetAudioDampen     ( false );
   249         {--showfps}             12 : cShowFPS          := true;
   250         {--fullscreen}          12 : cFullScreen       := true;
   250         {--altdmg}              13 : cAltDamage        := true;
   251         {--showfps}             13 : cShowFPS          := true;
   251         {--low-quality}         14 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
   252         {--altdmg}              14 : cAltDamage        := true;
   252         {--raw-quality}         15 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
   253         {--low-quality}         15 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
   253         {--stereo}              16 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
   254         {--raw-quality}         16 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
   254         {--nick}                17 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
   255         {--stereo}              17 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
       
   256         {--nick}                18 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
   255         {deprecated options}
   257         {deprecated options}
   256         {--depth}               18 : setDepth(paramIndex);
   258         {--depth}               19 : setDepth(paramIndex);
   257         {--set-video}           19 : parseClassicParameter(videoarray,5,paramIndex);
   259         {--set-video}           20 : parseClassicParameter(videoarray,5,paramIndex);
   258         {--set-audio}           20 : parseClassicParameter(audioarray,3,paramIndex);
   260         {--set-audio}           21 : parseClassicParameter(audioarray,3,paramIndex);
   259         {--set-other}           21 : parseClassicParameter(otherarray,3,paramIndex);
   261         {--set-other}           22 : parseClassicParameter(otherarray,3,paramIndex);
   260         {--set-multimedia}      22 : parseClassicParameter(mediaarray,10,paramIndex);
   262         {--set-multimedia}      23 : parseClassicParameter(mediaarray,10,paramIndex);
   261         {--set-everything}      23 : parseClassicParameter(allarray,14,paramIndex);
   263         {--set-everything}      24 : parseClassicParameter(allarray,14,paramIndex);
   262         {"internal" options}
   264         {"internal" options}
   263         {--internal}            24 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
   265         {--internal}            25 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
   264         {--port}                25 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
   266         {--port}                26 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
   265         {--recorder}            26 : startVideoRecording(paramIndex);
   267         {--recorder}            27 : startVideoRecording(paramIndex);
   266         {--landpreview}         27 : GameType := gmtLandPreview;
   268         {--landpreview}         28 : GameType := gmtLandPreview;
   267         {anything else}
   269         {anything else}
   268         {--stats-only}          28 : statsOnlyGame();
   270         {--stats-only}          29 : statsOnlyGame();
   269         {--gci}                 29 : GciEasterEgg();
   271         {--gci}                 30 : GciEasterEgg();
   270         {--help}                30 : DisplayUsage();
   272         {--help}                31 : DisplayUsage();
   271         {--no-teamtag}          31 : cTagsMask := cTagsMask and (not htTeamName);
   273         {--no-teamtag}          32 : cTagsMask := cTagsMask and (not htTeamName);
   272         {--no-hogtag}           32 : cTagsMask := cTagsMask and (not htName);
   274         {--no-hogtag}           33 : cTagsMask := cTagsMask and (not htName);
   273         {--no-healthtag}        33 : cTagsMask := cTagsMask and (not htHealth);
   275         {--no-healthtag}        34 : cTagsMask := cTagsMask and (not htHealth);
   274         {--translucent-tags}    34 : cTagsMask := cTagsMask or htTransparent;
   276         {--translucent-tags}    35 : cTagsMask := cTagsMask or htTransparent;
   275         {--lua-test}            35 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
   277         {--lua-test}            36 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
   276     else
   278     else
   277         begin
   279         begin
   278         //Assume the first "non parameter" is the replay file, anything else is invalid
   280         //Assume the first "non parameter" is the replay file, anything else is invalid
   279         if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
   281         if (recordFileName = '') and (Copy(cmd,1,2) <> '--') then
   280             recordFileName := cmd
   282             recordFileName := cmd
   306         cmd:= cmdarray[index];
   308         cmd:= cmdarray[index];
   307         arg:= cmdarray[paramIndex];
   309         arg:= cmdarray[paramIndex];
   308         isValid:= (cmd<>'--depth');
   310         isValid:= (cmd<>'--depth');
   309 
   311 
   310         // check if the parameter is a boolean one
   312         // check if the parameter is a boolean one
   311         isBool:= (cmd = '--nomusic') or (cmd = '--nosound') 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');
   313         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');
   312         if isBool and (arg='0') then
   314         if isBool and (arg='0') then
   313             isValid:= false;
   315             isValid:= false;
   314         if (cmd='--nomusic') or (cmd='--nosound') then
   316         if (cmd='--nomusic') or (cmd='--nosound') or (cmd='--nodampen') then
   315             isValid:= not isValid;
   317             isValid:= not isValid;
   316 
   318 
   317         if isValid then
   319         if isValid then
   318             begin
   320             begin
   319             parseParameter(cmd, arg, tmpInt);
   321             parseParameter(cmd, arg, tmpInt);