mirror of
https://github.com/motajs/template.git
synced 2026-11-13 23:04:32 +08:00
refactor: 地图 MapLayer
This commit is contained in:
1 parent
122567b050
commit
b262918082
15 files changed
+281
-267
No files matched your search
@@ -138,8 +138,8 @@ export class PathFinder implements IPathFinder {
|
||||
target: ITileLocator
|
||||
): IPathfindingStep[] {
|
||||
const indexer = this.graph.indexer;
|
||||
const startIndex = indexer.locaterToIndex(start);
|
||||
const targetIndex = indexer.locaterToIndex(target);
|
||||
const startIndex = indexer.locatorToIndex(start);
|
||||
const targetIndex = indexer.locatorToIndex(target);
|
||||
if (startIndex === targetIndex) return [];
|
||||
if (!graph.nodes.has(startIndex) || !graph.nodes.has(targetIndex)) {
|
||||
return [];
|
||||
@@ -190,7 +190,7 @@ export class PathFinder implements IPathFinder {
|
||||
const step = prev.get(curr);
|
||||
if (!step) return [];
|
||||
steps.push(step);
|
||||
curr = indexer.locaterToIndex(step.from);
|
||||
curr = indexer.locatorToIndex(step.from);
|
||||
}
|
||||
steps.reverse();
|
||||
return steps;
|
||||
|
||||
@@ -89,7 +89,7 @@ export class MapGraphBuilder implements IMapGraphBuilder {
|
||||
const terminals: Set<number> = new Set();
|
||||
const adjacency: Map<number, IPathGraphEdge[]> = new Map();
|
||||
const mapped: Set<number> = new Set();
|
||||
const startIndex = indexer.locaterToIndex(start);
|
||||
const startIndex = indexer.locatorToIndex(start);
|
||||
adjacency.set(startIndex, []);
|
||||
|
||||
// 以起始位置为中心 BFS,仅沿可通行有向边扩展,不可达区域不入图
|
||||
@@ -97,7 +97,7 @@ export class MapGraphBuilder implements IMapGraphBuilder {
|
||||
let head = 0;
|
||||
while (head < queue.length) {
|
||||
const { x, y } = queue[head++]!;
|
||||
const index = indexer.locToIndex(x, y);
|
||||
const index = indexer.index(x, y);
|
||||
const edges: IPathGraphEdge[] = [];
|
||||
for (const [dir, desc] of face.mapMovement()) {
|
||||
// 如果连接原地,那么应该忽略,避免陷入死循环
|
||||
@@ -106,7 +106,7 @@ export class MapGraphBuilder implements IMapGraphBuilder {
|
||||
const ny = y + desc.y;
|
||||
if (!layer.inMap(nx, ny)) continue;
|
||||
|
||||
const nextIndex = indexer.locToIndex(nx, ny);
|
||||
const nextIndex = indexer.index(nx, ny);
|
||||
const next: ITileLocator = { x: nx, y: ny };
|
||||
const handler: IPassCheckHandler = {
|
||||
currLoc: { x, y },
|
||||
@@ -132,7 +132,7 @@ export class MapGraphBuilder implements IMapGraphBuilder {
|
||||
|
||||
const nodes: Map<number, IPathGraphNode> = new Map();
|
||||
for (const index of mapped) {
|
||||
const { x, y } = indexer.indexToLocator(index);
|
||||
const { x, y } = indexer.locator(index);
|
||||
const block = layer.getLocationData(x, y)!;
|
||||
nodes.set(index, {
|
||||
x,
|
||||
|
||||
Reference in new issue
Block a user