10458
|
1 |
unit uFLScripts;
|
|
2 |
interface
|
|
3 |
uses uFLTypes;
|
|
4 |
|
|
5 |
function getScriptsList: PPChar; cdecl;
|
|
6 |
procedure freeScriptsList;
|
|
7 |
|
|
8 |
implementation
|
|
9 |
uses uFLUtils, uFLIPC, uPhysFSLayer, uFLData;
|
|
10 |
|
|
11 |
const MAX_SCRIPT_NAMES = 64;
|
|
12 |
type
|
|
13 |
TScript = record
|
|
14 |
scriptName: shortstring;
|
|
15 |
description: shortstring;
|
|
16 |
gameScheme, weapons: shortstring;
|
|
17 |
end;
|
|
18 |
PScript = ^TScript;
|
|
19 |
var
|
|
20 |
scriptsList: PScript;
|
|
21 |
scriptsNumber: Longword;
|
|
22 |
listOfScriptNames: array[0..MAX_SCRIPT_NAMES] of PChar;
|
|
23 |
|
10517
|
24 |
procedure loadScript(var script: TScript; scriptName, fileName: shortstring);
|
10458
|
25 |
var f: PFSFile;
|
|
26 |
begin
|
10517
|
27 |
underScore2Space(scriptName);
|
|
28 |
script.scriptName:= scriptName;
|
|
29 |
script.description:= scriptName + ' script description';
|
10458
|
30 |
|
10517
|
31 |
f:= pfsOpenRead(copy(fileName, 1, length(fileName) - 4) + '.txt');
|
|
32 |
|
|
33 |
script.gameScheme:= '';
|
|
34 |
script.weapons:= '';
|
|
35 |
|
|
36 |
if f <> nil then
|
10458
|
37 |
begin
|
10517
|
38 |
if not pfsEOF(f) then
|
|
39 |
begin
|
|
40 |
pfsReadLn(f, script.gameScheme);
|
10458
|
41 |
|
10517
|
42 |
if not pfsEOF(f) then
|
|
43 |
pfsReadLn(f, script.weapons);
|
|
44 |
end;
|
|
45 |
|
|
46 |
pfsClose(f)
|
|
47 |
end
|
10458
|
48 |
end;
|
|
49 |
|
|
50 |
procedure loadScripts;
|
|
51 |
var filesList, tmp: PPChar;
|
|
52 |
script: PScript;
|
|
53 |
s: shortstring;
|
|
54 |
l: Longword;
|
|
55 |
begin
|
|
56 |
filesList:= pfsEnumerateFiles('/Scripts/Multiplayer');
|
10612
|
57 |
scriptsNumber:= 1;
|
10458
|
58 |
|
|
59 |
tmp:= filesList;
|
|
60 |
while tmp^ <> nil do
|
|
61 |
begin
|
|
62 |
s:= shortstring(tmp^);
|
|
63 |
writeln(stderr, '> ', s);
|
|
64 |
l:= length(s);
|
|
65 |
if (l > 4) and (copy(s, l - 3, 4) = '.lua') then inc(scriptsNumber);
|
|
66 |
inc(tmp)
|
|
67 |
end;
|
|
68 |
|
10612
|
69 |
scriptsList:= GetMem(sizeof(scriptsList^) * (scriptsNumber + 1));
|
10458
|
70 |
|
|
71 |
script:= scriptsList;
|
10612
|
72 |
|
|
73 |
// add 'normal' script
|
|
74 |
script^.scriptName:= 'Normal';
|
|
75 |
script^.description:= 'Normal gameplay';
|
|
76 |
inc(script);
|
|
77 |
|
|
78 |
// fill the rest from *.lua list
|
10458
|
79 |
tmp:= filesList;
|
|
80 |
while tmp^ <> nil do
|
|
81 |
begin
|
|
82 |
s:= shortstring(tmp^);
|
|
83 |
l:= length(s);
|
|
84 |
if (l > 4) and (copy(s, l - 3, 4) = '.lua') then
|
|
85 |
begin
|
10517
|
86 |
loadScript(script^, copy(s, 1, l - 4), '/Config/Scripts/' + s);
|
10458
|
87 |
inc(script)
|
|
88 |
end;
|
|
89 |
inc(tmp)
|
|
90 |
end;
|
|
91 |
|
|
92 |
pfsFreeList(filesList)
|
|
93 |
end;
|
|
94 |
|
|
95 |
|
|
96 |
function getScriptsList: PPChar; cdecl;
|
|
97 |
var i, t, l: Longword;
|
|
98 |
script: PScript;
|
|
99 |
begin
|
|
100 |
if scriptsList = nil then
|
|
101 |
loadScripts;
|
|
102 |
|
|
103 |
t:= scriptsNumber;
|
|
104 |
if t >= MAX_SCRIPT_NAMES then
|
|
105 |
t:= MAX_SCRIPT_NAMES;
|
|
106 |
|
|
107 |
script:= scriptsList;
|
|
108 |
for i:= 0 to Pred(t) do
|
|
109 |
begin
|
|
110 |
l:= length(script^.scriptName);
|
|
111 |
if l >= 255 then l:= 254;
|
|
112 |
script^.scriptName[l + 1]:= #0;
|
|
113 |
listOfScriptNames[i]:= @script^.scriptName[1];
|
|
114 |
inc(script)
|
|
115 |
end;
|
|
116 |
|
|
117 |
listOfScriptNames[t]:= nil;
|
|
118 |
|
|
119 |
getScriptsList:= listOfScriptNames
|
|
120 |
end;
|
|
121 |
|
|
122 |
|
|
123 |
procedure freeScriptsList;
|
|
124 |
begin
|
|
125 |
if scriptsList <> nil then
|
|
126 |
FreeMem(scriptsList, sizeof(scriptsList^) * scriptsNumber)
|
|
127 |
end;
|
|
128 |
|
|
129 |
end.
|