Skip to content

Commit

Permalink
cardtrader/sealed: Decouple merged SLD products for foil/nonfoil vari…
Browse files Browse the repository at this point in the history
…ants
  • Loading branch information
kodawah committed Oct 9, 2023
1 parent aa074a1 commit eb347a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions cardtrader/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ func preprocessSealed(edition, productName string) (string, error) {
uuid = product.UUID
}
case strings.Contains(productName, "Deck"),
strings.Contains(productName, "Secret Lair"),
strings.Contains(productName, "Intro Pack"):
decks, found := product.Contents["deck"]
if found {
Expand Down
25 changes: 22 additions & 3 deletions cardtrader/sealed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cardtrader
import (
"fmt"
"io"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -51,8 +52,10 @@ func (ct *CardtraderSealed) printf(format string, a ...interface{}) {
}
}

func processSealedProducts(channel chan<- resultChan, uuid string, products []Product, shareCode string, rate float64) error {
func (ct *CardtraderSealed) processSealedProducts(channel chan<- resultChan, uuid string, products []Product, shareCode string, rate float64) error {
for _, product := range products {
productId := uuid

if product.Properties.Language != "en" {
continue
}
Expand All @@ -68,6 +71,22 @@ func processSealedProducts(channel chan<- resultChan, uuid string, products []Pr
continue
}

if product.Properties.Foil {
blueprint, found := ct.blueprints[product.BlueprintId]
if !found {
continue
}

if strings.Contains(blueprint.Name, "Secret Lair") {
var err error
productId, err = preprocessSealed("SLD", blueprint.Name+" Foil Edition")
if err != nil {
ct.printf("No association for '%s'", blueprint.Name)
continue
}
}
}

qty := product.Quantity
if product.Bundle {
qty *= 4
Expand All @@ -84,7 +103,7 @@ func processSealedProducts(channel chan<- resultChan, uuid string, products []Pr
}

channel <- resultChan{
cardId: uuid,
cardId: productId,
invEntry: &mtgban.InventoryEntry{
Conditions: "NM",
Price: price,
Expand Down Expand Up @@ -131,7 +150,7 @@ func (ct *CardtraderSealed) processEntry(channel chan<- resultChan, expansionId
continue
}

processSealedProducts(channel, uuid, products, ct.ShareCode, ct.exchangeRate)
ct.processSealedProducts(channel, uuid, products, ct.ShareCode, ct.exchangeRate)
}

return nil
Expand Down

0 comments on commit eb347a5

Please sign in to comment.