Split client code from server

This commit is contained in:
2026-03-20 23:13:27 +01:00
parent eb3910d7ea
commit 1fc21d700e
117 changed files with 850 additions and 762 deletions
+35 -1
View File
@@ -1,7 +1,6 @@
import { TileType, Region, IMap } from './interfaces';
import { clamp } from './utils';
import { tileWidth, tileHeight, REGION_SIZE, REGION_WIDTH, REGION_HEIGHT } from './constants';
import { getRegion } from './worldMap';
import { toScreenX, toScreenY } from './positionUtils';
import { ponyColliders, ponyCollidersBounds } from './mixins';
import { decompressTiles } from './compress';
@@ -200,3 +199,38 @@ export function generateRegionCollider<T extends Region | undefined>(region: Reg
}
}
}
export function getRegionGlobal<T>(map: IMap<T>, x: number, y: number): T {
const rx = worldToRegionX(x, map);
const ry = worldToRegionY(y, map);
return getRegion(map, rx, ry);
}
export function getRegion<T>(map: IMap<T>, x: number, y: number): T {
if (x < 0 || y < 0 || x >= map.regionsX || y >= map.regionsY) {
throw new Error(`Invalid region coords (${x}, ${y})`);
} else {
return map.regions[((x | 0) + (y | 0) * map.regionsX) | 0];
}
}
export function getRegionUnsafe<T>(map: IMap<T>, x: number, y: number): T | undefined {
if (x < 0 || y < 0 || x >= map.regionsX || y >= map.regionsY) {
return undefined;
} else {
return map.regions[((x | 0) + (y | 0) * map.regionsX) | 0];
}
}
export function doRelativeToRegion(
map: IMap<Region | undefined>, x: number, y: number, action: (region: Region, x: number, y: number) => void
) {
const region = getRegionGlobal(map, x, y);
if (region) {
const regionX = Math.floor(x - region.x * REGION_SIZE);
const regionY = Math.floor(y - region.y * REGION_SIZE);
action(region, regionX, regionY);
}
}