TheMathemagicians/sevenkeys/logic/locate.go

69 lines
1.5 KiB
Go

package logic
import (
"database/sql"
"fmt"
"sevenkeys/database"
)
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
}
// TODO: Filter by search criteria
var location string
for _, result := range results {
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
}