about summary refs log tree commit diff stats
path: root/html/rogue/js/utils.js
blob: bd329fba4dbf05063cf893abfb8534c76769b1d6 (plain) (blame)
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
const Utils = {
    hexToKey(hex) {
        return `${hex.q},${hex.r}`;
    },
    
    keyToHex(key) {
        const [q, r] = key.split(',').map(Number);
        return { q, r };
    },
    
    // Screen/canvas coordinate utilities
    screenToCanvas(x, y, camera) {
        return {
            x: x + camera.x,
            y: y + camera.y
        };
    },
    
    canvasToScreen(x, y, camera) {
        return {
            x: x - camera.x,
            y: y - camera.y
        };
    }
};