aboutsummaryrefslogtreecommitdiff
path: root/views/script/global_levelsapi.js
blob: ebd969d60cdeee410c241550b8979e781ce9621a (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
module.exports = class LevelsAPI {

    associates;

    constructor() {

        let assocs_raw;
        let assocs_lines;
        let assocs_base;
        let assocs;
        let score;
        let cline;
        let line;
        let clvl;

        assocs_raw = require('fs').readFileSync("./online/levels.txt");
        assocs_lines = assocs_raw.toString().split("\n");
        assocs_base = {};

        for (line of assocs_lines) {
            cline = line.split(":");
            assocs_base[cline[1].trim()] = cline[0].trim() - 1 + 1;
        }

        assocs = {};

        clvl = 0;
        for (let c = 0; c <= 5051; c++) {
            if (assocs_base[c.toString()] !== undefined) {
                clvl = assocs_base[c.toString()];
            }
            assocs[c.toString()] = clvl.toString()
        }

        this.associates = assocs;

    }

    correspond(score, god) {
        if (score <= 5051) {
            return this.associates[score].toString();
        } else {
            return god;
        }
    }

}