@@ -1,6 +1,5 @@
|
||||
import { Node, UITransform, Layers, Sprite } from 'cc';
|
||||
import { LevelConfig } from './LevelTypes';
|
||||
import { CommonDefine } from '../core/Define';
|
||||
import { VisualAssets, normalizeTheme } from '../visual/VisualAssets';
|
||||
import { layoutLevelTiles, sortIsoTiles } from './TileLayout';
|
||||
import { LevelTileLayout } from './LevelTileLayout';
|
||||
@@ -9,6 +8,7 @@ import { GridSnapHelper } from './GridSnapHelper';
|
||||
import { getThemeBorderDecorKey } from '../theme/ThemeRegistry';
|
||||
import { centerLevelRoot, syncTileNodesFromConfig } from './LevelTileSync';
|
||||
import { mergeLevelConfigWithMapData } from './LevelConfigMerge';
|
||||
import { resolveTileNameAtCell, normalizeGroundTile, normalizeBorderTile } from './TileKinds';
|
||||
|
||||
const UI_LAYER = Layers.Enum.UI_2D;
|
||||
|
||||
@@ -70,13 +70,10 @@ export class LevelDisplay {
|
||||
const decorKey = getThemeBorderDecorKey(config.theme);
|
||||
if (decorKey) names.add(decorKey);
|
||||
for (const v of Object.values(config.ground ?? {})) {
|
||||
const tile = typeof v === 'string' ? v.trim() : (typeof v === 'number' ? String(v) : '');
|
||||
if (tile) names.add(tile);
|
||||
names.add(normalizeGroundTile(v));
|
||||
}
|
||||
for (const v of Object.values(config.border ?? {})) {
|
||||
if (v === true) continue;
|
||||
const tile = typeof v === 'string' ? v.trim() : (typeof v === 'number' ? String(v) : '');
|
||||
if (tile) names.add(tile);
|
||||
names.add(normalizeBorderTile(v));
|
||||
}
|
||||
return Array.from(names);
|
||||
}
|
||||
@@ -98,7 +95,7 @@ export class LevelDisplay {
|
||||
}
|
||||
|
||||
static sortIsoLayers(levelRoot: Node) {
|
||||
sortIsoTiles(levelRoot);
|
||||
sortIsoTiles(levelRoot, true);
|
||||
}
|
||||
|
||||
private static queueTileSprite(
|
||||
@@ -122,31 +119,24 @@ export class LevelDisplay {
|
||||
static async refreshTileSprites(levelRoot: Node, config: LevelConfig, theme: string) {
|
||||
const jobs: Promise<void>[] = [];
|
||||
|
||||
const processLayer = (layer: Node | null, isBorder: boolean) => {
|
||||
const processLayer = (layer: Node | null, layerKind: 'ground' | 'border') => {
|
||||
if (!layer) return;
|
||||
for (const ch of layer.children) {
|
||||
if (!ch?.active) continue;
|
||||
const m = isBorder
|
||||
const m = layerKind === 'border'
|
||||
? /^b_(-?\d+)_(-?\d+)$/.exec(ch.name)
|
||||
: /^g_(-?\d+)_(-?\d+)$/.exec(ch.name);
|
||||
if (!m) continue;
|
||||
const key = `${m[1]},${m[2]}`;
|
||||
const cx = parseInt(m[1], 10);
|
||||
const cy = parseInt(m[2], 10);
|
||||
let tileName: string;
|
||||
if (isBorder) {
|
||||
tileName = config.border?.[key] as string | boolean | undefined;
|
||||
if (tileName === true || tileName === undefined) tileName = 'WallBlock';
|
||||
if (typeof tileName !== 'string') tileName = 'WallBlock';
|
||||
} else {
|
||||
tileName = config.ground?.[key] ?? CommonDefine.BlockBase;
|
||||
}
|
||||
const tileName = resolveTileNameAtCell(layerKind, key, config.ground, config.border);
|
||||
this.queueTileSprite(jobs, ch, tileName, cx, cy, theme);
|
||||
}
|
||||
};
|
||||
|
||||
processLayer(levelRoot.getChildByName('Ground'), false);
|
||||
processLayer(levelRoot.getChildByName('Border'), true);
|
||||
processLayer(levelRoot.getChildByName('Ground'), 'ground');
|
||||
processLayer(levelRoot.getChildByName('Border'), 'border');
|
||||
|
||||
const tiles = levelRoot.getChildByName('Tiles');
|
||||
if (tiles) {
|
||||
@@ -158,16 +148,14 @@ export class LevelDisplay {
|
||||
const key = `${mg[1]},${mg[2]}`;
|
||||
this.queueTileSprite(
|
||||
jobs, ch,
|
||||
config.ground?.[key] ?? CommonDefine.BlockBase,
|
||||
resolveTileNameAtCell('ground', key, config.ground, config.border),
|
||||
parseInt(mg[1], 10), parseInt(mg[2], 10), theme,
|
||||
);
|
||||
} else if (mb) {
|
||||
const key = `${mb[1]},${mb[2]}`;
|
||||
let tileName = config.border?.[key];
|
||||
if (tileName === true || tileName === undefined) tileName = 'WallBlock';
|
||||
if (typeof tileName !== 'string') tileName = 'WallBlock';
|
||||
this.queueTileSprite(
|
||||
jobs, ch, tileName,
|
||||
jobs, ch,
|
||||
resolveTileNameAtCell('border', key, config.ground, config.border),
|
||||
parseInt(mb[1], 10), parseInt(mb[2], 10), theme,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user