Skip to content

Commit

Permalink
Add dumps for object modifications
Browse files Browse the repository at this point in the history
Fixes #21.
  • Loading branch information
FWDekker committed Sep 28, 2020
1 parent c2c926d commit 7c6e9a7
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Edit scripts/ExportAll.pas
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ExportTabularLVLI,
ExportTabularMISC,
ExportTabularNPC_,
ExportTabularOMOD,
ExportTabularOTFT,
ExportTabularRACE,
ExportTabularWEAP,
Expand Down Expand Up @@ -57,6 +58,7 @@ function _selectDumps(): TStringList;
clb.items.add('LVLI.csv');
clb.items.add('MISC.csv');
clb.items.add('NPC_.csv');
clb.items.add('OMOD.csv');
clb.items.add('OTFT.csv');
clb.items.add('RACE.csv');
clb.items.add('WEAP.csv');
Expand Down Expand Up @@ -137,6 +139,9 @@ function initialize(): Integer;
if _hasSelectedDump('NPC_.csv') then begin
ExportTabularNPC_.initialize();
end;
if _hasSelectedDump('OMOD.csv') then begin
ExportTabularOMOD.initialize();
end;
if _hasSelectedDump('OTFT.csv') then begin
ExportTabularOTFT.initialize();
end;
Expand Down Expand Up @@ -198,6 +203,9 @@ function process(e: IInterface): Integer;
if _hasSelectedDump('NPC_.csv') and ExportTabularNPC_.canProcess(e) then begin
ExportTabularNPC_.process(e);
end;
if _hasSelectedDump('OMOD.csv') and ExportTabularOMOD.canProcess(e) then begin
ExportTabularOMOD.process(e);
end;
if _hasSelectedDump('OTFT.csv') and ExportTabularOTFT.canProcess(e) then begin
ExportTabularOTFT.process(e);
end;
Expand Down Expand Up @@ -260,6 +268,9 @@ function finalize(): Integer;
if _hasSelectedDump('NPC_.csv') then begin
ExportTabularNPC_.finalize();
end;
if _hasSelectedDump('OMOD.csv') then begin
ExportTabularOMOD.finalize();
end;
if _hasSelectedDump('OTFT.csv') then begin
ExportTabularOTFT.finalize();
end;
Expand Down
2 changes: 1 addition & 1 deletion Edit scripts/ExportJson.pas
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function getJsonKeywordArray(e: IInterface): String;

keywords := eBySign(eByPath(e, 'Keywords'), 'KWDA');
for i := 0 to eCount(keywords) - 1 do begin
resultList.add(evBySign(linkByIndex(keywords, i), 'EDID'));
resultList.add(evByIndex(keywords, i));
end;

resultList.sort();
Expand Down
170 changes: 170 additions & 0 deletions Edit scripts/ExportTabularOMOD.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
unit ExportTabularOMOD;

uses ExportCore,
ExportTabularCore,
ExportJson;


var ExportTabularOMOD_outputLines: TStringList;


function initialize(): Integer;
begin
ExportTabularOMOD_outputLines := TStringList.create();
ExportTabularOMOD_outputLines.add(
'"File"' // Name of the originating ESM
+ ', "Form ID"' // Form ID
+ ', "Editor ID"' // Editor ID
+ ', "Name"' // Full name
+ ', "Description"' // Description
+ ', "Form type"' // Type of mod (`Armor` or `Weapon`)
+ ', "Loose mod"' // Loose mod (MISC)
+ ', "Attach point"' // Attach point
+ ', "Attach parent slots"' // Sorted JSON array of attach parent slots
+ ', "Includes"' // Sorted JSON object of includes
+ ', "Properties"' // Sorted JSON object of properties
+ ', "Target keywords"' // Sorted JSON array of keywords. Each keyword is represented by its editor ID
);
end;

function canProcess(e: IInterface): Boolean;
begin
result := signature(e) = 'OMOD';
end;

function process(omod: IInterface): Integer;
var data: IInterface;
begin
if not canProcess(omod) then begin
addWarning(name(omod) + ' is not a OMOD. Entry was ignored.');
exit;
end;

data := eBySign(omod, 'DATA');

ExportTabularOMOD_outputLines.add(
escapeCsvString(getFileName(getFile(omod))) + ', '
+ escapeCsvString(stringFormID(omod)) + ', '
+ escapeCsvString(evBySign(omod, 'EDID')) + ', '
+ escapeCsvString(evBySign(omod, 'FULL')) + ', '
+ escapeCsvString(evBySign(omod, 'DESC')) + ', '
+ escapeCsvString(evByName(data, 'Form Type')) + ', '
+ escapeCsvString(evBySign(omod, 'LNAM')) + ', '
+ escapeCsvString(evByName(data, 'Attach Point')) + ', '
+ escapeCsvString(getJsonAttachParentSlotsArray(data)) + ', '
+ escapeCsvString(getJsonIncludesArray(data)) + ', '
+ escapeCsvString(getJsonOMODPropertyObject(data)) + ', '
+ escapeCsvString(getJsonTargetKeywordArray(omod))
);
end;

