同步主站 Cocos 当前工程:关卡资源、运行脚本与打包工具。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,33 +1,12 @@
|
||||
import { Node } from 'cc';
|
||||
import { LevelConfig, SpawnConfig } from './LevelTypes';
|
||||
import { LevelConfig } from './LevelTypes';
|
||||
import { LevelMapData } from './LevelMapData';
|
||||
import { themeForLevelId } from './LevelIds';
|
||||
|
||||
function hasKeys(rec?: Record<string, unknown>): boolean {
|
||||
return !!rec && Object.keys(rec).length > 0;
|
||||
}
|
||||
|
||||
/** 地图是否覆盖玩家/道具/载具 spawn 格(旧预制体常残留错误横向砖块) */
|
||||
function groundCoversSpawns(ground: Record<string, unknown> | undefined, spawns: SpawnConfig[]): boolean {
|
||||
if (!ground || !spawns.length) return false;
|
||||
for (const s of spawns) {
|
||||
if (s.kind !== 'player' && s.kind !== 'prop' && s.kind !== 'vehicle') continue;
|
||||
if (!ground[`${s.x},${s.y}`]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Cocos 预制体 LevelMapData 优先;DB 仅作 spawns 载体时的回退 */
|
||||
function pickGround(
|
||||
fromPrefab: LevelConfig['ground'],
|
||||
fromDb: LevelConfig['ground'],
|
||||
spawns: SpawnConfig[],
|
||||
): LevelConfig['ground'] {
|
||||
if (groundCoversSpawns(fromPrefab, spawns)) return fromPrefab;
|
||||
if (groundCoversSpawns(fromDb, spawns)) return fromDb;
|
||||
if (hasKeys(fromPrefab)) return fromPrefab;
|
||||
return fromDb;
|
||||
}
|
||||
|
||||
function parseJsonRecord(json: string): Record<string, unknown> | undefined {
|
||||
try {
|
||||
const o = JSON.parse(json || '{}') as unknown;
|
||||
@@ -41,7 +20,8 @@ function parseJsonRecord(json: string): Record<string, unknown> | undefined {
|
||||
}
|
||||
|
||||
/**
|
||||
* Cocos 预制体 LevelMapData 为地图/主题权威;levels-database 主要提供 spawns。
|
||||
* 预制体 LevelMapData(编辑器里看到的地图)为地图/主题权威。
|
||||
* levels-database 只提供 spawns / boundary;仅当预制体没有地图数据时才回退到库。
|
||||
*/
|
||||
export function mergeLevelConfigWithMapData(config: LevelConfig, levelRoot: Node): LevelConfig {
|
||||
if (!levelRoot?.isValid) return config;
|
||||
@@ -51,20 +31,23 @@ export function mergeLevelConfigWithMapData(config: LevelConfig, levelRoot: Node
|
||||
const prefabGround = parseJsonRecord(md.groundJson) as LevelConfig['ground'];
|
||||
const prefabBorder = parseJsonRecord(md.borderJson) as LevelConfig['border'];
|
||||
const prefabTheme = md.theme?.trim();
|
||||
const seriesTheme = themeForLevelId(config.levelID);
|
||||
const prefabHasMap =
|
||||
hasKeys(prefabGround as Record<string, unknown>)
|
||||
|| hasKeys(prefabBorder as Record<string, unknown>);
|
||||
|
||||
const border = hasKeys(prefabBorder as Record<string, unknown>)
|
||||
? prefabBorder
|
||||
: config.border;
|
||||
if (!prefabHasMap) {
|
||||
return {
|
||||
...config,
|
||||
theme: seriesTheme || config.theme?.trim() || prefabTheme || 'silu',
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...config,
|
||||
// DB 主题优先(主站批次权威);预制体仅作缺省回退
|
||||
theme: config.theme?.trim() || prefabTheme || 'silu',
|
||||
ground: pickGround(
|
||||
prefabGround as LevelConfig['ground'],
|
||||
config.ground,
|
||||
config.spawns ?? [],
|
||||
),
|
||||
border,
|
||||
theme: seriesTheme || prefabTheme || config.theme?.trim() || 'silu',
|
||||
ground: hasKeys(prefabGround as Record<string, unknown>) ? prefabGround : config.ground,
|
||||
// 预制体已写过地图:空边框就是没有边框,不要用库里的旧 border 补上
|
||||
border: prefabBorder ?? {},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user