// assets/scripts/FruitConfig.ts
import { SpriteFrame } from 'cc';

export interface FruitDef {
  level: number;       // 1..MAX
  name: string;
  radius: number;      // 物理半径（像素）
  score: number;       // 合成到该等级获得的分数
  sprite?: SpriteFrame; // 运行时由 GameManager 注入
}

export const MAX_LEVEL = 11; // 西瓜

// 半径与分数可按手感微调（半径越大越难堆）
export const FRUITS: FruitDef[] = [
  { level: 1,  name: '樱桃',   radius: 26, score: 1 },
  { level: 2,  name: '草莓',   radius: 30, score: 2 },
  { level: 3,  name: '葡萄',   radius: 34, score: 4 },
  { level: 4,  name: '橘子',   radius: 38, score: 8 },
  { level: 5,  name: '柠檬',   radius: 44, score: 16 },
  { level: 6,  name: '猕猴桃', radius: 50, score: 24 },
  { level: 7,  name: '番茄',   radius: 58, score: 36 },
  { level: 8,  name: '桃子',   radius: 66, score: 48 },
  { level: 9,  name: '菠萝',   radius: 74, score: 64 },
  { level: 10, name: '哈密瓜', radius: 84, score: 96 },
  { level: 11, name: '西瓜',   radius: 96, score: 128 },
];

export function clampLevel(lv: number) {
  if (lv < 1) return 1; if (lv > MAX_LEVEL) return MAX_LEVEL; return lv;
}

export function randomStartLevel(min=1, max=5) {
  const a = Math.max(1, Math.min(MAX_LEVEL-1, min));
  const b = Math.max(a, Math.min(MAX_LEVEL-1, max));
  return Math.floor(Math.random() * (b - a + 1)) + a;
}