10458
|
1 |
unit uFLScripts;
|
|
2 |
interface
|
|
3 |
uses uFLTypes;
|
|
4 |
|
|
5 |
function getScriptsList: PPChar; cdecl;
|
|
6 |
procedure freeScriptsList;
|
|
7 |
|
|
8 |
implementation
|
11456
|
9 |
uses uFLUtils, uFLIPC, uPhysFSLayer, uFLThemes;
|
10458
|
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 |
l:= length(s);
|
|
64 |
if (l > 4) and (copy(s, l - 3, 4) = '.lua') then inc(scriptsNumber);
|
|
65 |
inc(tmp)
|
|
66 |
end;
|
|
67 |
|
10612
|
68 |
scriptsList:= GetMem(sizeof(scriptsList^) * (scriptsNumber + 1));
|
10458
|
69 |
|
|
70 |
script:= scriptsList;
|
10612
|
71 |
|
|
72 |
// add 'normal' script
|
|
73 |
script^.scriptName:= 'Normal';
|
|
74 |
script^.description:= 'Normal gameplay';
|
|
75 |
inc(script);
|
|
76 |
|
|
77 |
// fill the rest from *.lua list
|
10458
|
78 |
tmp:= filesList;
|
|
79 |
while tmp^ <> nil do
|
|
80 |
begin
|
|
81 |
s:= shortstring(tmp^);
|
|
82 |
l:= length(s);
|
|
83 |
if (l > 4) and (copy(s, l - 3, 4) = '.lua') then
|
|
84 |
begin
|
10517
|
85 |
loadScript(script^, copy(s, 1, l - 4), '/Config/Scripts/' + s);
|
10458
|
86 |
inc(script)
|
|
87 |
end;
|
|
88 |
inc(tmp)
|
|
89 |
end;
|
|
90 |
|
|
91 |
pfsFreeList(filesList)
|
|
92 |
end;
|
|
93 |
|
|
94 |
|
|
95 |
function getScriptsList: PPChar; cdecl;
|
|
96 |
var i, t, l: Longword;
|
|
97 |
script: PScript;
|
|
98 |
begin
|
|
99 |
if scriptsList = nil then
|
|
100 |
loadScripts;
|
|
101 |
|
|
102 |
t:= scriptsNumber;
|
|
103 |
if t >= MAX_SCRIPT_NAMES then
|
|
104 |
t:= MAX_SCRIPT_NAMES;
|
|
105 |
|
|
106 |
script:= scriptsList;
|
|
107 |
for i:= 0 to Pred(t) do
|
|
108 |
begin
|
|
109 |
l:= length(script^.scriptName);
|
|
110 |
if l >= 255 then l:= 254;
|
|
111 |
script^.scriptName[l + 1]:= #0;
|
|
112 |
listOfScriptNames[i]:= @script^.scriptName[1];
|
|
113 |
inc(script)
|
|
114 |
end;
|
|
115 |
|
|
116 |
listOfScriptNames[t]:= nil;
|
|
117 |
|
|
118 |
getScriptsList:= listOfScriptNames
|
|
119 |
end;
|
|
120 |
|
|
121 |
|
|
122 |
procedure freeScriptsList;
|
|
123 |
begin
|
|
124 |
if scriptsList <> nil then
|
|
125 |
FreeMem(scriptsList, sizeof(scriptsList^) * scriptsNumber)
|
|
126 |
end;
|
|
127 |
|
|
128 |
end.
|