This repository has been archived by the owner on Feb 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
63 lines (54 loc) · 2.38 KB
/
main.js
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
var sea = require("node:sea");
if (sea.isSea()) {
const { createRequire } = require("node:module");
require = createRequire(__filename);
}
const fs = require("fs")
const xml2js = require("xml2js");
var parser = new xml2js.Parser();
var storage = new Map();
var output = new Map();
fs.readFile(__dirname + 'data.xml', "utf-8", function(err, data) {
if (err) { console.warn("[prop-xml-extractor] Error: data.xml do not exist."); return }
parser.parseString(data, function (err, result) {
if (result == undefined) { console.warn("[prop-xml-extractor] Error: data.xml might be empty."); return }
const Items = result.CMapTypes.archetypes[0].Item;
var index = 0;
Items.forEach((Item) => {
// Props
if(Item.name[0] != undefined) storage.set((index += 1), Item.name[0]);
// Extensions Props
const Props = Item.extensions[0].Item;
if(Props != undefined) {
Props.forEach((prop) => {
if(prop.spawnType != undefined) storage.set((index += 1), prop.spawnType[0]);
});
};
// Entities Props
if(Item.entities != undefined) {
const Entities = Item.entities[0].Item;
Entities.forEach((entity) => {
if(entity.archetypeName != undefined) storage.set((index += 1), entity.archetypeName[0]);
})
};
// Entities Sets Props
if (Item.entitySets != undefined) {
const EntitySetsItems = Item.entitySets[0].Item;
EntitySetsItems.forEach((item) => {
const Entities = item.entities[0].Item;
Entities.forEach((object) => {
if(object.archetypeName != undefined) storage.set((index += 1), object.archetypeName[0]);
});
});
};
});
storage.forEach((item) => {
if (!output.has(item)) {
output.set(item, undefined);
};
});
var json = JSON.stringify([...output.keys()], null, 1).replaceAll('[', '').replaceAll('"', '').replaceAll(',', '').replaceAll(']', '').replaceAll(' ', ''); // How regex works???
fs.writeFile('result.txt', json, err => {});
console.log(`[prop-xml-extractor] Result: Done, got ${output.size} props !`);
});
});