refactor: enforce package boundaries
This commit is contained in:
@@ -1,25 +1,6 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import { existsSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { loadMapDefinitionByName as loadRuntimeMapDefinitionByName } from '@sammo-ts/game-engine/scenario/mapLoader.js';
|
||||
import type { MapDefinition } from '@sammo-ts/logic';
|
||||
|
||||
import { MapDefinitionSchema, type MapDefinition } from '@sammo-ts/logic';
|
||||
|
||||
const resolveWorkspaceRoot = (): string => {
|
||||
let current = path.resolve(process.cwd());
|
||||
for (let depth = 0; depth <= 6; depth += 1) {
|
||||
if (existsSync(path.join(current, 'pnpm-workspace.yaml'))) {
|
||||
return current;
|
||||
}
|
||||
const parent = path.dirname(current);
|
||||
if (parent === current) {
|
||||
break;
|
||||
}
|
||||
current = parent;
|
||||
}
|
||||
return path.resolve(process.cwd());
|
||||
};
|
||||
|
||||
const RESOURCE_MAP_ROOT = path.resolve(resolveWorkspaceRoot(), 'resources/map');
|
||||
const mapCache = new Map<string, MapDefinition>();
|
||||
|
||||
export const loadMapDefinitionByName = async (mapName: string): Promise<MapDefinition> => {
|
||||
@@ -30,8 +11,7 @@ export const loadMapDefinitionByName = async (mapName: string): Promise<MapDefin
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
const raw = await fs.readFile(path.join(RESOURCE_MAP_ROOT, `map_${mapName}.json`), 'utf-8');
|
||||
const map = MapDefinitionSchema.parse(JSON.parse(raw));
|
||||
const map = await loadRuntimeMapDefinitionByName(mapName);
|
||||
mapCache.set(mapName, map);
|
||||
return map;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user