-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodegen-metagame.js
58 lines (51 loc) · 1.45 KB
/
codegen-metagame.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
import fs from "fs";
import fetch from "node-fetch";
const template = (
data
) => `// This file is generated. Run \`yarn codegen\` to regenerate.
import { AlertType } from "./types";
export const metagameIDs = {
${Object.entries(data)
.map(([id, type]) => `${JSON.stringify(id)}: ${type}`)
.join(",\n")}
};
`;
const run = async () => {
// Get the data from the api
const response = await fetch(
"https://census.daybreakgames.com/s:medkit2/get/ps2:v2/metagame_event/?c:limit=1000"
);
const json = await response.json();
const data = {
// Oshur pre-fill
222: "AlertType.Conquest",
223: "AlertType.Conquest",
224: "AlertType.Conquest",
226: "AlertType.Conquest",
232: "AlertType.Air",
233: "AlertType.Max",
236: "AlertType.SuddenDeath",
237: "AlertType.SuddenDeath",
238: "AlertType.SuddenDeath",
239: "AlertType.SuddenDeath",
240: "AlertType.SuddenDeath",
};
// Parse the data
for (const event of json.metagame_event_list) {
switch (event.type) {
case "9": // Conquest
data[event.metagame_event_id] = "AlertType.Conquest";
break;
case "10": // Air
data[event.metagame_event_id] = "AlertType.Air";
break;
case "6": // Max
data[event.metagame_event_id] = "AlertType.Max";
break;
}
}
// Write the file
const output = template(data);
fs.writeFileSync("./src/metagame.gen.ts", output);
};
run().then().catch(console.error);