topfans/frontend/pages/square/config/cabin.js
2026-04-13 16:16:41 +08:00

117 lines
3.2 KiB
JavaScript

// ========== 图片原始尺寸 ==========
export const IMAGE_W = 2012
export const IMAGE_H = 1918
// ========== 小屋类型定义 ==========
export const CABIN_DEFS = [
{ src: '/static/components/cabin1.png', imgW: 1000, imgH: 1000, anchorX: 500, anchorY: 680 },
{ src: '/static/components/cabin2.png', imgW: 1000, imgH: 1000, anchorX: 500, anchorY: 680 },
{ src: '/static/components/cabin3.png', imgW: 1000, imgH: 1351, anchorX: 500, anchorY: 965 },
{ src: '/static/components/cabin4.png', imgW: 1000, imgH: 1223, anchorX: 500, anchorY: 875 },
]
// ========== 根据等级返回 cabin 类型索引 ==========
export const cabinTypeByLevel = (level) => {
if (level >= 7) return 3
if (level >= 5) return 2
if (level >= 3) return 1
return 0
}
// ========== 背景网格配置 ==========
export const GRID_CONFIG = {
backgroundWidth: 2012,
backgroundHeight: 1918,
grid: {
rows: 11,
cols: 4,
startX: -260,
startY: -20,
spacingX: 515,
spacingY: 180, // 减小垂直间距
staggered: true,
staggerOffsetX: 260,
cellWidth: 200,
cellHeight: 150,
excludeRows: [0, 1, 2],
},
// 手动微调个别位置
manualAdjustments: {
// 可以在这里添加需要微调的坐标
// 格式: index: { x: newX, y: newY }
16: { x: -255, y: 740 },
17: { x: 255, y: 740 },
18: { x: 750, y: 740 },
19: { x: 1265, y: 740 },
20: { x: 0, y: 900 },
21: { x: 505, y: 900 },
22: { x: 1010, y: 900 },
23: { x: 1515, y: 900 },
24: { x: -245, y: 1120 },
25: { x: 255, y: 1120 },
26: { x: 750, y: 1120 },
27: { x: 1265, y: 1120 },
28: { x: 0, y: 1300 },
29: { x: 505, y: 1300 },
30: { x: 1010, y: 1300 },
31: { x: 1515, y: 1300 },
32: { x: -245, y: 1520 },
33: { x: 255, y: 1520 },
34: { x: 750, y: 1520 },
35: { x: 1265, y: 1520 },
36: { x: 0, y: 1690 },
37: { x: 505, y: 1690 },
38: { x: 1010, y: 1690 },
39: { x: 1515, y: 1690 },
40: { x: -245, y: 1880 },
41: { x: 255, y: 1880 },
42: { x: 750, y: 1880 },
43: { x: 1265, y: 1880 },
}
}
// ========== 网格坐标生成函数 ==========
export function generateGridCoordinates(config = GRID_CONFIG) {
const { rows, cols, startX, startY, spacingX, spacingY, staggered, staggerOffsetX, excludeRows } = config.grid
const coords = []
// 先填充被排除行的占位符
for (let row = 0; row < rows; row++) {
if (excludeRows.includes(row)) {
for (let col = 0; col < cols; col++) {
coords.push({
x: 0,
y: 0,
row,
col,
index: coords.length
})
}
} else {
for (let col = 0; col < cols; col++) {
const offsetX = staggered && row % 2 === 1 ? staggerOffsetX : 0
coords.push({
x: startX + col * spacingX + offsetX,
y: startY + row * spacingY,
row,
col,
index: coords.length
})
}
}
}
// 应用手动微调
Object.entries(config.manualAdjustments || {}).forEach(([index, adjustment]) => {
const idx = parseInt(index)
if (coords[idx]) {
coords[idx].x = adjustment.x ?? coords[idx].x
coords[idx].y = adjustment.y ?? coords[idx].y
}
})
return coords
}