function finalize(): Integer;
begin
createDir('dumps/');
ExportTabularOMOD_outputLines.saveToFile('dumps/OMOD.csv');
ExportTabularOMOD_outputLines.free();
end;


function getJsonAttachParentSlotsArray(data: IInterface): String;
var i: Integer;
attachParentSlots: IInterface;
resultList: TStringList;
begin
resultList := TStringList.create();

attachParentSlots := eByName(data, 'Attach Parent Slots');
for i := 0 to eCount(attachParentSlots) - 1 do begin
resultList.add(evByIndex(attachParentSlots, i));
end;

resultList.sort();
result := stringListToJsonArray(resultList);
resultList.free();
end;

function getJsonTargetKeywordArray(omod: IInterface): String;
var i: Integer;
keywords: IInterface;
resultList: TStringList;
begin
resultList := TStringList.create();

keywords := eBySign(omod, 'MNAM');
for i := 0 to eCount(keywords) - 1 do begin
resultList.add(evByIndex(keywords, i));
end;

resultList.sort();
result := stringListToJsonArray(resultList);
resultList.free();
end;

(**
* Returns a JSON array of the mods that are included by the given mod.
*
* @param data the mod's data
* @return a JSON array of the mods that are included by the given mod
*)
function getJsonIncludesArray(data: IInterface): String;
var i: Integer;
includes: IInterface;
include: IInterface;
resultList: TStringList;
begin
resultList := TStringList.create();

includes := eByName(data, 'Includes');
for i := 0 to eCount(includes) - 1 do begin
include := eByIndex(includes, i);
resultList.add(
'{' +
'"Mod":"' + escapeJson(evByName(include, 'Mod')) + '"' +
',"Minimum Level":"' + escapeJson(evByName(include, 'MinimumLevel')) + '"' +
',"Optional":"' + escapeJson(evByName(include, 'Optional')) + '"' +
',"Don''t Use All":"' + escapeJson(evByName(include, 'Don''t Use All')) + '"' +
'}'
);
end;

resultList.sort();
result := listToJsonArray(resultList);
resultList.free();
end;

(**
* Returns a JSON array of the properties of the given mod.
*
* @param data the mod's data
* @return a JSON array of the properties of the given mod
*)
function getJsonOMODPropertyObject(data: IInterface): String;
var i: Integer;
props: IInterface;
prop: IInterface;
resultList: TStringList;
begin
resultList := TStringList.create();

props := eByName(data, 'Properties');
for i := 0 to eCount(props) - 1 do begin
prop := eByIndex(props, i);
resultList.add(
'{' +
'"Value Type":"' + escapeJson(evByName(prop, 'Value Type')) + '"' +
',"Function Type":"' + escapeJson(evByName(prop, 'Function Type')) + '"' +
',"Property":"' + escapeJson(evByName(prop, 'Property')) + '"' +
',"Value 1":"' + escapeJson(evByName(prop, 'Value 1')) + '"' +
',"Value 2":"' + escapeJson(evByName(prop, 'Value 2')) + '"' +
',"Curve Table":"' + escapeJson(evByName(prop, 'Curve Table')) + '"' +
'}'
);
end;

resultList.sort();
result := listToJsonArray(resultList);
resultList.free();
end;


end.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ To manually interpret location data, take a look at my [maps with grids](https:/
| [`ExportTabularLVLI.pas`](Edit%20scripts/ExportTabularLVLI.pas) | `LVLI.csv` | Leveled lists |
| [`ExportTabularMISC.pas`](Edit%20scripts/ExportTabularMISC.pas) | `MISC.csv` | Inventory item weights, values, and scrap yields |
| [`ExportTabularNPC_.pas`](Edit%20scripts/ExportTabularNPC_.pas) | `NPC_.csv` | NPC factions, keywords, stats, etc. |
| [`ExportTabularOMOD.pas`](Edit%20scripts/ExportTabularOMOD.pas) | `OMOD.csv` | Armor and weapon mods |
| [`ExportTabularOTFT.pas`](Edit%20scripts/ExportTabularOTFT.pas) | `OTFT.csv` | Outfits |
| [`ExportTabularRACE.pas`](Edit%20scripts/ExportTabularRACE.pas) | `RACE.csv` | Race keywords and properties |
| [`ExportTabularWEAP.pas`](Edit%20scripts/ExportTabularWEAP.pas) | `WEAP.csv` | Weapons |
Expand Down

0 comments on commit 7c6e9a7

Please sign in to comment.