fix: update player module version and enhance teleportation cooldown to prevent rapid back-and-forth movement

This commit is contained in:
Z. Cliffe Schreuders
2026-02-21 00:20:59 +00:00
parent d4ea4ccb66
commit e9633766c9
3 changed files with 20 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
import { initializeRooms, calculateWorldBounds, calculateRoomPositions, createRoom, revealRoom, updatePlayerRoom, rooms } from './rooms.js?v=17';
import { createPlayer, updatePlayerMovement, movePlayerToPoint, facePlayerToward, player } from './player.js?v=17';
import { createPlayer, updatePlayerMovement, movePlayerToPoint, facePlayerToward, player } from './player.js?v=18';
import { initializePathfinder } from './pathfinding.js?v=7';
import { initializeInventory, processInitialInventoryItems } from '../systems/inventory.js?v=9';
import { checkObjectInteractions, setGameInstance, isObjectInInteractionRange } from '../systems/interactions.js?v=31';

View File

@@ -915,6 +915,18 @@ export function movePlayerToPoint(x, y) {
}
}
// Exposed globally so teleport handlers (collision.js) can cancel in-flight paths
// without creating a circular import.
window.cancelClickToMove = () => {
playerPath = [];
playerPathIndex = 0;
playerFollowingPath = false;
playerFinalGoal = null;
++playerPathRequestId; // invalidate any pending EasyStar callbacks
isMoving = false;
targetPoint = null;
};
/**
* Turn the player to face a world position, updating direction and idle animation.
* Call this before triggering a click-based interaction so the player visually

View File

@@ -14,7 +14,7 @@ let rooms = null;
// Teleportation cooldown system to prevent rapid back-and-forth
let lastTeleportTime = 0;
const TELEPORT_COOLDOWN = 500; // 500ms cooldown between teleports
const TELEPORT_COOLDOWN = 1500; // 1.5s — long enough that a path cannot loop back
// Initialize collision system
export function initializeCollision(gameInstance, roomsRef) {
@@ -361,6 +361,9 @@ export function removeTilesUnderDoor(wallLayer, roomId, position) {
player.x = doorX - offset;
}
lastTeleportTime = currentTime;
// Cancel any active click-to-move path — prevents it
// from immediately re-crossing the door on the way back.
window.cancelClickToMove?.();
console.log(`Teleported player through door void (from ${roomId}) to x=${player.x}`);
}
}
@@ -666,6 +669,9 @@ export function removeWallTilesForDoorInRoom(roomId, fromRoomId, direction, door
player.x = doorX + offset;
}
lastTeleportTime = currentTime;
// Cancel any active click-to-move path — prevents it
// from immediately re-crossing the door on the way back.
window.cancelClickToMove?.();
console.log(`Teleported player through door void to x=${player.x}`);
}
}