-
Notifications
You must be signed in to change notification settings - Fork 2
/
AutoDoorifier.pas
93 lines (79 loc) · 2.95 KB
/
AutoDoorifier.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
{
New script template, only shows processed records
Assigning any nonzero value to Result will terminate script
}
unit AutoDoorifier;
uses praUtil;
var
setupDone: boolean;
autoDoorFile: IwbFile;
ToFile: IwbFile;
autoDoorKeyword: IInterface;
function doSetup(e: IInterface): boolean;
begin
Result := false;
if not Assigned(ToFile) then begin
ToFile := ShowFileSelectDialog('Select file to create overrides in');
if not Assigned(ToFile) then begin
Exit;
end;
end;
autoDoorFile := findFile('AutoDoors.esp');
if(not assigned(autoDoorFile)) then begin
AddMessage('AutoDoors.esp not found!');
exit;
end;
autoDoorKeyword := MainRecordByEditorID(GroupBySignature(autoDoorFile, 'KYWD'), 'AD_CrossModUniversalDoorSupport');
setupDone := true;
Result := true;
end;
function getDisplayString(e: IInterface): string;
var
dName: string;
begin
dName := DisplayName(e);
if(dName = '') then begin
dName := '<no name set>';
end else begin
dName := ''''+dName+'''';
end;
Result := GetElementEditValues(e, 'EDID') + ' '+dName;
end;
// called for every record selected in xEdit
function Process(e: IInterface): integer;
var
sig: string;
dName: string;
newElem: IInterface;
begin
Result := 0;
if(not setupDone) then begin
if(not doSetup(e)) then begin
Result := 1;
exit;
end;
end;
sig := signature(e);
if(sig = 'DOOR') then begin
if(not hasKeywordByPath(e, autoDoorKeyword, 'KWDA')) then begin
// check if we have this one already
newElem := MainRecordByEditorID(GroupBySignature(ToFile, 'DOOR'), GetElementEditValues(e, 'EDID'));
dName := getDisplayString(e);
if(assigned(newElem)) then begin
if(hasKeywordByPath(newElem, autoDoorKeyword, 'KWDA')) then begin
AddMessage(dName+' is already done');
exit;
end else begin
AddMessage('Adding keyword to existing override of '+dName);
end;
end else begin
AddMessage('Creating override with keyword for '+dName);
// addRequiredMastersSilent(e, ToFile);
newElem := getOrCreateElementOverride(e, ToFile);
end;
addRequiredMastersSilent(autoDoorKeyword, ToFile);
addKeywordByPath(newElem, autoDoorKeyword, 'KWDA');
end;
end;
end;
end.