diff --git a/assets/tiles/bamboo_9.png b/assets/tiles/bamboo_0.png similarity index 100% rename from assets/tiles/bamboo_9.png rename to assets/tiles/bamboo_0.png diff --git a/assets/tiles/desert.png b/assets/tiles/desert.png deleted file mode 100644 index d823aa1..0000000 Binary files a/assets/tiles/desert.png and /dev/null differ diff --git a/assets/tiles/desert_0.png b/assets/tiles/desert_0.png new file mode 100644 index 0000000..86f71b2 Binary files /dev/null and b/assets/tiles/desert_0.png differ diff --git a/assets/tiles/desert_1.png b/assets/tiles/desert_1.png new file mode 100644 index 0000000..c6d70fa Binary files /dev/null and b/assets/tiles/desert_1.png differ diff --git a/assets/tiles/desert_2.png b/assets/tiles/desert_2.png new file mode 100644 index 0000000..774a156 Binary files /dev/null and b/assets/tiles/desert_2.png differ diff --git a/assets/tiles/desert_3.png b/assets/tiles/desert_3.png new file mode 100644 index 0000000..65fc7ec Binary files /dev/null and b/assets/tiles/desert_3.png differ diff --git a/assets/tiles/desert_4.png b/assets/tiles/desert_4.png new file mode 100644 index 0000000..12423ec Binary files /dev/null and b/assets/tiles/desert_4.png differ diff --git a/assets/tiles/desert_5.png b/assets/tiles/desert_5.png new file mode 100644 index 0000000..9dc4392 Binary files /dev/null and b/assets/tiles/desert_5.png differ diff --git a/assets/tiles/desert_6.png b/assets/tiles/desert_6.png new file mode 100644 index 0000000..3b93346 Binary files /dev/null and b/assets/tiles/desert_6.png differ diff --git a/assets/tiles/desert_7.png b/assets/tiles/desert_7.png new file mode 100644 index 0000000..273ddfa Binary files /dev/null and b/assets/tiles/desert_7.png differ diff --git a/assets/tiles/desert_8.png b/assets/tiles/desert_8.png new file mode 100644 index 0000000..21194e5 Binary files /dev/null and b/assets/tiles/desert_8.png differ diff --git a/assets/tiles/forest.png b/assets/tiles/forest.png deleted file mode 100644 index 66e810f..0000000 Binary files a/assets/tiles/forest.png and /dev/null differ diff --git a/assets/tiles/forest_0.png b/assets/tiles/forest_0.png new file mode 100644 index 0000000..72f8014 Binary files /dev/null and b/assets/tiles/forest_0.png differ diff --git a/assets/tiles/forest_1.png b/assets/tiles/forest_1.png new file mode 100644 index 0000000..603aa87 Binary files /dev/null and b/assets/tiles/forest_1.png differ diff --git a/assets/tiles/forest_2.png b/assets/tiles/forest_2.png new file mode 100644 index 0000000..a5ac629 Binary files /dev/null and b/assets/tiles/forest_2.png differ diff --git a/assets/tiles/forest_3.png b/assets/tiles/forest_3.png new file mode 100644 index 0000000..3aadf31 Binary files /dev/null and b/assets/tiles/forest_3.png differ diff --git a/assets/tiles/forest_4.png b/assets/tiles/forest_4.png new file mode 100644 index 0000000..7061b8a Binary files /dev/null and b/assets/tiles/forest_4.png differ diff --git a/assets/tiles/forest_5.png b/assets/tiles/forest_5.png new file mode 100644 index 0000000..8c65807 Binary files /dev/null and b/assets/tiles/forest_5.png differ diff --git a/assets/tiles/forest_6.png b/assets/tiles/forest_6.png new file mode 100644 index 0000000..90b8716 Binary files /dev/null and b/assets/tiles/forest_6.png differ diff --git a/assets/tiles/forest_7.png b/assets/tiles/forest_7.png new file mode 100644 index 0000000..52d7bb4 Binary files /dev/null and b/assets/tiles/forest_7.png differ diff --git a/assets/tiles/forest_8.png b/assets/tiles/forest_8.png new file mode 100644 index 0000000..02ca6c8 Binary files /dev/null and b/assets/tiles/forest_8.png differ diff --git a/assets/tiles/glacier.png b/assets/tiles/glacier.png deleted file mode 100644 index 63c8705..0000000 Binary files a/assets/tiles/glacier.png and /dev/null differ diff --git a/assets/tiles/glacier_0.png b/assets/tiles/glacier_0.png new file mode 100644 index 0000000..ab7385d Binary files /dev/null and b/assets/tiles/glacier_0.png differ diff --git a/assets/tiles/glacier_1.png b/assets/tiles/glacier_1.png new file mode 100644 index 0000000..f987fb1 Binary files /dev/null and b/assets/tiles/glacier_1.png differ diff --git a/assets/tiles/glacier_2.png b/assets/tiles/glacier_2.png new file mode 100644 index 0000000..e021f00 Binary files /dev/null and b/assets/tiles/glacier_2.png differ diff --git a/assets/tiles/glacier_3.png b/assets/tiles/glacier_3.png new file mode 100644 index 0000000..a0b8e64 Binary files /dev/null and b/assets/tiles/glacier_3.png differ diff --git a/assets/tiles/glacier_4.png b/assets/tiles/glacier_4.png new file mode 100644 index 0000000..1c19f89 Binary files /dev/null and b/assets/tiles/glacier_4.png differ diff --git a/assets/tiles/glacier_5.png b/assets/tiles/glacier_5.png new file mode 100644 index 0000000..569d4a8 Binary files /dev/null and b/assets/tiles/glacier_5.png differ diff --git a/assets/tiles/glacier_6.png b/assets/tiles/glacier_6.png new file mode 100644 index 0000000..f137326 Binary files /dev/null and b/assets/tiles/glacier_6.png differ diff --git a/assets/tiles/glacier_7.png b/assets/tiles/glacier_7.png new file mode 100644 index 0000000..a689283 Binary files /dev/null and b/assets/tiles/glacier_7.png differ diff --git a/assets/tiles/glacier_8.png b/assets/tiles/glacier_8.png new file mode 100644 index 0000000..b76f7d0 Binary files /dev/null and b/assets/tiles/glacier_8.png differ diff --git a/assets/tiles/gobi_9.png b/assets/tiles/gobi_0.png similarity index 100% rename from assets/tiles/gobi_9.png rename to assets/tiles/gobi_0.png diff --git a/assets/tiles/grassland.png b/assets/tiles/grassland.png deleted file mode 100644 index 490ed1f..0000000 Binary files a/assets/tiles/grassland.png and /dev/null differ diff --git a/assets/tiles/grassland_0.png b/assets/tiles/grassland_0.png new file mode 100644 index 0000000..cbe5642 Binary files /dev/null and b/assets/tiles/grassland_0.png differ diff --git a/assets/tiles/grassland_1.png b/assets/tiles/grassland_1.png new file mode 100644 index 0000000..f619e3a Binary files /dev/null and b/assets/tiles/grassland_1.png differ diff --git a/assets/tiles/grassland_2.png b/assets/tiles/grassland_2.png new file mode 100644 index 0000000..796fd39 Binary files /dev/null and b/assets/tiles/grassland_2.png differ diff --git a/assets/tiles/grassland_3.png b/assets/tiles/grassland_3.png new file mode 100644 index 0000000..beab884 Binary files /dev/null and b/assets/tiles/grassland_3.png differ diff --git a/assets/tiles/grassland_4.png b/assets/tiles/grassland_4.png new file mode 100644 index 0000000..ae326af Binary files /dev/null and b/assets/tiles/grassland_4.png differ diff --git a/assets/tiles/grassland_5.png b/assets/tiles/grassland_5.png new file mode 100644 index 0000000..6264d74 Binary files /dev/null and b/assets/tiles/grassland_5.png differ diff --git a/assets/tiles/grassland_6.png b/assets/tiles/grassland_6.png new file mode 100644 index 0000000..cf6afdf Binary files /dev/null and b/assets/tiles/grassland_6.png differ diff --git a/assets/tiles/grassland_7.png b/assets/tiles/grassland_7.png new file mode 100644 index 0000000..00d7287 Binary files /dev/null and b/assets/tiles/grassland_7.png differ diff --git a/assets/tiles/grassland_8.png b/assets/tiles/grassland_8.png new file mode 100644 index 0000000..2ac751b Binary files /dev/null and b/assets/tiles/grassland_8.png differ diff --git a/assets/tiles/island_9.png b/assets/tiles/island_0.png similarity index 100% rename from assets/tiles/island_9.png rename to assets/tiles/island_0.png diff --git a/assets/tiles/mountain.png b/assets/tiles/mountain.png deleted file mode 100644 index ac5134b..0000000 Binary files a/assets/tiles/mountain.png and /dev/null differ diff --git a/assets/tiles/mountain_0.png b/assets/tiles/mountain_0.png new file mode 100644 index 0000000..5524256 Binary files /dev/null and b/assets/tiles/mountain_0.png differ diff --git a/assets/tiles/mountain_1.png b/assets/tiles/mountain_1.png new file mode 100644 index 0000000..d28d88a Binary files /dev/null and b/assets/tiles/mountain_1.png differ diff --git a/assets/tiles/mountain_2.png b/assets/tiles/mountain_2.png new file mode 100644 index 0000000..3b9f421 Binary files /dev/null and b/assets/tiles/mountain_2.png differ diff --git a/assets/tiles/mountain_3.png b/assets/tiles/mountain_3.png new file mode 100644 index 0000000..be2d4af Binary files /dev/null and b/assets/tiles/mountain_3.png differ diff --git a/assets/tiles/mountain_4.png b/assets/tiles/mountain_4.png new file mode 100644 index 0000000..bb1c7f1 Binary files /dev/null and b/assets/tiles/mountain_4.png differ diff --git a/assets/tiles/mountain_5.png b/assets/tiles/mountain_5.png new file mode 100644 index 0000000..556fdb5 Binary files /dev/null and b/assets/tiles/mountain_5.png differ diff --git a/assets/tiles/mountain_6.png b/assets/tiles/mountain_6.png new file mode 100644 index 0000000..47a367a Binary files /dev/null and b/assets/tiles/mountain_6.png differ diff --git a/assets/tiles/mountain_7.png b/assets/tiles/mountain_7.png new file mode 100644 index 0000000..0c0f082 Binary files /dev/null and b/assets/tiles/mountain_7.png differ diff --git a/assets/tiles/mountain_8.png b/assets/tiles/mountain_8.png new file mode 100644 index 0000000..89361ea Binary files /dev/null and b/assets/tiles/mountain_8.png differ diff --git a/assets/tiles/rainforest.png b/assets/tiles/rainforest.png deleted file mode 100644 index 21e8473..0000000 Binary files a/assets/tiles/rainforest.png and /dev/null differ diff --git a/assets/tiles/rainforest_9.png b/assets/tiles/rainforest_0.png similarity index 100% rename from assets/tiles/rainforest_9.png rename to assets/tiles/rainforest_0.png diff --git a/assets/tiles/snow_mountain.png b/assets/tiles/snow_mountain.png deleted file mode 100644 index f21a833..0000000 Binary files a/assets/tiles/snow_mountain.png and /dev/null differ diff --git a/assets/tiles/snow_mountain_0.png b/assets/tiles/snow_mountain_0.png new file mode 100644 index 0000000..f583f97 Binary files /dev/null and b/assets/tiles/snow_mountain_0.png differ diff --git a/assets/tiles/snow_mountain_1.png b/assets/tiles/snow_mountain_1.png new file mode 100644 index 0000000..c3a8509 Binary files /dev/null and b/assets/tiles/snow_mountain_1.png differ diff --git a/assets/tiles/snow_mountain_2.png b/assets/tiles/snow_mountain_2.png new file mode 100644 index 0000000..6e97382 Binary files /dev/null and b/assets/tiles/snow_mountain_2.png differ diff --git a/assets/tiles/snow_mountain_3.png b/assets/tiles/snow_mountain_3.png new file mode 100644 index 0000000..af59a97 Binary files /dev/null and b/assets/tiles/snow_mountain_3.png differ diff --git a/assets/tiles/snow_mountain_4.png b/assets/tiles/snow_mountain_4.png new file mode 100644 index 0000000..7e761ec Binary files /dev/null and b/assets/tiles/snow_mountain_4.png differ diff --git a/assets/tiles/snow_mountain_5.png b/assets/tiles/snow_mountain_5.png new file mode 100644 index 0000000..f8798dc Binary files /dev/null and b/assets/tiles/snow_mountain_5.png differ diff --git a/assets/tiles/snow_mountain_6.png b/assets/tiles/snow_mountain_6.png new file mode 100644 index 0000000..2dcae6f Binary files /dev/null and b/assets/tiles/snow_mountain_6.png differ diff --git a/assets/tiles/snow_mountain_7.png b/assets/tiles/snow_mountain_7.png new file mode 100644 index 0000000..6844739 Binary files /dev/null and b/assets/tiles/snow_mountain_7.png differ diff --git a/assets/tiles/snow_mountain_8.png b/assets/tiles/snow_mountain_8.png new file mode 100644 index 0000000..c5b218a Binary files /dev/null and b/assets/tiles/snow_mountain_8.png differ diff --git a/assets/tiles/swamp_9.png b/assets/tiles/swamp_0.png similarity index 100% rename from assets/tiles/swamp_9.png rename to assets/tiles/swamp_0.png diff --git a/web/src/components/game/composables/useTextures.ts b/web/src/components/game/composables/useTextures.ts index 18d4e9e..2d95ba7 100644 --- a/web/src/components/game/composables/useTextures.ts +++ b/web/src/components/game/composables/useTextures.ts @@ -7,12 +7,20 @@ import { getClusteredTileVariant } from '@/utils/procedural' TextureStyle.defaultOptions.scaleMode = 'nearest' // 地形变体配置 -const TILE_VARIANTS: Record = { - 'RAINFOREST': { prefix: 'rainforest', count: 9 }, - 'BAMBOO': { prefix: 'bamboo', count: 9 }, - 'GOBI': { prefix: 'gobi', count: 9 }, - 'ISLAND': { prefix: 'island', count: 9 }, - 'SWAMP': { prefix: 'swamp', count: 9 }, +// startIndex: 变体索引起始值,默认为 0 +const TILE_VARIANTS: Record = { + // 从 0 开始的变体 (0-8) + 'GLACIER': { prefix: 'glacier', count: 9, startIndex: 0 }, + 'MOUNTAIN': { prefix: 'mountain', count: 9, startIndex: 0 }, + 'DESERT': { prefix: 'desert', count: 9, startIndex: 0 }, + 'SNOW_MOUNTAIN': { prefix: 'snow_mountain', count: 9, startIndex: 0 }, + 'FOREST': { prefix: 'forest', count: 9, startIndex: 0 }, + 'GRASSLAND': { prefix: 'grassland', count: 9, startIndex: 0 }, + 'RAINFOREST': { prefix: 'rainforest', count: 9, startIndex: 0 }, + 'BAMBOO': { prefix: 'bamboo', count: 9, startIndex: 0 }, + 'GOBI': { prefix: 'gobi', count: 9, startIndex: 0 }, + 'ISLAND': { prefix: 'island', count: 9, startIndex: 0 }, + 'SWAMP': { prefix: 'swamp', count: 9, startIndex: 0 }, } // 全局纹理缓存,避免重复加载 @@ -83,8 +91,8 @@ export function useTextures() { // Load Tile Variants const variantPromises: Promise[] = [] - Object.entries(TILE_VARIANTS).forEach(([key, { prefix, count }]) => { - for (let i = 1; i <= count; i++) { + Object.entries(TILE_VARIANTS).forEach(([key, { prefix, count, startIndex = 0 }]) => { + for (let i = startIndex; i < startIndex + count; i++) { const variantKey = `${key}_${i}` const url = `/assets/tiles/${prefix}_${i}.png` variantPromises.push( diff --git a/web/src/utils/procedural.ts b/web/src/utils/procedural.ts index 3fb98b0..97d60be 100644 --- a/web/src/utils/procedural.ts +++ b/web/src/utils/procedural.ts @@ -19,20 +19,21 @@ function random(x: number, y: number): number { * 算法逻辑: * 1. 使用双重正弦波生成低频噪声(Biomes/群落感),让相邻的格子倾向于选择索引相近的变体。 * 2. 叠加高频 Hash 扰动(Jitter),避免纹理过于死板或出现明显的人工波纹。 - * 3. 最终效果:变体会在地图上呈现自然的“斑块状”分布,而非杂乱的噪点。 + * 3. 最终效果:变体会在地图上呈现自然的"斑块状"分布,而非杂乱的噪点。 * * @param x 地图 X 坐标 * @param y 地图 Y 坐标 * @param count 变体总数 (例如 9) - * @returns 1 到 count 之间的整数索引 + * @param startIndex 变体索引起始值,默认为 0 + * @returns startIndex 到 startIndex + count - 1 之间的整数索引 */ -export function getClusteredTileVariant(x: number, y: number, count: number): number { - if (count <= 1) return 1; +export function getClusteredTileVariant(x: number, y: number, count: number, startIndex: number = 0): number { + if (count <= 1) return startIndex; // 1. 低频噪声 (Large Scale Noise) // 决定区域的主色调。Scale 越小,斑块越大。 // 0.15 意味着大约 2PI / 0.15 ~= 40 格一个完整周期, - // 视觉上大约 10-20 格为一个明显的“群落”。 + // 视觉上大约 10-20 格为一个明显的"群落"。 const scale = 0.15; // 使用两个不同频率和方向的波叠加,打破完美的对角线感 @@ -55,13 +56,13 @@ export function getClusteredTileVariant(x: number, y: number, count: number): nu // 钳制到 [0, 1] finalValue = Math.max(0, Math.min(1, finalValue)); - // 4. 映射到 [1, count] - // 使用 Math.floor(val * count) 得到 0..count-1,再 +1 - let index = Math.floor(finalValue * count) + 1; + // 4. 映射到 [startIndex, startIndex + count - 1] + let index = Math.floor(finalValue * count) + startIndex; // 边界保护 (防止浮点误差导致溢出) - if (index > count) index = count; - if (index < 1) index = 1; + const maxIndex = startIndex + count - 1; + if (index > maxIndex) index = maxIndex; + if (index < startIndex) index = startIndex; return index; }