import { PIVOT_FROM_BOTTOM_PX } from "../protocol/constants.js"; export function tilePivot (tileX, tileY, tileSize) { return { x: tileX * tileSize + tileSize / 2, y: tileY * tileSize + tileSize / 2 }; } export function spriteCenterFromPivot (pivotX, pivotY, spriteHeight, zoom) { const height = spriteHeight * zoom; return { x: pivotX, y: pivotY - (height / 2 - PIVOT_FROM_BOTTOM_PX * zoom) }; } export function spriteDrawSize (spriteWidth, spriteHeight, zoom) { return { w: spriteWidth * zoom, h: spriteHeight * zoom }; } /** * Within one rounded sortY, layers occupy [0, Y_SORT_SUBORDER_STRIDE). * Keep door front / HP bar above entity body + equipment overlays. */ export const Y_SORT_SUBORDER_STRIDE = 16; export function ySortLayer (sortY, subOrder) { const slot = Math.max(0, Math.min(Y_SORT_SUBORDER_STRIDE - 1, subOrder | 0)); return 10000 + Math.round(sortY) * Y_SORT_SUBORDER_STRIDE + slot; } /** * Free-flight sprites (e.g. pigeons) must draw above all ground y-sorted * blocks/entities. Bias sits well above {@link ySortLayer} for any in-view tile. */ export const FLIGHT_SORT_BIAS = 2_000_000; export function flightSortLayer (sortY, subOrder = 0) { const slot = Math.max(0, Math.min(Y_SORT_SUBORDER_STRIDE - 1, subOrder | 0)); return FLIGHT_SORT_BIAS + Math.round(sortY) * Y_SORT_SUBORDER_STRIDE + slot; }