summaryrefslogtreecommitdiff
path: root/2026/games/cammymoop/js/hints.js
blob: 250c080229f4e8a433b0229e7025e1bf7c62d56d (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

const nums = ['1', '2', '3', '4', '5', '6']; 
const shortNames = [];

M.Hint = class extends Phaser.GameObjects.Container
{
    constructor(scene) {
        super(scene);
        this.rows = [];
        this.allImgs = [];
        this.maxWidth = 0;
    }

    setupExample() {
        this.addToDisplayList();
        this.addRow(["equal", "5", "", "arrow", "", "skull", "dice"]);
        this.addRow(["greater", "2", "", "arrow", "", "skull"]);
        this.build();
    }

    setup(hintData) {
        this.addToDisplayList();
        this.rows = [];
        for (let row of hintData) {
            this.addRow(row);
        }
        this.build();
    }

    addRow(contents) {
        this.rows.push(contents);
    }

    clearRows() {
        this.rows = [];
    }

    clearImgs() {
        for (let img of this.allImgs) {
            img.destroy();
        }
        this.allImgs = [];
    }

    build() {
        this.clearImgs();
        
        for (let i = 0; i < this.rows.length; i++) {
            // Place rows in reverse order from bottom to top, moving coords upward so the end result is in order
            const row = this.rows[this.rows.length - 1 - i];
            if (row.length < 1) {
                continue;
            }
            const row_width = row.length * 8;
            for (let j = 0; j < row.length; j++) {
                if (row[j] === '') {
                    continue;
                }
                const charImg = this.getImageForKey(row[j]);
                this.allImgs.push(charImg);
                this.add(charImg);
                charImg.x = (8 * j) - (row_width/2);
                charImg.y = -i * 10;
            }
        }
    }

    getImageForKey(charKey) {
        if (nums.includes(charKey)) {
            return this.newImage("number_icons", parseInt(charKey) - 1);
        } else {
            return this.newImage(charKey + "_icon");
        }
    }

    newImage(texKey, frame = '') {
        if (frame !== '') {
            return new Phaser.GameObjects.Image(this.scene, 0, 0, texKey, frame);
        } else {
            return new Phaser.GameObjects.Image(this.scene, 0, 0, texKey);
        }
    }
};