clone

fifteen puzzle games for the terminal, with daily puzzles, weekly ladders and xp, built on bubble tea

debug(nonogram): add mouse event telemetry to debug overlay

Dami committed bfa7389
Shows last mouse screen position, button, grid hit-test result, grid
origin, terminal size, paint brush and drag state. Use Ctrl+E to
toggle the debug overlay while testing mouse interaction.
commit
bfa7389bcd1b931d55a2f42f1ee8e15525881b46
parent
ccba74ad8fd14ad9aa3c1c76fc766a5986b54064
author
Dami <dami.etoile@gmail.com>
1 file changed, +22 -5
Mnonogram/Model.go27++++++++++++++++++++++-----
M nonogram/Model.go +22 -5
@@ -40,6 +40,13 @@ type Model struct {
4040 4141 // Screen geometry for mouse hit-testing.4242 termWidth, termHeight int43+44+ // Debug: last mouse event info.45+ lastMouseX, lastMouseY int46+ lastMouseBtn string47+ lastMouseGridCol int48+ lastMouseGridRow int49+ lastMouseHit bool4350 }4451 4552 func New(mode NonogramMode, hints Hints) (game.Gamer, error) {
@@ -119,11 +126,12 @@ func (m Model) Update(msg tea.Msg) (game.Gamer, tea.Cmd) {
119126 }120127 121128 case tea.MouseClickMsg:122- if m.solved {123- break124- }129+ m.lastMouseX, m.lastMouseY = msg.X, msg.Y130+ m.lastMouseBtn = msg.String()125131 col, row, ok := m.screenToGrid(msg.X, msg.Y)126- if !ok {132+ m.lastMouseGridCol, m.lastMouseGridRow = col, row133+ m.lastMouseHit = ok134+ if m.solved || !ok {127135 break128136 }129137 m.cursor.X, m.cursor.Y = col, row
@@ -183,11 +191,20 @@ func (m Model) GetDebugInfo() string {
183191 status = "Solved"184192 }185193 194+ ox, oy := m.gridOrigin()195+ hitStr := "miss"196+ if m.lastMouseHit {197+ hitStr = fmt.Sprintf("(%d, %d)", m.lastMouseGridCol, m.lastMouseGridRow)198+ }199+186200 s := game.DebugHeader("Nonogram", [][2]string{187201 {"Status", status},188202 {"Cursor", fmt.Sprintf("(%d, %d)", m.cursor.X, m.cursor.Y)},189203 {"Grid Size", fmt.Sprintf("%d x %d", m.width, m.height)},190- {"Hint Widths", fmt.Sprintf("row: %d, col: %d", m.rowHints.RequiredLen()*cellWidth, m.colHints.RequiredLen())},204+ {"Term Size", fmt.Sprintf("%d x %d", m.termWidth, m.termHeight)},205+ {"Grid Origin", fmt.Sprintf("(%d, %d)", ox, oy)},206+ {"Last Mouse", fmt.Sprintf("screen=(%d, %d) btn=%s grid=%s", m.lastMouseX, m.lastMouseY, m.lastMouseBtn, hitStr)},207+ {"Paint/Drag", fmt.Sprintf("brush=%d drag=%d keyrel=%v", m.paintBrush, m.dragging, m.supportsKeyRelease)},191208 })192209 193210 s += tomoDebugTable("Row Tomography", "Row", m.rowHints, m.currentHints.rows)