-
Notifications
You must be signed in to change notification settings - Fork 21
/
gameDbLoader.js
53 lines (46 loc) · 1.83 KB
/
gameDbLoader.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
let xml = require("xml2js");
module.exports = function (code) {
let callback = this.async();
xml.parseString(code, (err, res) => {
if (err) {
return callback(err);
}
let out = {};
res.games.game.forEach((game) => {
if (game.title[0].search(/^[-a-z0-9 &!\.',+$]+$/i) === -1) {
this.emitWarning(game.title[0] + " contains non-allowed characters");
}
let name = game.title[0];
// These are case sensitive
if (name.search(/, The(?: |$)/) !== -1) {
name = "The " + name.replace(", The", "");
}
if (name.search(/, Die(?: |$)/) !== -1) {
name = "Die " + name.replace(", Die", "");
}
if (name.search(/, Les(?: |$)/) !== -1) {
name = "Les " + name.replace(", Les", "");
}
if (name.search(/, La(?: |$)/) !== -1) {
name = "La " + name.replace(", La", "");
}
if (name === "Fantastici 4, I") {
name = "I Fantastici 4";
}
let options = game.cartridge[0] || {};
for (let prop in options) {
if (options.hasOwnProperty(prop)) {
if (Array.isArray(options[prop]) && options[prop].length === 1 && options[prop][0] === "") {
options[prop] = true;
} else if (options[prop].length === 1 && options[prop][0].$) {
options[prop] = options[prop][0].$;
} else {
this.emitWarning("unexpected structure on " + name);
}
}
}
out[game.$.code] = [name, options];
});
callback(null, "module.exports = " + JSON.stringify(out));
});
};