- 新增 useGameBoardVm 数据层实施说明文档 - 添加 36字花核心玩法与前端规则摘要 - 创建游戏模块数据与界面分层第一阶段实施稿 - 定义四层架构:api/dto、store、view-model hooks、ui层 - 规范 PC 与 Mobile 共享业务逻辑的改造方案 - 明确各层职责边界和组件改造顺序
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { useMemo } from 'react'
|
|
import { CHIP_OPTIONS } from '@/constants'
|
|
import { selectSelectionTotal, useGameRoundStore } from '@/store/game'
|
|
|
|
const CHIP_IMAGE_MAP = new Map(
|
|
CHIP_OPTIONS.map((chip) => [chip.value, chip.src] as const),
|
|
)
|
|
|
|
export function useGameControlVm() {
|
|
const chips = useGameRoundStore((state) => state.chips)
|
|
const activeChipId = useGameRoundStore((state) => state.activeChipId)
|
|
const selections = useGameRoundStore((state) => state.selections)
|
|
const clearSelections = useGameRoundStore((state) => state.clearSelections)
|
|
const selectChip = useGameRoundStore((state) => state.selectChip)
|
|
const totalBetAmount = useGameRoundStore(selectSelectionTotal)
|
|
|
|
const chipItems = useMemo(
|
|
() =>
|
|
chips.map((chip) => ({
|
|
amount: chip.amount,
|
|
id: chip.id,
|
|
isSelected: chip.id === activeChipId,
|
|
src: CHIP_IMAGE_MAP.get(chip.amount) ?? CHIP_OPTIONS[0]?.src ?? '',
|
|
valueLabel: String(chip.amount),
|
|
})),
|
|
[activeChipId, chips],
|
|
)
|
|
|
|
const selectedChip =
|
|
chipItems.find((chip) => chip.id === activeChipId) ?? chipItems[0] ?? null
|
|
|
|
return {
|
|
canClear: selections.length > 0,
|
|
onChipSelect: selectChip,
|
|
onClearSelections: clearSelections,
|
|
selectedChipAmountLabel: selectedChip?.valueLabel ?? '--',
|
|
selectedChipId: activeChipId,
|
|
selectedCountLabel: `${selections.length}/5`,
|
|
totalBetAmountLabel: String(totalBetAmount),
|
|
chips: chipItems,
|
|
}
|
|
}
|