author | unc0rr |
Sun, 14 Jan 2007 21:51:17 +0000 | |
changeset 337 | a46abb65eb0c |
parent 302 | 7aca131ecd7f |
child 351 | 29bc9c36ad5f |
permissions | -rw-r--r-- |
184 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2006 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
19 |
unit uLocale; |
|
20 |
interface |
|
21 |
type TAmmoStrId = (sidGrenade, sidClusterBomb, sidBazooka, sidUFO, sidShotgun, |
|
22 |
sidPickHammer, sidSkip, sidRope, sidMine, sidDEagle, |
|
211 | 23 |
sidDynamite, sidBaseballBat, sidFirePunch, sidSeconds, |
302 | 24 |
sidParachute, sidAirAttack, sidMineStrike, sidBlowTorch); |
285 | 25 |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
263
diff
changeset
|
26 |
TMsgStrId = (sidStartFight, sidDraw, sidWinner, sidVolume, sidPaused); |
285 | 27 |
|
184 | 28 |
var trammo: array[TAmmoStrId] of string; |
29 |
trmsg: array[TMsgStrId] of string; |
|
30 |
||
31 |
procedure LoadLocale(FileName: string); |
|
32 |
function Format(fmt: shortstring; var arg: shortstring): shortstring; |
|
33 |
||
34 |
implementation |
|
35 |
uses uMisc; |
|
36 |
||
37 |
procedure LoadLocale(FileName: string); |
|
38 |
var s: shortstring; |
|
39 |
f: textfile; |
|
40 |
a, b, c: integer; |
|
41 |
begin |
|
42 |
{$I-} |
|
43 |
AssignFile(f, FileName); |
|
44 |
reset(f); |
|
45 |
TryDo(IOResult = 0, 'Cannot load locale "' + FileName + '"', true); |
|
46 |
while not eof(f) do |
|
47 |
begin |
|
48 |
readln(f, s); |
|
49 |
if Length(s) = 0 then continue; |
|
50 |
if s[1] = ';' then continue; |
|
51 |
TryDo(Length(s) > 6, 'Load locale: empty string', true); |
|
52 |
val(s[1]+s[2], a, c); |
|
53 |
TryDo(c = 0, 'Load locale: numbers should be two-digit', true); |
|
54 |
TryDo(s[3] = ':', 'Load locale: ":" expected', true); |
|
55 |
val(s[4]+s[5], b, c); |
|
56 |
TryDo(c = 0, 'Load locale: numbers should be two-digit', true); |
|
57 |
TryDo(s[6] = '=', 'Load locale: "=" expected', true); |
|
58 |
Delete(s, 1, 6); |
|
59 |
case a of |
|
60 |
0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b)]:= s; |
|
61 |
1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s; |
|
62 |
end; |
|
63 |
end; |
|
64 |
closefile(f) |
|
65 |
{$I+} |
|
66 |
end; |
|
67 |
||
68 |
function Format(fmt: shortstring; var arg: shortstring): shortstring; |
|
69 |
var i: integer; |
|
70 |
begin |
|
71 |
i:= Pos('%1', fmt); |
|
72 |
if i = 0 then Result:= fmt |
|
73 |
else Result:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) |
|
74 |
end; |
|
75 |
||
76 |
end. |