fix: clamp target cursor when monsters die

This commit is contained in:
2026-03-24 10:44:25 +09:00
parent b6c28ddd80
commit 15614b966a

View File

@@ -285,6 +285,14 @@ func (m Model) updateGame(msg tea.Msg) (tea.Model, tea.Cmd) {
// Refresh state on every update
if m.session != nil {
m.gameState = m.session.GetState()
// Clamp target cursor to valid range after monsters die
if len(m.gameState.Monsters) > 0 {
if m.targetCursor >= len(m.gameState.Monsters) {
m.targetCursor = len(m.gameState.Monsters) - 1
}
} else {
m.targetCursor = 0
}
}
if m.gameState.GameOver {