summaryrefslogtreecommitdiff
path: root/includes/data.backup2/migrate.js
blob: 716096fe6ed080b1e3ee9e14188bd91fb383215c (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const fs = require('fs');

for (let file of fs.readdirSync(".").filter(i => i.endsWith("-metadata.json"))) {
    let size = fs.readFileSync(file).toString().length;
    let json = JSON.parse(fs.readFileSync(file).toString());
    console.log("-- " + file + " --");

    if (!json['bitset']) {
        console.log("Migrating file...");
        let p1r = "0".repeat(2 - json['shared_memory'].toString(2).length) + json['shared_memory'].toString(2);
        let p2r = json['median'] ? "1" : "0";
        let p3r = "0".repeat(2 - json['little'].toString(2).length) + json['little'].toString(2);
        let p4r = json['protector'] ? "1" : "0";
        let p5r = json['fictive'] ? "1" : "0";
        let p6r = json['not_talking'] ? "1" : "0";
        let p7r = json['host'] ? "1" : "0";
        let p8a = json['species'][0];
        let p9a = json['species'][1];

        let p8r = "0000";
        switch (p8a) {
            case "earth":
                p8r = "0001";
                break;

            case "unicorn":
                p8r = "0010";
                break;

            case "pegasus":
                p8r = "0011";
                break;

            case "alicorn":
                p8r = "0100";
                break;

            case "batpony":
                p8r = "0101";
                break;

            case "crystal":
                p8r = "0110";
                break;
        }

        let p9r = "0000";
        switch (p9a) {
            case "earth":
                p9r = "0001";
                break;

            case "unicorn":
                p9r = "0010";
                break;

            case "pegasus":
                p9r = "0011";
                break;

            case "alicorn":
                p9r = "0100";
                break;

            case "batpony":
                p9r = "0101";
                break;

            case "crystal":
                p9r = "0110";
                break;
        }

        console.log("Generated bitset: " + p1r + p2r + p3r + p4r + p5r + p6r + p7r + p8r + p9r + "0000000");

        let ret = {
            bitset: parseInt(p1r + p2r + p3r + p4r + p5r + p6r + p7r + p8r + p9r + "0000000", 2),
            regression: json['regression'] ?? null,
            marefriends: json['marefriends'] ?? [],
            sisters: json['sisters'] ?? [],
            caretakers: json['caretakers'] ?? []
        }

        console.log("Saving...");
        fs.writeFileSync(file, JSON.stringify(ret, null, 2));
        let now = JSON.stringify(ret, null, 2).length;

        console.log("Saved space: " + (size - now) + " bytes, " + (((size - now) / size) * 100).toFixed(2) + "%");
    } else {
        console.log("File has already been migrated, ignoring.");
    }

    console.log("");
}