-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRecompileScripts.pas
112 lines (91 loc) · 3.1 KB
/
RecompileScripts.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
{
Recompiles any scripts or fragments in the selected records.
}
unit RecompileScripts;
uses praCompiler;
var
scriptsDone: TSTringList;
procedure processScriptName(scriptName: string);
var
sourcePath: string;
destDir: string;
begin
if(scriptsDone.indexOf(scriptName) >= 0) then begin
exit;
end;
scriptsDone.add(scriptName);
AddMessage('=================');
AddMessage('Recompiling: '+scriptName);
compileScriptByName(scriptName);
end;
procedure processScriptElem(script: IInterface);
var
curScriptName: string;
begin
curScriptName := GetElementEditValues(script, 'scriptName');
if(curScriptName <> '') then begin
processScriptName(curScriptName);
end;
end;
function Initialize: integer;
begin
initCompiler();
scriptsDone := TSTringList.create;
Result := 0;
end;
procedure processScripts(e: IInterface);
var
vmad, scriptList, frags, aliases: IInterface;
curScript, curAlias: IInterface;
i, j: integer;
oldScriptName: string;
begin
vmad := ElementByName(e, 'VMAD - Virtual Machine Adapter');
if(not assigned(vmad)) then begin
exit;
end;
// scripts
scriptList := ElementByName(vmad, 'Scripts');
if(assigned(scriptList)) then begin
for i := 0 to ElementCount(scriptList)-1 do begin
curScript := ElementByIndex(scriptList, i);
processScriptElem(curScript);
end;
end;
// fragments
frags := ElementByName(vmad, 'Script Fragments');
if(assigned(frags)) then begin
curScript := ElementByName(frags, 'Script');
if(assigned(curScript)) then begin
processScriptElem(curScript);
end;
// sometimes frags itself has a script
processScriptElem(frags);
end;
// quest aliases
aliases := ElementByName(vmad, 'Aliases');
if(assigned(aliases)) then begin
for i := 0 to ElementCount(aliases)-1 do begin
curAlias := ElementByIndex(aliases, i);
scriptList := ElementByName(curAlias, 'Alias Scripts');
for j := 0 to ElementCount(scriptList)-1 do begin
curScript := ElementByIndex(scriptList, j);
processScriptElem(curScript);
end;
end;
end;
end;
// called for every record selected in xEdit
function Process(e: IInterface): integer;
begin
Result := 0;
processScripts(e);
end;
// Called after processing
// You can remove it if script doesn't require finalization code
function Finalize: integer;
begin
scriptsDone.free();
Result := 0;
end;
end.