~hokiegeek/astro-knights-play-stats

e95b927744ec53427b705dfc71eeccb3fe791cb4 — HokieGeek 5 months ago d883bd1 main
this matrix will not work
M cmd/astro-knights-play-stats/main.go => cmd/astro-knights-play-stats/main.go +21 -19
@@ 133,27 133,29 @@ func main() {
		log.Panic(err)
	}

	stats, err := astro_knights.GetKnightUseStats(collection)
	if err != nil {
		log.Panic(err)
	}

	fmt.Println(stats)

	/*
		m := model{
			tabs: []string{"plays", "knights", "bosses", "homeworlds"},
			tabContent: []tea.Model{
				newTabPlays(plays),
				newTabKnights(plays),
				newTabBosses(plays),
				newTabHomeworlds(plays),
			},
		stats, err := astro_knights.GetKnightUseStats(collection)
		if err != nil {
			log.Panic(err)
		}

		if _, err := tea.NewProgram(m, tea.WithAltScreen()).Run(); err != nil {
			fmt.Println("WTF?:", err)
			os.Exit(1)
		}
		fmt.Println(stats)
	*/

	/*
	 */
	m := model{
		tabs: []string{"plays", "knights", "bosses", "homeworlds"},
		tabContent: []tea.Model{
			newTabPlays(collection),
			newTabKnights(collection),
			newTabBosses(collection.Plays),
			newTabHomeworlds(collection.Plays),
		},
	}

	if _, err := tea.NewProgram(m, tea.WithAltScreen()).Run(); err != nil {
		fmt.Println("WTF?:", err)
		os.Exit(1)
	}
}

M cmd/astro-knights-play-stats/tab_knights.go => cmd/astro-knights-play-stats/tab_knights.go +60 -32
@@ 1,14 1,17 @@
package main

import (
	"log"
	"strconv"

	"git.sr.ht/~hokiegeek/astro-knights-play-stats"

	// "github.com/charmbracelet/bubbles/table"
	"github.com/charmbracelet/bubbles/table"
	tea "github.com/charmbracelet/bubbletea"
)

type tabKnightsModel struct {
	// matrixTable    table.Model
	matrixTable   table.Model
	width, height int
}



@@ 25,46 28,71 @@ func (m tabKnightsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

	case tea.KeyMsg:
		switch keypress := msg.String(); keypress {
		/*
			case "esc":
				if m.playsTable.Focused() {
					m.playsTable.Blur()
				} else {
					m.playsTable.Focus()
				}
			case "enter":
				return m, tea.Batch(
					tea.Printf("Let's go to %s!", m.playsTable.SelectedRow()[1]),
				)
		*/
		case "esc":
			if m.matrixTable.Focused() {
				m.matrixTable.Blur()
			} else {
				m.matrixTable.Focus()
			}
		case "enter":
			return m, tea.Batch(
				tea.Printf("Let's go to %s!", m.matrixTable.SelectedRow()[1]),
			)

		}
	}
	// m.matrixTable, cmd = m.matrixTable.Update(msg)
	m.matrixTable, cmd = m.matrixTable.Update(msg)

	return m, cmd
}

func (m tabKnightsModel) View() string {
	/*
		if m.height > 0 {
			m.matrixTable.SetHeight(m.height - 12) // TODO: magic number
		}
		return basicTableStyle.Render(m.matrixTable.View())
	*/
	return "TODO"
	if m.height > 0 {
		m.matrixTable.SetHeight(m.height - 12) // TODO: magic number
	}
	return basicTableStyle.Render(m.matrixTable.View())
}

func newTabKnights(plays []astro_knights.Play) tea.Model {
	// stats, err := astro_knights.GetKnightUseStats(plays)
	// if err != nil {
	// 	panic(err)
	// }
func createKnightsMatrix(matrix map[astro_knights.KnightID]map[astro_knights.KnightID]int) table.Model {
	knights := make([]astro_knights.KnightID, 0, len(matrix))
	for k := range matrix {
		knights = append(knights, k)
	}

	rows := make([]table.Row, len(knights))
	// TODO: grab a list of the knights

	return tabKnightsModel{}
	/*
		return tabKnightsModel{
			matrixTable: createPlaysTable(plays),
	// for knight, knights := range matrix {
	for _, k1 := range knights {
		row := table.Row{string(k1)}
		for _, k2 := range knights {
			val := ""
			if matrix[k1][k2] > 0 {
				val = strconv.Itoa(matrix[k1][k2])
			}
			row = append(row, val)
		}
	*/
		rows = append(rows, row)
	}

	columns := make([]table.Column, len(knights)+1)
	columns[0].Width = 15

	for i, k := range knights {
		columns[i+1].Title = string(k)
		columns[i+1].Width = 8
	}

	return createStandardTable(columns, rows)
}

func newTabKnights(collection astro_knights.UserCollection) tea.Model {
	stats, err := astro_knights.GetKnightUseStats(collection)
	if err != nil {
		log.Panic(err)
	}

	return tabKnightsModel{
		matrixTable: createKnightsMatrix(stats.Matrix),
	}
}

M cmd/astro-knights-play-stats/tab_plays.go => cmd/astro-knights-play-stats/tab_plays.go +2 -2
@@ 76,8 76,8 @@ func createPlaysTable(plays []astro_knights.Play) table.Model {
	return createStandardTable(columns, rows)
}

func newTabPlays(plays []astro_knights.Play) tea.Model {
func newTabPlays(collection astro_knights.UserCollection) tea.Model {
	return tabPlaysModel{
		playsTable: createPlaysTable(plays),
		playsTable: createPlaysTable(collection.Plays),
	}
}