TheMathemagicians/sevenkeys/main.go

123 lines
2.6 KiB
Go
Raw Normal View History

2024-05-28 14:29:13 +00:00
package main
import (
2024-06-10 12:32:45 +00:00
"os"
"path/filepath"
"sevenkeys/constants"
"sevenkeys/database"
2024-05-28 14:29:13 +00:00
"sevenkeys/logic"
2024-06-10 12:32:45 +00:00
"sevenkeys/tui"
2024-06-01 21:54:15 +00:00
2024-06-05 12:06:24 +00:00
tea "github.com/charmbracelet/bubbletea"
2024-06-10 12:32:45 +00:00
"github.com/lukesampson/figlet/figletlib"
2024-05-28 14:29:13 +00:00
)
2024-06-10 12:32:45 +00:00
func readFigletFonts() {
cwd, err := os.Getwd()
logic.Check(err)
fontsdir := filepath.Join(cwd, "fonts")
constants.FigletFontSlant, err = figletlib.GetFontByName(fontsdir, "slant")
logic.Check(err)
constants.FigletFontTerm, err = figletlib.GetFontByName(fontsdir, "term")
logic.Check(err)
}
2024-05-28 14:29:13 +00:00
func main() {
2024-06-10 12:32:45 +00:00
constants.Database = database.GetDatabaseFromConfig("config.json")
readFigletFonts()
m := tui.NewMainModel()
constants.Program = tea.NewProgram(m, tea.WithAltScreen())
_, err := constants.Program.Run()
2024-05-28 14:29:13 +00:00
logic.Check(err)
2024-06-05 12:06:24 +00:00
/*
fmt.Println("Checking for updates...")
bulkData, err := scryfall.GetBulkDataByType(scryfall.BulkDataTypeAllCards)
logic.Check(err)
2024-05-29 19:55:38 +00:00
2024-06-05 12:06:24 +00:00
needsUpdate, err := logic.CheckForUpdates(db, bulkData)
logic.Check(err)
2024-05-29 19:55:38 +00:00
2024-06-05 12:06:24 +00:00
if needsUpdate {
fmt.Println("Update required.")
2024-05-29 19:55:38 +00:00
2024-06-05 12:06:24 +00:00
if logic.ConfirmUpdate() {
fmt.Println("Running update...")
2024-05-30 13:32:04 +00:00
2024-06-05 12:06:24 +00:00
logic.CreateCacheDirectories()
2024-06-01 21:18:33 +00:00
2024-06-05 12:06:24 +00:00
err = logic.UpdateSets(db)
logic.Check(err)
2024-06-01 21:18:33 +00:00
2024-06-05 12:06:24 +00:00
err = logic.UpdateCards(db, bulkData)
logic.Check(err)
}
2024-05-30 13:32:04 +00:00
2024-06-05 12:06:24 +00:00
fmt.Println("Update finished.")
} else {
fmt.Println("No update required.")
}
2024-06-05 12:06:24 +00:00
storageBox := logic.GetResponse("Enter storage box label:")
source := logic.GetResponse("Enter source:")
2024-06-05 12:06:24 +00:00
storageLocation := database.CardStorageLocation{
StorageBox: storageBox,
Source: source,
2024-06-01 21:54:15 +00:00
}
2024-06-05 12:06:24 +00:00
searchOptions, err := logic.GetAllSearchOptions(db)
logic.Check(err)
2024-06-01 21:18:33 +00:00
2024-06-05 12:06:24 +00:00
var selectedCardId string
var selectedCardSearchOption string = "None"
var lastOutput string
for {
screen.Clear()
screen.MoveTopLeft()
2024-06-01 21:18:33 +00:00
2024-06-05 12:06:24 +00:00
fmt.Println("Storage location:", storageBox, "|", "Source:", source)
fmt.Println("Selected card:", selectedCardSearchOption, "ID:", selectedCardId)
if lastOutput != "" {
fmt.Println(lastOutput)
2024-06-01 21:18:33 +00:00
}
2024-06-05 12:06:24 +00:00
var action string
action = logic.GetResponse("[s]earch for card/[i]nsert selected card/[q]uit:")
switch action {
case "s":
selectedCardId, selectedCardSearchOption, err = logic.Search(searchOptions)
logic.Check(err)
2024-06-01 21:18:33 +00:00
2024-06-05 12:06:24 +00:00
storageLocation.CardPrintingId = selectedCardId
lastOutput = ""
2024-06-01 21:54:15 +00:00
2024-06-05 12:06:24 +00:00
continue
case "i":
if selectedCardId == "" {
lastOutput = "No selected card, please search for one."
continue
}
err = logic.StoreCard(db, storageLocation)
logic.Check(err)
lastOutput = "Inserted card: " + selectedCardSearchOption
break
case "q":
os.Exit(0)
default:
lastOutput = "Not a valid command: " + action
break
}
}
2024-06-05 12:06:24 +00:00
*/
2024-05-28 14:29:13 +00:00
}