Преглед на файлове

epic: require discountPercentage==100 for free; deals show percent-only when discountPrice absent

Paul Klumpp преди 3 дни
родител
ревизия
cd1ac9ffcf
променени са 3 файла, в които са добавени 20 реда и са изтрити 7 реда
  1. 5 2
      cmd/cheapo/chatto.go
  2. 5 1
      cmd/cheapo/main.go
  3. 10 4
      internal/epic/client.go

+ 5 - 2
cmd/cheapo/chatto.go

@@ -84,8 +84,11 @@ func formatGames(games []game.Game, mode string) string {
 // with percent for deals.
 func priceCell(g game.Game) string {
 	switch {
-	case g.DiscountPct > 0 && g.FinalPriceFmt != "":
-		return fmt.Sprintf("%s → **%s** (−%d %%)", g.PriceFmt, g.FinalPriceFmt, g.DiscountPct)
+	case g.DiscountPct > 0:
+		if g.FinalPriceFmt != "" {
+			return fmt.Sprintf("%s → **%s** (−%d %%)", g.PriceFmt, g.FinalPriceFmt, g.DiscountPct)
+		}
+		return fmt.Sprintf("%s (−%d %%)", g.PriceFmt, g.DiscountPct)
 	case g.Kind == "free-now" || g.Kind == "free-to-keep":
 		return "**0 €**"
 	case g.PriceFmt != "":

+ 5 - 1
cmd/cheapo/main.go

@@ -121,7 +121,11 @@ func printGames(cmd *cobra.Command, games []game.Game) error {
 			fmt.Fprintf(out, "   By: %s\n", g.Seller)
 		}
 		if g.DiscountPct > 0 {
-			fmt.Fprintf(out, "   Price: %s → %s (−%d %%)\n", g.PriceFmt, g.FinalPriceFmt, g.DiscountPct)
+			if g.FinalPriceFmt != "" {
+				fmt.Fprintf(out, "   Price: %s → %s (−%d %%)\n", g.PriceFmt, g.FinalPriceFmt, g.DiscountPct)
+			} else {
+				fmt.Fprintf(out, "   Price: %s (−%d %%)\n", g.PriceFmt, g.DiscountPct)
+			}
 		} else if g.PriceFmt != "" && g.Store != "steam" && g.PriceFmt != "0" {
 			fmt.Fprintf(out, "   Instead of: %s\n", g.PriceFmt)
 		}

+ 10 - 4
internal/epic/client.go

@@ -153,7 +153,10 @@ func buildGames(el element, kind string, windows []offer, keep func(offer) bool,
 		if !keep(o) {
 			continue
 		}
-		if freeOnly && o.Discount.DiscountPrice != 0 {
+		if freeOnly && (o.Discount.DiscountPrice != 0 || o.Discount.DiscountPercentage != 100) {
+			// DiscountPrice alone is not enough: some offers omit the price
+			// field (null → 0) while discountPercentage reveals them as
+			// partial discounts (e.g. Castlevania, Oct 2026).
 			continue
 		}
 		g := game.Game{
@@ -171,9 +174,12 @@ func buildGames(el element, kind string, windows []offer, keep func(offer) bool,
 		}
 		if o.Discount.DiscountPercentage > 0 && o.Discount.DiscountPercentage < 100 {
 			g.DiscountPct = o.Discount.DiscountPercentage
-			// The API's fmtPrice shows the *original* price; compute the
-			// discounted price display from the discount price (cents).
-			g.FinalPriceFmt = fmt.Sprintf("%d.%02d €", o.Discount.DiscountPrice/100, o.Discount.DiscountPrice%100)
+			// discountPercentage here is the *discount* (e.g. 40 = −40 %),
+			// not the remaining share. discountPrice (cents) may be absent
+			// (null → 0) on such offers; then show percent only.
+			if o.Discount.DiscountPrice > 0 {
+				g.FinalPriceFmt = fmt.Sprintf("%d.%02d €", o.Discount.DiscountPrice/100, o.Discount.DiscountPrice%100)
+			}
 		}
 		if i := indexOfID(games, g.ID); i >= 0 {
 			if g.EndDate.After(games[i].EndDate) {