Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Flora, Leveled Items, Weapons, Item locations #20

Merged
merged 6 commits into from
Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions Edit scripts/ExportAll.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
ExportTabularCOBJ,
ExportTabularENTM,
ExportTabularFACT,
ExportTabularFLOR,
ExportTabularGLOB,
ExportTabularGMST,
ExportTabularIDs,
ExportTabularLVLI,
ExportTabularMISC,
ExportTabularNPC_,
ExportTabularOTFT,
ExportTabularRACE,
ExportTabularWEAP,
ExportWikiBOOK,
ExportWikiDIAL,
ExportWikiNOTE,
Expand Down Expand Up @@ -42,30 +45,32 @@ function _selectDumps(): TStringList;
form.caption := 'Select dump scripts';

clb := TCheckListBox(form.findComponent('CheckListBox1'));
clb.items.add('IDs.csv');
clb.items.add('ARMO.csv');
clb.items.add('CLAS.csv');
clb.items.add('COBJ.csv');
clb.items.add('ENTM.csv');
clb.items.add('FACT.csv');
clb.items.add('FLOR.csv');
clb.items.add('GLOB.csv');
clb.items.add('GMST.csv');
clb.items.add('IDs.csv');
clb.items.add('LVLI.csv');
clb.items.add('MISC.csv');
clb.items.add('NPC_.csv');
clb.items.add('OTFT.csv');
clb.items.add('RACE.csv');
clb.items.add('WEAP.csv');
clb.items.add('BOOK.wiki');
clb.items.add('DIAL.wiki');
clb.items.add('NOTE.wiki');
clb.items.add('TERM.wiki');

for i := 0 to pred(clb.items.count) do begin
clb.checked[i] := true;
end;
// Show form
if form.showModal() <> mrOk then begin
exit;
end;

// Process input
for i := 0 to pred(clb.items.count) do begin
if clb.checked[i] then begin
result.add(clb.items[i]);
Expand Down Expand Up @@ -111,6 +116,9 @@ function initialize(): Integer;
if _hasSelectedDump('FACT.csv') then begin
ExportTabularFACT.initialize();
end;
if _hasSelectedDump('FLOR.csv') then begin
ExportTabularFLOR.initialize();
end;
if _hasSelectedDump('GLOB.csv') then begin
ExportTabularGLOB.initialize();
end;
Expand All @@ -120,6 +128,9 @@ function initialize(): Integer;
if _hasSelectedDump('IDs.csv') then begin
ExportTabularIDs.initialize();
end;
if _hasSelectedDump('LVLI.csv') then begin
ExportTabularLVLI.initialize();
end;
if _hasSelectedDump('MISC.csv') then begin
ExportTabularMISC.initialize();
end;
Expand All @@ -132,6 +143,9 @@ function initialize(): Integer;
if _hasSelectedDump('RACE.csv') then begin
ExportTabularRACE.initialize();
end;
if _hasSelectedDump('WEAP.csv') then begin
ExportTabularWEAP.initialize();
end;
if _hasSelectedDump('BOOK.wiki') then begin
ExportWikiBOOK.initialize();
end;
Expand Down Expand Up @@ -163,6 +177,9 @@ function process(e: IInterface): Integer;
if _hasSelectedDump('FACT.csv') and ExportTabularFACT.canProcess(e) then begin
ExportTabularFACT.process(e);
end;
if _hasSelectedDump('FLOR.csv') and ExportTabularFLOR.canProcess(e) then begin
ExportTabularFLOR.process(e);
end;
if _hasSelectedDump('GLOB.csv') and ExportTabularGLOB.canProcess(e) then begin
ExportTabularGLOB.process(e);
end;
Expand All @@ -172,6 +189,9 @@ function process(e: IInterface): Integer;
if _hasSelectedDump('IDs.csv') and ExportTabularIDs.canProcess(e) then begin
ExportTabularIDs.process(e);
end;
if _hasSelectedDump('LVLI.csv') and ExportTabularLVLI.canProcess(e) then begin
ExportTabularLVLI.process(e);
end;
if _hasSelectedDump('MISC.csv') and ExportTabularMISC.canProcess(e) then begin
ExportTabularMISC.process(e);
end;
Expand All @@ -184,6 +204,9 @@ function process(e: IInterface): Integer;
if _hasSelectedDump('RACE.csv') and ExportTabularRACE.canProcess(e) then begin
ExportTabularRACE.process(e);
end;
if _hasSelectedDump('WEAP.csv') and ExportTabularWEAP.canProcess(e) then begin
ExportTabularWEAP.process(e);
end;
if _hasSelectedDump('BOOK.wiki') and ExportWikiBOOK.canProcess(e) then begin
ExportWikiBOOK.process(e);
end;
Expand Down Expand Up @@ -216,6 +239,9 @@ function finalize(): Integer;
if _hasSelectedDump('FACT.csv') then begin
ExportTabularFACT.finalize();
end;
if _hasSelectedDump('FLOR.csv') then begin
ExportTabularFLOR.finalize();
end;
if _hasSelectedDump('GLOB.csv') then begin
ExportTabularGLOB.finalize();
end;
Expand All @@ -225,6 +251,9 @@ function finalize(): Integer;
if _hasSelectedDump('IDs.csv') then begin
ExportTabularIDs.finalize();
end;
if _hasSelectedDump('LVLI.csv') then begin
ExportTabularLVLI.finalize();
end;
if _hasSelectedDump('MISC.csv') then begin
ExportTabularMISC.finalize();
end;
Expand All @@ -237,6 +266,9 @@ function finalize(): Integer;
if _hasSelectedDump('RACE.csv') then begin
ExportTabularRACE.finalize();
end;
if _hasSelectedDump('WEAP.csv') then begin
ExportTabularWEAP.finalize();
end;
if _hasSelectedDump('BOOK.wiki') then begin
ExportWikiBOOK.finalize();
end;
Expand Down
11 changes: 6 additions & 5 deletions Edit scripts/ExportCore.pas
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* Shorthands for commonly used functions.
*
***)
**)

