TheMathemagicians/sevenkeys/logic/locate.go

80 lines
1.7 KiB
Go
Raw Normal View History

package logic
import (
"database/sql"
2024-09-07 23:24:24 +00:00
"fmt"
"sevenkeys/database"
)
2024-09-07 23:24:24 +00:00
const SLOTS_PER_BINDER_PAGE = 18 // TODO: Make this configurable
func GetBinderLocationDescription(position int) string {
var page int = (position / SLOTS_PER_BINDER_PAGE) + 1
var pagePosition int = position % SLOTS_PER_BINDER_PAGE
var slot int
var frontOrBack string
if pagePosition <= (SLOTS_PER_BINDER_PAGE / 2) {
slot = pagePosition
frontOrBack = "front"
} else {
slot = pagePosition - (SLOTS_PER_BINDER_PAGE / 2)
frontOrBack = "back"
}
return fmt.Sprintf(" on page %d in %s slot %d", page, frontOrBack, slot)
}
func LocateCards(db *sql.DB, cardNames []string, criteria SearchCriteria) ([]string, error) {
var locations []string
results, err := database.GetLocateResults(db, cardNames)
if err != nil {
return locations, err
}
var location string
for _, result := range results {
2024-09-12 12:31:42 +00:00
printing := database.CardPrinting{
SetCode: result.SetCode,
IsFoil: result.IsFoil,
IsPromo: result.IsPromo,
Language: result.Language,
}
filter := filterPrinting(printing, criteria)
if filter {
continue
}
2024-09-07 23:24:24 +00:00
location = fmt.Sprintf("%s (%s %s) [%s]",
result.CardName,
result.SetCode,
result.CollectorNumber,
result.Language)
if result.IsFoil {
location += " FOIL"
}
if result.IsPromo {
location += " PROMO"
}
location += fmt.Sprintf(" in %s \"%s\"",
result.StorageAreaType,
result.StorageAreaName)
if result.StorageAreaType == "Binder" {
location += GetBinderLocationDescription(result.Position)
} else if result.StorageAreaType == "Box" {
location += fmt.Sprintf(" at position %d", result.Position)
}
locations = append(locations, location)
}
return locations, nil
}