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');
|
|
57 |
scriptsNumber:= 0;
|
|
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 |
|
|
69 |
scriptsList:= GetMem(sizeof(scriptsList^) * scriptsNumber);
|
|
70 |
|
|
71 |
script:= scriptsList;
|
|
72 |
tmp:= filesList;
|
|
73 |
while tmp^ <> nil do
|
|
74 |
begin
|
|
75 |
s:= shortstring(tmp^);
|
|
76 |
l:= length(s);
|
|
77 |
if (l > 4) and (copy(s, l - 3, 4) = '.lua') then
|
|
78 |
begin
|
10517
|
79 |
loadScript(script^, copy(s, 1, l - 4), '/Config/Scripts/' + s);
|
10458
|
80 |
inc(script)
|
|
81 |
end;
|
|
82 |
inc(tmp)
|
|
83 |
end;
|
|
84 |
|
|
85 |
pfsFreeList(filesList)
|
|
86 |
end;
|
|
87 |
|
|
88 |
|
|
89 |
function getScriptsList: PPChar; cdecl;
|
|
90 |
var i, t, l: Longword;
|
|
91 |
script: PScript;
|
|
92 |
begin
|
|
93 |
if scriptsList = nil then
|
|
94 |
loadScripts;
|
|
95 |
|
|
96 |
t:= scriptsNumber;
|
|
97 |
if t >= MAX_SCRIPT_NAMES then
|
|
98 |
t:= MAX_SCRIPT_NAMES;
|
|
99 |
|
|
100 |
script:= scriptsList;
|
|
101 |
for i:= 0 to Pred(t) do
|
|
102 |
begin
|
|
103 |
l:= length(script^.scriptName);
|
|
104 |
if l >= 255 then l:= 254;
|
|
105 |
script^.scriptName[l + 1]:= #0;
|
|
106 |
listOfScriptNames[i]:= @script^.scriptName[1];
|
|
107 |
inc(script)
|
|
108 |
end;
|
|
109 |
|
|
110 |
listOfScriptNames[t]:= nil;
|
|
111 |
|
|
112 |
getScriptsList:= listOfScriptNames
|
|
113 |
end;
|
|
114 |
|
|
115 |
|
|
116 |
procedure freeScriptsList;
|
|
117 |
begin
|
|
118 |
if scriptsList <> nil then
|
|
119 |
FreeMem(scriptsList, sizeof(scriptsList^) * scriptsNumber)
|
|
120 |
end;
|
|
121 |
|
|
122 |
end.
|