Update server/static/map.js

This commit is contained in:
2025-11-13 17:59:13 +00:00
parent 03a6787992
commit a8747275af

View File

@@ -167,11 +167,14 @@ export class MapView {
const seen = new Set(); const seen = new Set();
for (const p of players) { for (const p of players) {
seen.add(p.id); seen.add(p.id);
const snapped = this.snapToTile(p.x, p.y);
// If you're using tiles:
const pos = this.snapToTile ? this.snapToTile(p.x, p.y) : { x: p.x, y: p.y };
if (!this.otherSprites.has(p.id)) { if (!this.otherSprites.has(p.id)) {
const img = this.scene.add.image(snapped.x, snapped.y, 'other').setDepth(5); const img = this.scene.add.image(pos.x, pos.y, 'other').setDepth(5);
const label = this.scene const label = this.scene
.add.text(snapped.x, snapped.y - 22, p.name || 'Player', { .add.text(pos.x, pos.y - 22, p.name || 'Player', {
fontSize: '12px', fontSize: '12px',
color: '#9ca3af' color: '#9ca3af'
}) })
@@ -179,11 +182,12 @@ export class MapView {
this.otherSprites.set(p.id, { img, label }); this.otherSprites.set(p.id, { img, label });
} else { } else {
const rec = this.otherSprites.get(p.id); const rec = this.otherSprites.get(p.id);
rec.img.setPosition(snapped.x, snapped.y); rec.img.setPosition(pos.x, pos.y);
rec.label.setPosition(snapped.x, snapped.y - 22); rec.label.setPosition(pos.x, pos.y - 22);
} }
} }
// Remove any that disappeared
// Clean up players that disconnected
for (const [id, rec] of this.otherSprites) { for (const [id, rec] of this.otherSprites) {
if (!seen.has(id)) { if (!seen.has(id)) {
rec.img.destroy(); rec.img.destroy();