2023-01-01 00:06:45 +08:00
|
|
|
import { has } from '../utils';
|
|
|
|
|
2022-12-31 21:44:33 +08:00
|
|
|
export default function init() {
|
|
|
|
return { splitArea };
|
|
|
|
}
|
|
|
|
|
2023-01-01 00:06:45 +08:00
|
|
|
type BFSFromString = `${FloorIds},${number},${number},${Dir}`;
|
|
|
|
type BFSToString = `${FloorIds},${number},${number}`;
|
|
|
|
|
2022-12-31 22:45:32 +08:00
|
|
|
interface MapBFSResult {
|
|
|
|
maps: FloorIds[];
|
2023-01-01 00:06:45 +08:00
|
|
|
link: Record<BFSFromString, BFSToString>;
|
2022-12-31 22:45:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const bfsCache: Partial<Record<FloorIds, MapBFSResult>> = {};
|
|
|
|
|
2023-01-01 00:06:45 +08:00
|
|
|
const arrow: Partial<Record<AllIds, Dir>> = {
|
|
|
|
leftPortal: 'left',
|
|
|
|
rightPortal: 'right',
|
|
|
|
upPortal: 'up',
|
|
|
|
downPortal: 'down'
|
|
|
|
};
|
|
|
|
|
2022-12-31 22:45:32 +08:00
|
|
|
export function splitArea() {}
|
|
|
|
|
|
|
|
export function getMapData(floorId: FloorIds) {}
|
2022-12-31 21:44:33 +08:00
|
|
|
|
2022-12-31 22:45:32 +08:00
|
|
|
export function getMapDrawData(floorId: FloorIds) {}
|
2022-12-31 21:44:33 +08:00
|
|
|
|
2022-12-31 22:45:32 +08:00
|
|
|
/**
|
|
|
|
* 广度优先搜索地图信息
|
|
|
|
* @param floorId 中心楼层id
|
|
|
|
* @param noCache 是否不使用缓存
|
|
|
|
*/
|
2023-01-01 00:06:45 +08:00
|
|
|
function bfs(floorId: FloorIds, noCache: boolean = false): MapBFSResult {
|
|
|
|
if (has(bfsCache[floorId]) && !noCache) return bfsCache[floorId]!;
|
2022-12-31 22:45:32 +08:00
|
|
|
|
|
|
|
const queue = [floorId];
|
2023-01-01 00:06:45 +08:00
|
|
|
const used: Partial<Record<FloorIds, boolean>> = {
|
|
|
|
[floorId]: true
|
|
|
|
};
|
|
|
|
const floors = [floorId];
|
|
|
|
const link: Record<BFSFromString, BFSToString> = {};
|
2022-12-31 22:45:32 +08:00
|
|
|
|
|
|
|
while (queue.length > 0) {
|
|
|
|
const now = queue.shift()!;
|
2023-01-01 00:06:45 +08:00
|
|
|
const change = core.floors[now].changeFloor;
|
|
|
|
const blocks = core.getMapBlocksObj(now);
|
|
|
|
for (const [loc, ev] of Object.entries(change)) {
|
|
|
|
const target = ev.floorId as FloorIds;
|
|
|
|
if (target.startsWith(':')) continue;
|
|
|
|
const block = blocks[loc as LocString];
|
|
|
|
const id = block.event.id;
|
|
|
|
if (id in arrow) {
|
|
|
|
const from = `${now},${loc},${arrow[id]}` as BFSFromString;
|
|
|
|
const to = `${target},${ev.loc![0]},${
|
|
|
|
ev.loc![1]
|
|
|
|
}` as BFSToString;
|
|
|
|
link[from] = to;
|
|
|
|
if (!used[target]) {
|
|
|
|
queue.push(target);
|
|
|
|
floors.push(target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
used[now] = true;
|
2022-12-31 22:45:32 +08:00
|
|
|
}
|
2023-01-01 00:06:45 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
maps: floors,
|
|
|
|
link
|
|
|
|
};
|
2022-12-31 22:45:32 +08:00
|
|
|
}
|