mtgc

package module
v0.0.0-...-bdfc954 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2021 License: GPL-3.0 Imports: 10 Imported by: 0

README

MTGC

Storing all Magic: The Gathering cards information on your machine with a Go API to access their data and cached images. I've created this project because I developed multiple applications using the same information but each project with it's own code and database. MTGC makes it possible to store all cards and images once on your machine and then access them in multiple apps.

Usage

On first installation you have to do following (assuming that $GOBIN is in your $PATH)

export MTGC_DB="/my/storage/mtgc/mtgc.db"
export MTGC_RES="/my/storage/mtgc/res"

go install github.com/mbndr/mtgc
mtgc # use -update to force reimport

Then you can use the library as shown in example/main.go.

Fields

These structs hold the fields of a card

type Card struct {
	ScryfallId    string
	OracleId      string
	Name          string
	ImageUri      string
	ManaCost      string // {2}{B}{W}
	Cmc           float64
	TypeLine      string
	OracleText    string
	Colors        []string
	ColorIdentity []string
	Rarity        string
	SetCode       string
	SetName       string
	Lang          string
	Artist        string
	// When a card has multiple faces
	CardFaces []*CardFace
}

type CardFace struct {
	Colors     []string
	ImageUri   string
	ManaCost   string
	Name       string
	TypeLine   string
	OracleText string
	Artist     string
}

Documentation

Index

Constants

View Source
const (
	FieldScryfallId    = "scryfall_id"
	FieldOracleId      = "oracle_id"
	FieldName          = "name"
	FieldImageUri      = "image_uri"
	FieldManaCost      = "mana_cost"
	FieldCmc           = "cmc"
	FieldTypeLine      = "type_line"
	FieldOracleText    = "oracle_text"
	FieldColors        = "colors"
	FieldColorIdentity = "color_identity"
	FieldRarity        = "rarity"
	FieldSetCode       = "set_code"
	FieldSetName       = "set_name"
	FieldLang          = "lang"
	FieldArtist        = "artist"
	FieldReleasedAt    = "released_at"

	TableCards     = "cards"
	TableCardFaces = "card_faces"
)

Variables

Fields for a SELECT statement used for unmarshalling into Card struct

Functions

func CardColorArr2Str

func CardColorArr2Str(colors []string) string

func CardColorStr2Arr

func CardColorStr2Arr(s string) []string

helper to convert colors of db into an array

Types

type Card

type Card struct {
	ScryfallId    string   `json:"scryfall_id"`
	OracleId      string   `json:"oracle_id"`
	Name          string   `json:"name"`
	ImageUri      string   `json:"image_uri"`
	ManaCost      string   `json:"mana_cost"` // {2}{B}{W}
	Cmc           float64  `json:"cmc"`
	TypeLine      string   `json:"type_line"`
	OracleText    string   `json:"oracle_text"`
	Colors        []string `json:"colors"`
	ColorIdentity []string `json:"color_identity"`
	Rarity        string   `json:"rarity"`
	SetCode       string   `json:"set_code"`
	SetName       string   `json:"set_name"`
	Lang          string   `json:"lang"`
	Artist        string   `json:"artist"`
	ReleasedAt    string   `json:"released_at"`
	// When a card has multiple faces
	CardFaces []*CardFace `json:"card_faces"`
}

Card represents a single card

type CardCollection

type CardCollection struct {
	// contains filtered or unexported fields
}

CardCollection is a list of card pointers

func (*CardCollection) Add

func (cc *CardCollection) Add(c *Card)

func (*CardCollection) List

func (cc *CardCollection) List() []*Card

func (*CardCollection) Size

func (cc *CardCollection) Size() int

type CardDb

type CardDb struct {
	// contains filtered or unexported fields
}

func NewCardDb

func NewCardDb(path string, resPath string) (*CardDb, error)

NewCardDb opens the sqlite3 file and updates the flag if fields are already filled.

func (*CardDb) CardCount

func (cdb *CardDb) CardCount() (int64, error)

CardCount returns the count of all cards in database

func (*CardDb) CreateQuery

func (cdb *CardDb) CreateQuery(opt QueryOptions) *CardQuery

CreateQuery creates a database query with options.

func (*CardDb) Image

func (cdb *CardDb) Image(c *Card) ([]byte, error)

Image returns the first image for a card. Downloads it when not in resources. For multiface cards return first image.

func (*CardDb) Import

func (cdb *CardDb) Import(i Importer) error

Import creates a transaction in which all reimport happens. 1. Drop tables and reinit them 2. Call importer (e.g. ScryfallImporter) 3. Commit transaction or rollback in case of an error

func (*CardDb) IsFilled

func (cdb *CardDb) IsFilled() bool

IsFilled returns if database is already imported / filled.

type CardFace

type CardFace struct {
	Colors     []string `json:"colors"`
	ImageUri   string   `json:"image_uri"`
	ManaCost   string   `json:"mana_cost"`
	Name       string   `json:"name"`
	TypeLine   string   `json:"type_line"`
	OracleText string   `json:"oracle_text"`
	Artist     string   `json:"artist"`
}

CardFace represents a face of a multiface card

type CardQuery

type CardQuery struct {
	// contains filtered or unexported fields
}

CardQuery holds some query attributes for a simpler card query

func (*CardQuery) Exec

func (q *CardQuery) Exec(args ...interface{}) (*CardCollection, error)

Exec builds the SQL query and executes it with args. Attributes of CardQuery should not contain user input values. These should be done with "?" and args.

func (*CardQuery) ExecSingle

func (q *CardQuery) ExecSingle(args ...interface{}) (*Card, error)

ExecSingle executes the query and returns only the first card

type Importer

type Importer interface {
	Import(*sql.Tx) error
}

type QueryOptions

type QueryOptions struct {
	OrderBy         string
	GroupByOracleId bool
	Where           string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL