mirror of
https://gitlab.aachen.ccc.de/inventory/in.git
synced 2025-06-09 05:25:09 +02:00
set item coords via map, closes #3
This commit is contained in:
parent
4bf4f754c9
commit
5aa8b8a37f
5 changed files with 2341 additions and 6 deletions
25
static/shared.js
Normal file
25
static/shared.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
function renderMap(xx, yy) {
|
||||
if (xx[0] > 0 && xx[0] < 31 && yy[0] > 0 && yy[0] < 9 &&
|
||||
xx[1] > 0 && xx[1] < 31 && yy[1] > 0 && yy[1] < 9 &&
|
||||
xx[1] >= xx[0] && yy[1] >= yy[0]) {
|
||||
let grid = document.getElementById('grid');
|
||||
grid.style.top = `${yy[0]*10}%`;
|
||||
grid.style.left = `${100/31*xx[0]}%`;
|
||||
grid.style.height = `${(yy[1] - yy[0] + 1) * 10}%`;
|
||||
grid.style.width = `${100/31*(xx[1] - xx[0] + 1)}%`;
|
||||
} else {
|
||||
alert(`invalid coordinates x=${xx} y=${yy}`);
|
||||
}
|
||||
}
|
||||
|
||||
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 = 8 - (bl_y.charCodeAt(0) - 65);
|
||||
tr_y = 8 - (tr_y.charCodeAt(0) - 65);
|
||||
|
||||
renderMap([bl_x, tr_x], [tr_y, bl_y]);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue