hedgewars/uLocale.pas
branchphysfslayer
changeset 8028 dc30104660d3
parent 7069 bcf9d8e64e92
child 8096 453917e94e55
child 8107 ee21b816394f
equal deleted inserted replaced
8025:07862ab415c8 8028:dc30104660d3
    32 {$IFDEF HWLIBRARY}
    32 {$IFDEF HWLIBRARY}
    33 procedure LoadLocaleWrapper(str: pchar); cdecl; export;
    33 procedure LoadLocaleWrapper(str: pchar); cdecl; export;
    34 {$ENDIF}
    34 {$ENDIF}
    35 
    35 
    36 implementation
    36 implementation
    37 uses uRandom, uUtils, uVariables, uDebug;
    37 uses uRandom, uUtils, uVariables, uDebug, uPhysFSLayer;
    38 
    38 
    39 var trevt: array[TEventId] of array [0..Pred(MAX_EVENT_STRINGS)] of ansistring;
    39 var trevt: array[TEventId] of array [0..Pred(MAX_EVENT_STRINGS)] of ansistring;
    40     trevt_n: array[TEventId] of integer;
    40     trevt_n: array[TEventId] of integer;
    41 
    41 
    42 procedure LoadLocale(FileName: shortstring);
    42 procedure LoadLocale(FileName: shortstring);
    43 var s: ansistring;
    43 var s: shortstring;
    44     f: textfile;
    44     f: pfsFile;
    45     a, b, c: LongInt;
    45     a, b, c: LongInt;
    46     first: array[TEventId] of boolean;
    46     first: array[TEventId] of boolean;
    47     e: TEventId;
    47     e: TEventId;
    48     loaded: boolean;
    48     loaded: boolean;
    49 begin
    49 begin
    50 loaded:= false;
    50 loaded:= false;
    51 for e:= Low(TEventId) to High(TEventId) do
    51 for e:= Low(TEventId) to High(TEventId) do
    52     first[e]:= true;
    52     first[e]:= true;
    53 
    53 
    54 {$I-} // iochecks off
    54 f:= pfsOpenRead(FileName);
    55 Assign(f, FileName);
    55 TryDo(f <> nil, 'Cannot load locale "' + FileName + '"', false);
    56 filemode:= 0; // readonly
    56 
    57 Reset(f);
    57 if f <> nil then
    58 if IOResult = 0 then
       
    59     loaded:= true;
       
    60 TryDo(loaded, 'Cannot load locale "' + FileName + '"', false);
       
    61 if loaded then
       
    62     begin
    58     begin
    63     while not eof(f) do
    59     while not pfsEof(f) do
    64         begin
    60         begin
    65         readln(f, s);
    61         pfsReadLn(f, s);
    66         if Length(s) = 0 then
    62         if Length(s) = 0 then
    67             continue;
    63             continue;
    68         if (s[1] < '0') or (s[1] > '9') then
    64         if (s[1] < '0') or (s[1] > '9') then
    69             continue;
    65             continue;
    70         TryDo(Length(s) > 6, 'Load locale: empty string', true);
    66         TryDo(Length(s) > 6, 'Load locale: empty string', true);
    97                 trammod[TAmmoStrId(b)]:= s;
    93                 trammod[TAmmoStrId(b)]:= s;
    98             5: if (b >=0) and (b <= ord(High(TGoalStrId))) then
    94             5: if (b >=0) and (b <= ord(High(TGoalStrId))) then
    99                 trgoal[TGoalStrId(b)]:= s;
    95                 trgoal[TGoalStrId(b)]:= s;
   100            end;
    96            end;
   101        end;
    97        end;
   102    Close(f);
    98    pfsClose(f);
   103    end;
    99    end;
   104 {$I+}
       
   105 end;
   100 end;
   106 
   101 
   107 function GetEventString(e: TEventId): ansistring;
   102 function GetEventString(e: TEventId): ansistring;
   108 begin
   103 begin
   109     if trevt_n[e] = 0 then // no messages for this event type?
   104     if trevt_n[e] = 0 then // no messages for this event type?