in-c4/static/shared.js

34 lines
1,019 B
JavaScript
Raw Permalink Normal View History

2022-08-05 21:58:53 +02:00
function renderMap(xx, yy) {
2024-04-30 16:27:00 +02:00
if (xx[0] > 0 && xx[0] < 36 && yy[0] > 0 && yy[0] < 18 &&
xx[1] > 0 && xx[1] < 36 && yy[1] > 0 && yy[1] < 18 &&
2022-08-05 21:58:53 +02:00
xx[1] >= xx[0] && yy[1] >= yy[0]) {
let grid = document.getElementById('mapgrid');
grid.style.top = `${yy[0]*100/18}%`;
2024-04-30 16:27:00 +02:00
grid.style.left = `${100/36*xx[0]}%`;
grid.style.height = `${(yy[1] - yy[0] + 1) * 100/18}%`;
2024-04-30 16:27:00 +02:00
grid.style.width = `${100/36*(xx[1] - xx[0] + 1)}%`;
2022-08-05 21:58:53 +02:00
} else {
alert(`invalid coordinates x=${xx} y=${yy}`);
}
}
function clearMap() {
const mapnote = document.getElementById('mapnote');
if (mapnote) {
mapnote.textContent = '';
}
document.getElementById('mapgrid').removeAttribute('style');
}
2022-08-05 21:58:53 +02:00
function coordsToMap(coords_bl, coords_tr) {
let bl_y = coords_bl[0];
let tr_y = coords_tr[0];
let bl_x = parseInt(coords_bl.slice(1));
let tr_x = parseInt(coords_tr.slice(1));
bl_y = 16 - (bl_y.charCodeAt(0) - 65);
tr_y = 16 - (tr_y.charCodeAt(0) - 65);
2022-08-05 21:58:53 +02:00
renderMap([bl_x, tr_x], [tr_y, bl_y]);
}