Mator

[xedit] [Pascal] Test GetChildRecords

Sep 16th, 2015
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.48 KB | None | 0 0
  1. {
  2.   Test GetChildRecords
  3. }
  4. unit userscript;
  5.  
  6. const
  7.   saveRecords = true;
  8.   maxRecordsToSave = 10000;
  9.  
  10. procedure SaveRecordNames(var lst: TList; fn: string);
  11. var
  12.   sl: TStringList;
  13.   i: Integer;
  14. begin
  15.   sl := TStringList.Create;
  16.   for i := 0 to Pred(lst.Count) do
  17.     sl.Add(Name(ObjectToElement(TObject(lst[i]))));
  18.   AddMessage('  Saved to '+fn);
  19.   sl.SaveToFile(fn);
  20.   sl.Free;
  21. end;
  22.  
  23. procedure TestGetChildRecords(f: IInterface; gsig, sig: string);
  24. var
  25.   g: IInterface;
  26.   t: TDateTime;
  27.   lst: TList;
  28. begin
  29.   AddMessage(Format('Searching file %s for records matching %s in group %s', [GetFileName(f), sig, gsig]));
  30.   g := GroupBySignature(f, gsig);
  31.   if not Assigned(g) then begin
  32.     AddMessage('    Group not found!  Skipping.');
  33.     exit;
  34.   end;
  35.   t := Now;
  36.   lst := TList.Create;
  37.   GetChildRecords(g, sig, lst);
  38.   AddMessage(Format('    Found %d records in %0.3fs', [lst.Count, (Now - t)*86400]));
  39.   if saveRecords and (lst.Count <= maxRecordsToSave) then
  40.     SaveRecordNames(lst, Format('%s-%s-%s.txt', [GetFileName(f), gsig, sig]));
  41.   lst.Free;
  42.   AddMessage(' ');
  43. end;
  44.  
  45. function Initialize: integer;
  46. var
  47.   f: IInterface;
  48. begin
  49.   f := FileByIndex(0);
  50.   TestGetChildRecords(f, 'CELL', 'REFR');
  51.   TestGetChildRecords(f, 'CELL', 'ACHR');
  52.   TestGetChildRecords(f, 'CELL', 'NAVM');
  53.   TestGetChildRecords(f, 'WRLD', 'REFR');
  54.   TestGetChildRecords(f, 'WRLD', 'ACHR');
  55.   TestGetChildRecords(f, 'WRLD', 'NAVM');
  56.   TestGetChildRecords(f, 'DIAL', 'INFO');
  57. end;
  58.  
  59. end.
Advertisement
Add Comment
Please, Sign In to add comment