(**
* Shorthand for [getEditValue].
Expand Down Expand Up @@ -141,7 +141,7 @@ function stringFormID(e: IInterface): String;
*
* xEdit utility functions
*
***)
**)

(**
* Returns `true` iff [e] is referenced by a record with signature [sig].
Expand All @@ -166,12 +166,13 @@ function isReferencedBy(e: IInterface; sig: String): Boolean;


(***
*
* Error and warning management.
*)
*
**)
var ExportCore_warnings: TStringList;
var ExportCore_errors: TStringList;


(**
* Initializes error and warning management if this has not happened yet.
*)
Expand Down Expand Up @@ -244,7 +245,7 @@ function errorStats(full: Boolean): String;
*
* Generic utility functions.
*
***)
**)

(**
* Repeats [text] [amount] times.
Expand Down
114 changes: 102 additions & 12 deletions Edit scripts/ExportJson.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,28 @@
unit ExportJson;


(***
*
* Core functions for JSON serialization.
*
**)

(**
* Escapes all double quotes in [text] by putting a backslash in front of them.
*
* @param text the text to escape
* @return a quote-escaped version of [text]
*)
function escapeQuotes(text: String): String;
begin
result := stringReplace(text, '"', '\"', [rfReplaceAll]);
end;

(**
* Serializes the list of values into a JSON array.
*
* Each list entry is interpreted as a raw value and is not surrounded with quotes.
*
* @param list the list of values to convert to a serialized JSON array
* @return a serialized JSON array version of [list]
*)
Expand All @@ -18,14 +37,31 @@ function listToJsonArray(list: TStringList): String;
exit;
end;

result := '"' + list[0] + '"';
result := list[0];
for i := 1 to list.count - 1 do begin
result := result + ',"' + list[i] + '"';
result := result + ',' + list[i];
end;

result := '[' + result + ']';
end;

(**
* Serializes the list of strings into a JSON array.
*
* Each list entry is interpreted as a string and is therefore surrounded with double quotes as part of serialization.
*
* @param list the list of strings to convert to a serialized JSON array
* @return a serialized JSON array version of [list]
*)
function stringListToJsonArray(list: TStringList): String;
var i: Integer;
begin
for i := 0 to list.count - 1 do begin
list[i] := '"' + escapeQuotes(list[i]) + '"';
end;
result := listToJsonArray(list);
end;

(**
* Serializes the lists of keys and values into a JSON object.
*
Expand All @@ -49,7 +85,7 @@ function listsToJsonObject(keys: TStringList; values: TStringList; sorted: Boole

entries := TStringList.create();
for i := 0 to keys.count - 1 do begin
entries.add('"' + keys[i] + '": "' + values[i] + '"');
entries.add('"' + escapeQuotes(keys[i]) + '": "' + escapeQuotes(values[i]) + '"');
end;

if sorted then begin
Expand All @@ -65,6 +101,13 @@ function listsToJsonObject(keys: TStringList; values: TStringList; sorted: Boole
end;



(***
*
* Domain-specific serialization functions.
*
**)

(**
* Returns the keywords of [e] as a serialized JSON array of editor IDs.
*
Expand All @@ -84,7 +127,7 @@ function getJsonKeywordArray(e: IInterface): String;
end;

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

Expand All @@ -109,7 +152,7 @@ function getJsonFactionArray(e: IInterface): String;
end;

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

Expand Down Expand Up @@ -137,7 +180,7 @@ function getJsonComponentArray(e: IInterface): String;
end;

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

Expand All @@ -162,7 +205,7 @@ function getJsonPerkArray(e: IInterface): String;
end;

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

Expand Down Expand Up @@ -226,11 +269,11 @@ function getJsonChildArray(list: IInterface): String;
resultList := TStringList.create();

for i := 0 to eCount(list) - 1 do begin
resultList.add(escapeQuotes(evByIndex(list, i)));
resultList.add(evByIndex(list, i));
end;

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

Expand All @@ -249,10 +292,10 @@ function getJsonUnsortedChildArray(list: IInterface): String;
resultList := TStringList.create();

for i := 0 to eCount(list) - 1 do begin
resultList.add(escapeQuotes(evByIndex(list, i)));
resultList.add(evByIndex(list, i));
end;

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

Expand All @@ -271,11 +314,58 @@ function getJsonChildNameArray(list: IInterface): String;
resultList := TStringList.create();

for i := 0 to eCount(list) - 1 do begin
resultList.add(escapeQuotes(name(eByIndex(list, i))));
resultList.add(name(eByIndex(list, i)));
end;

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

(**
* Returns the leveled list entries of [e] as a serialized JSON array.
*
* Each leveled list entry is expressed using a colon-separated triple of the referenced item, the level, and the count.
*
* @param e the element to return the leveled list entries of
* @return the entries of [e] as a serialized JSON array
*)
function getJsonLeveledListArray(e: IInterface): String;
var i: Integer;
entries: IInterface;
entry: IInterface;
entryKeys: TStringList;
entryValues: TStringList;
reference: String;
level: String;
quantity: String;
resultList: TStringList;
begin
resultList := TStringList.create();
entryKeys := TStringList.create();
entryValues := TStringList.create();

entryKeys.add('Reference');
entryKeys.add('Level');
entryKeys.add('Count');

entries := eByName(e, 'Leveled List Entries');
for i := 0 to eCount(entries) - 1 do begin
entry := eByName(eBySign(eByIndex(entries, i), 'LVLO'), 'Base Data');

entryValues.clear();
entryValues.add(evByName(entry, 'Reference'));
entryValues.add(evByName(entry, 'Level'));
entryValues.add(evByName(entry, 'Count'));

resultList.add(listsToJsonObject(entryKeys, entryValues, false));
end;

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

entryValues.free();
entryKeys.free();
resultList.free();
end;

Expand Down
Loading