From 845204320bed4f40c47c0a28496fd1a2cbb7c400 Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 12 Jun 2024 23:37:13 +0100 Subject: [PATCH] Show the number of times the selected card was inserted --- sevenkeys/cli/mainui.go | 27 ++++++++++-- sevenkeys/cli/search.go | 71 ++++++++++++++++++++++++++++++ sevenkeys/cli/stashui.go | 94 ---------------------------------------- sevenkeys/cli/storage.go | 63 +++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 98 deletions(-) create mode 100644 sevenkeys/cli/search.go delete mode 100644 sevenkeys/cli/stashui.go create mode 100644 sevenkeys/cli/storage.go diff --git a/sevenkeys/cli/mainui.go b/sevenkeys/cli/mainui.go index c51a887..820193f 100644 --- a/sevenkeys/cli/mainui.go +++ b/sevenkeys/cli/mainui.go @@ -8,12 +8,23 @@ import ( "sevenkeys/logic" ) +var output string + +func showOutput() { + if output != "" { + fmt.Println(output) + } +} + func MainCliLoop(db *sql.DB) { var command string for { ShowSplashScreen() - ShowStorageInfo() + showStorageInfo() + showSearchCriteria() + showSelectedCard() + showCopiesInserted() command = GetStringResponse("SEVENKEYS $") @@ -21,23 +32,31 @@ func MainCliLoop(db *sql.DB) { case "quit": return case "storage": - GetStorageOptions() + getStorageOptions() break case "criteria": getSearchCriteria() break case "search": getSearchOptions(db) + + var previousCardPrintingId = cardStorageLocation.CardPrintingId + var err error - selectedCardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions) + cardStorageLocation.CardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions) var exitError *exec.ExitError if errors.As(err, &exitError) { break } logic.Check(err) + + output = "" + if cardStorageLocation.CardPrintingId != previousCardPrintingId { + copiesInserted = 0 + } break case "insert": - InsertSelectedCard(db) + insertSelectedCard(db) break default: fmt.Println("Unrecognized command:", command) diff --git a/sevenkeys/cli/search.go b/sevenkeys/cli/search.go new file mode 100644 index 0000000..d972712 --- /dev/null +++ b/sevenkeys/cli/search.go @@ -0,0 +1,71 @@ +package cli + +import ( + "database/sql" + "fmt" + "sevenkeys/logic" +) + +var ( + searchCriteria logic.SearchCriteria = logic.SearchCriteria{ + SetCode: "", + Foil: logic.Either, + Promo: logic.Either, + Language: "", + } + shouldRefreshSearch bool = true + searchOptions logic.SearchOptions +) + +func getSearchCriteria() { + searchCriteria.SetCode = GetStringResponse("Set code:") + searchCriteria.Foil = GetTriadicResponse("Foil (y/n/E):") + searchCriteria.Promo = GetTriadicResponse("Promo (y/n/E):") + searchCriteria.Language = GetStringResponse("Language:") + shouldRefreshSearch = true +} + +func getTriadicDisplay(triadic logic.Triadic) string { + if triadic == logic.True { + return "True" + } + + if triadic == logic.False { + return "False" + } + + return "Either" +} + +func showSearchCriteria() { + fmt.Println("SEARCH CRITERIA") + + setCodeDisplay := getInfoDisplay(searchCriteria.SetCode) + foilDisplay := getTriadicDisplay(searchCriteria.Foil) + promoDisplay := getTriadicDisplay(searchCriteria.Promo) + languageDisplay := getInfoDisplay(searchCriteria.Language) + + fmt.Println("Set code:", setCodeDisplay) + fmt.Println("Foil:", foilDisplay) + fmt.Println("Promo:", promoDisplay) + fmt.Println("Language:", languageDisplay) + + fmt.Print("\n") +} + +func showSelectedCard() { + selectedCardDisplay := getInfoDisplay(selectedCardPrintingSearchLine) + fmt.Println("Selected card:", selectedCardDisplay) +} + +func getSearchOptions(db *sql.DB) { + if shouldRefreshSearch { + fmt.Println("LOADING") + options, err := logic.GetAllSearchOptions(db, searchCriteria) + logic.Check(err) + searchOptions = options + shouldRefreshSearch = false + fmt.Println("READY") + fmt.Println("RUN") + } +} diff --git a/sevenkeys/cli/stashui.go b/sevenkeys/cli/stashui.go deleted file mode 100644 index c9f06f2..0000000 --- a/sevenkeys/cli/stashui.go +++ /dev/null @@ -1,94 +0,0 @@ -package cli - -import ( - "database/sql" - "fmt" - "sevenkeys/database" - "sevenkeys/logic" -) - -var ( - selectedCardPrintingId string - selectedCardPrintingSearchLine string - - storageBoxLabel string - source string - cardCondition string - - searchCriteria logic.SearchCriteria = logic.SearchCriteria{ - SetCode: "", - Foil: logic.Either, - Promo: logic.Either, - Language: "", - } - shouldRefreshSearch bool = true - searchOptions logic.SearchOptions -) - -func getSearchCriteria() { - searchCriteria.SetCode = GetStringResponse("Set code:") - searchCriteria.Foil = GetTriadicResponse("Foil (y/n/E):") - searchCriteria.Promo = GetTriadicResponse("Promo (y/n/E):") - searchCriteria.Language = GetStringResponse("Language:") - shouldRefreshSearch = true -} - -func getSearchOptions(db *sql.DB) { - if shouldRefreshSearch { - fmt.Println("LOADING") - options, err := logic.GetAllSearchOptions(db, searchCriteria) - logic.Check(err) - searchOptions = options - shouldRefreshSearch = false - fmt.Println("READY") - fmt.Println("RUN") - } -} - -func getInfoDisplay(info string) string { - if info == "" { - return "[EMPTY]" - } - - return info -} - -func ShowStorageInfo() { - storageBoxDisplay := getInfoDisplay(storageBoxLabel) - sourceDisplay := getInfoDisplay(source) - conditionDisplay := getInfoDisplay(cardCondition) - - fmt.Println("Storage location:", storageBoxDisplay, "|", "Source:", sourceDisplay, "|", "Condition:", conditionDisplay) - - if selectedCardPrintingId != "" { - fmt.Println("Selected card:", selectedCardPrintingSearchLine) - } -} - -func GetStorageOptions() { - storageBoxLabel = GetStringResponse("Storage box label:") - source = GetStringResponse("Card source:") - cardCondition = GetStringResponse("Card condition:") -} - -func InsertSelectedCard(db *sql.DB) { - if selectedCardPrintingId == "" { - fmt.Println("No card selected, please [search] for a card printing.") - return - } - - if storageBoxLabel == "" || cardCondition == "" { - GetStorageOptions() - } - - storageLocation := database.CardStorageLocation{ - CardPrintingId: selectedCardPrintingId, - StorageBox: storageBoxLabel, - Source: source, - CardCondition: cardCondition, - } - - err := logic.StoreCard(db, storageLocation) - logic.Check(err) - fmt.Println("Inserted card") -} diff --git a/sevenkeys/cli/storage.go b/sevenkeys/cli/storage.go new file mode 100644 index 0000000..2053e2d --- /dev/null +++ b/sevenkeys/cli/storage.go @@ -0,0 +1,63 @@ +package cli + +import ( + "database/sql" + "fmt" + "sevenkeys/database" + "sevenkeys/logic" +) + +var ( + cardStorageLocation database.CardStorageLocation + selectedCardPrintingSearchLine string + + copiesInserted int +) + +func getInfoDisplay(info string) string { + if info == "" { + return "[EMPTY]" + } + + return info +} + +func showStorageInfo() { + fmt.Println("STORAGE SETTINGS") + + storageBoxDisplay := getInfoDisplay(cardStorageLocation.StorageBox) + sourceDisplay := getInfoDisplay(cardStorageLocation.Source) + conditionDisplay := getInfoDisplay(cardStorageLocation.CardCondition) + + fmt.Println("Storage location:", storageBoxDisplay) + fmt.Println("Source:", sourceDisplay) + fmt.Println("Condition:", conditionDisplay) + + fmt.Print("\n") +} + +func showCopiesInserted() { + fmt.Println("Copies inserted:", copiesInserted) +} + +func getStorageOptions() { + cardStorageLocation.StorageBox = GetStringResponse("Storage box label:") + cardStorageLocation.Source = GetStringResponse("Card source:") + cardStorageLocation.CardCondition = GetStringResponse("Card condition:") +} + +func insertSelectedCard(db *sql.DB) { + if cardStorageLocation.CardPrintingId == "" { + output = "No card selected, please [search] for a card printing." + return + } + + if cardStorageLocation.StorageBox == "" || cardStorageLocation.CardCondition == "" { + getStorageOptions() + } + + err := logic.StoreCard(db, cardStorageLocation) + logic.Check(err) + + copiesInserted++ +}