Add shop components 436-450; Odometer exact at 15 fps
Fifteen shop components: PriceTag, Wallet, ShopItem, Cart, Receipt, Checkout, CurrencyConvert, SaleBadge, Quantity, PricingTiers, Coupon, DailyReward, BidTicker, TradeWindow and VendingMachine. Receipt prints dot by dot with feed holes and a torn edge; Coupon cuts real notches; SaleBadge is a sixteen-point starburst; VendingMachine sells A1 to D4 by code and drops the snack into its tray. Sums are checked against overflow, TradeWindow withdraws both confirms on any change to an offer, and a disabled Checkout veils its inert content. text.Odometer now counts digits as text, steps at 15 fps as S5 asks, draws exact digits at rest and lands rolls that floats would stall.
This commit is contained in:
28 files changed
+2420
-9
No files matched your search
@@ -0,0 +1,125 @@
|
||||
package gallery
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/data"
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/icon"
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/shop"
|
||||
)
|
||||
|
||||
var marketEntries = []Entry{
|
||||
{444, "Quantity", "数量", "shop", "- and + within limits. The side at its limit fades.", demoQuantity},
|
||||
{445, "PricingTiers", "价格方案", "shop", "Bronze, silver and gold. Gold comes with a hat.", demoPricingTiers},
|
||||
{446, "Coupon", "优惠券", "shop", "A ticket with notched edges. COPY takes the code.", demoCoupon},
|
||||
{447, "DailyReward", "每日奖励", "shop", "Seven days, seven chests. Come back daily; today's is ready.", demoDailyReward},
|
||||
{448, "BidTicker", "竞价", "shop", "The latest bids on top; the highest wears the crown.", demoBidTicker},
|
||||
{449, "TradeWindow", "交易窗口", "shop", "Two offers. Both must confirm, and any change takes the confirms back.", demoTradeWindow},
|
||||
{450, "VendingMachine", "自动售货机", "shop", "Type a code like B3 and press OK. Credit first, snacks after.", demoVendingMachine},
|
||||
}
|
||||
|
||||
type marketDemo struct {
|
||||
qty, tier, credit int
|
||||
days []bool
|
||||
mine []data.Item
|
||||
trade shop.Trade
|
||||
}
|
||||
|
||||
func marketState(c *ui.Context) *marketDemo {
|
||||
return ui.Local(c.Root(), demoKey("market"), func() marketDemo {
|
||||
return marketDemo{qty: 1, tier: -1, credit: 100, days: []bool{true, false, true, false, false, false, false}, mine: []data.Item{{Sprite: icon.Sword, Name: "Sword"}}}
|
||||
})
|
||||
}
|
||||
|
||||
func demoQuantity(c *ui.Context, log func(string)) {
|
||||
s := marketState(c)
|
||||
if shop.Quantity(c, "Potions", &s.qty, shop.QuantityOptions{Min: 1, Max: 9}).Changed {
|
||||
log(fmt.Sprintf("%d potions", s.qty))
|
||||
}
|
||||
}
|
||||
|
||||
func demoPricingTiers(c *ui.Context, log func(string)) {
|
||||
s := marketState(c)
|
||||
if shop.PricingTiers(c, "Plans", [3]shop.Tier{
|
||||
{Price: 0, Perks: []string{"1 SAVE SLOT", "ADS"}},
|
||||
{Price: 5, Perks: []string{"3 SAVE SLOTS", "NO ADS"}},
|
||||
{Price: 9, Perks: []string{"99 SLOTS", "NO ADS", "A HAT"}},
|
||||
}, &s.tier, shop.PricingTiersOptions{Currency: shop.Gems}).Changed {
|
||||
log([]string{"bronze", "silver", "gold"}[s.tier])
|
||||
}
|
||||
}
|
||||
|
||||
func demoCoupon(c *ui.Context, log func(string)) {
|
||||
if shop.Coupon(c, "10% OFF", "UPUPDOWNDOWN", shop.CouponOptions{}).Copied {
|
||||
log("code copied")
|
||||
}
|
||||
}
|
||||
|
||||
func demoDailyReward(c *ui.Context, log func(string)) {
|
||||
s := marketState(c)
|
||||
if shop.DailyReward(c, "Rewards", 4, s.days, shop.DailyRewardOptions{}).Claimed {
|
||||
log("claimed day 4")
|
||||
}
|
||||
}
|
||||
|
||||
func demoBidTicker(c *ui.Context, log func(string)) {
|
||||
now := pixel.K(c).Now()
|
||||
shop.BidTicker(c, "Bids", []shop.Bid{
|
||||
{Bidder: "Aria", Amount: 120, At: now.Add(-9 * time.Minute)},
|
||||
{Bidder: "Brom", Amount: 150, At: now.Add(-6 * time.Minute)},
|
||||
{Bidder: "Cass", Amount: 140, At: now.Add(-40 * time.Second)},
|
||||
}, shop.BidTickerOptions{})
|
||||
}
|
||||
|
||||
func demoTradeWindow(c *ui.Context, log func(string)) {
|
||||
k := pixel.K(c)
|
||||
s := marketState(c)
|
||||
ui.Column(c).Gap(k.D(6)).Children(func() {
|
||||
r := shop.TradeWindow(c, "Trade", "Brom", s.mine, []data.Item{{Sprite: icon.Gem, Name: "Gem", Count: 3}}, &s.trade, shop.TradeWindowOptions{})
|
||||
if r.Changed {
|
||||
log(fmt.Sprintf("you %v, Brom %v", s.trade.Mine, s.trade.Theirs))
|
||||
}
|
||||
if r.Traded {
|
||||
log("traded")
|
||||
}
|
||||
ui.Row(c).Gap(k.D(6)).Children(func() {
|
||||
if input.Button(c, "BROM CONFIRMS", input.ButtonOptions{Size: input.Small}).Clicked {
|
||||
s.trade.Theirs = true
|
||||
log("Brom confirms")
|
||||
}
|
||||
if input.Button(c, "ADD POTION", input.ButtonOptions{Size: input.Small}).Clicked {
|
||||
s.mine = append(s.mine, data.Item{Sprite: icon.Potion, Name: "Potion"})
|
||||
log("you add a potion")
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// snacks fill the machine: A1 to D4, three of each.
|
||||
var snacks = func() (out [16]shop.Snack) {
|
||||
sprites := []*pixel.Sprite{icon.Potion, icon.Gem, icon.Heart, icon.Star, icon.Coin, icon.Flower, icon.Leaf, icon.Drop, icon.Sun, icon.Moon, icon.Cloud, icon.Snowflake, icon.Bolt, icon.Gift, icon.Book, icon.Key}
|
||||
names := []string{"POTION", "GEM", "HEART", "STAR", "COIN", "FLOWER", "LEAF", "DROP", "SUN", "MOON", "CLOUD", "SNOW", "BOLT", "GIFT", "BOOK", "KEY"}
|
||||
for i := range out {
|
||||
out[i] = shop.Snack{Name: names[i], Sprite: sprites[i], Price: 10 + i%4*10, Stock: 3 - i%5/4*3}
|
||||
}
|
||||
return out
|
||||
}()
|
||||
|
||||
func demoVendingMachine(c *ui.Context, log func(string)) {
|
||||
k := pixel.K(c)
|
||||
s := marketState(c)
|
||||
ui.Column(c).Gap(k.D(6)).Children(func() {
|
||||
if i := shop.VendingMachine(c, "Machine", snacks, &s.credit, shop.VendingMachineOptions{}).Vended; i >= 0 {
|
||||
log(fmt.Sprintf("vended %s, credit %d", snacks[i].Name, s.credit))
|
||||
}
|
||||
if input.Button(c, "INSERT COIN", input.ButtonOptions{Size: input.Small}).Clicked {
|
||||
s.credit += 10
|
||||
log(fmt.Sprintf("credit %d", s.credit))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package gallery
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/icon"
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/shop"
|
||||
)
|
||||
|
||||
var shopEntries = []Entry{
|
||||
{436, "PriceTag", "价签", "shop", "A coin and a number. On sale, the old price gets a line through it.", demoPriceTag},
|
||||
{437, "Wallet", "钱包", "shop", "Gold and gems. Earn some and watch the digits roll.", demoWallet},
|
||||
{438, "ShopItem", "商品卡", "shop", "A ware on the shelf: sprite, name, price, BUY. Short of gold, BUY sits out.", demoShopItem},
|
||||
{439, "Cart", "购物车", "shop", "What you are about to buy, how many, and how much it all costs.", demoCart},
|
||||
{440, "Receipt", "小票", "shop", "Printed dot by dot, holes down the sides, torn at the bottom.", demoReceipt},
|
||||
{441, "Checkout", "结账", "shop", "CART, PAY, CONFIRM, and the shopkeeper says THANK YOU!", demoCheckout},
|
||||
{442, "CurrencyConvert", "兑换", "shop", "A hundred gold buys a gem. Pick how many and CONVERT.", demoCurrencyConvert},
|
||||
{443, "SaleBadge", "促销角标", "shop", "SALE on a starburst, rim flashing, as shops have always shouted.", demoSaleBadge},
|
||||
}
|
||||
|
||||
type shopDemo struct {
|
||||
gold, gems, step int
|
||||
cart []shop.CartLine
|
||||
}
|
||||
|
||||
func shopState(c *ui.Context) *shopDemo {
|
||||
return ui.Local(c.Root(), demoKey("shop"), func() shopDemo {
|
||||
return shopDemo{gold: 950, gems: 3, cart: []shop.CartLine{
|
||||
{Name: "POTION", Price: 30, Qty: 3}, {Name: "ETHER", Price: 45, Qty: 1}, {Name: "PHOENIX FEATHER", Price: 200, Qty: 2},
|
||||
}}
|
||||
})
|
||||
}
|
||||
|
||||
func demoPriceTag(c *ui.Context, log func(string)) {
|
||||
k := pixel.K(c)
|
||||
ui.Column(c).Gap(k.D(6)).Children(func() {
|
||||
shop.PriceTag(c, 120, shop.PriceTagOptions{})
|
||||
shop.PriceTag(c, 75, shop.PriceTagOptions{Was: 150})
|
||||
shop.PriceTag(c, 3, shop.PriceTagOptions{Currency: shop.Gems})
|
||||
})
|
||||
}
|
||||
|
||||
func demoWallet(c *ui.Context, log func(string)) {
|
||||
k := pixel.K(c)
|
||||
s := shopState(c)
|
||||
ui.Column(c).Gap(k.D(6)).Children(func() {
|
||||
shop.Wallet(c, s.gold, s.gems, shop.WalletOptions{Digits: 5})
|
||||
if input.Button(c, "FIND GOLD", input.ButtonOptions{Size: input.Small}).Clicked {
|
||||
s.gold += 137
|
||||
log(fmt.Sprintf("gold %d", s.gold))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func demoShopItem(c *ui.Context, log func(string)) {
|
||||
k := pixel.K(c)
|
||||
s := shopState(c)
|
||||
ui.Row(c).Gap(k.D(6)).Children(func() {
|
||||
for _, w := range []shop.Ware{
|
||||
{Name: "POTION", Sprite: icon.Potion, Price: 30},
|
||||
{Name: "SWORD", Sprite: icon.Sword, Price: 3000},
|
||||
{Name: "SHIELD", Sprite: icon.Shield, Price: 80, Was: 120},
|
||||
} {
|
||||
if shop.ShopItem(c, w, shop.ShopItemOptions{Short: s.gold < w.Price}).Bought {
|
||||
s.gold -= w.Price
|
||||
log(fmt.Sprintf("bought %s, %d gold left", w.Name, s.gold))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func demoCart(c *ui.Context, log func(string)) {
|
||||
s := shopState(c)
|
||||
r := shop.Cart(c, "Cart", s.cart, shop.CartOptions{})
|
||||
if r.Changed {
|
||||
log("quantity changed")
|
||||
}
|
||||
if r.Removed >= 0 {
|
||||
log("removed " + s.cart[r.Removed].Name)
|
||||
s.cart = append(s.cart[:r.Removed:r.Removed], s.cart[r.Removed+1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
func demoReceipt(c *ui.Context, log func(string)) {
|
||||
shop.Receipt(c, "ITEM SHOP", []shop.ReceiptLine{
|
||||
{Name: "POTION", Qty: 3, Price: 30}, {Name: "ETHER", Qty: 1, Price: 45}, {Name: "TENT", Qty: 1, Price: 120},
|
||||
}, shop.ReceiptOptions{Time: time.Date(1997, 1, 31, 18, 42, 0, 0, time.UTC)})
|
||||
}
|
||||
|
||||
func demoCheckout(c *ui.Context, log func(string)) {
|
||||
s := shopState(c)
|
||||
r := shop.Checkout(c, "Checkout", &s.step, shop.CheckoutOptions{}, func() {
|
||||
pixel.Text(c, []string{"3 ITEMS, 375 GOLD", "PAY WITH: GOLD", "DELIVER TO: THE INN"}[s.step], pixel.TextOptions{})
|
||||
})
|
||||
if r.Changed {
|
||||
log(fmt.Sprintf("step %d", s.step+1))
|
||||
}
|
||||
if r.Done {
|
||||
log("order placed")
|
||||
}
|
||||
}
|
||||
|
||||
func demoCurrencyConvert(c *ui.Context, log func(string)) {
|
||||
s := shopState(c)
|
||||
if n := shop.CurrencyConvert(c, "Exchange", &s.gold, &s.gems, shop.CurrencyConvertOptions{}).Converted; n > 0 {
|
||||
log(fmt.Sprintf("bought %d gems, %d gold left", n, s.gold))
|
||||
}
|
||||
}
|
||||
|
||||
func demoSaleBadge(c *ui.Context, log func(string)) {
|
||||
k := pixel.K(c)
|
||||
ui.Row(c).Gap(k.D(8)).Children(func() {
|
||||
shop.SaleBadge(c, 50, shop.SaleBadgeOptions{})
|
||||
shop.SaleBadge(c, 10, shop.SaleBadgeOptions{})
|
||||
})
|
||||
}
|
||||
+1
-1
@@ -56,7 +56,7 @@ var Categories = []Category{
|
||||
{"tabletop", "Tabletop", "桌游", icon.Crown},
|
||||
}
|
||||
|
||||
var entries = slices.Concat(foundationEntries, layoutEntries, textEntries, displayEntries, inputEntries, controlEntries, feedbackEntries, navigationEntries, dataEntries, recordEntries, overlayEntries, popupEntries, datetimeEntries, timeEntries, chartEntries, plotEntries, gameEntries, rpgEntries, screenEntries, lootEntries, fxEntries, screenFxEntries, chatEntries, mailEntries, mediaEntries, studioEntries, codeEntries, debugEntries, accountEntries, playerEntries, filesEntries, storageEntries, projectEntries, teamEntries)
|
||||
var entries = slices.Concat(foundationEntries, layoutEntries, textEntries, displayEntries, inputEntries, controlEntries, feedbackEntries, navigationEntries, dataEntries, recordEntries, overlayEntries, popupEntries, datetimeEntries, timeEntries, chartEntries, plotEntries, gameEntries, rpgEntries, screenEntries, lootEntries, fxEntries, screenFxEntries, chatEntries, mailEntries, mediaEntries, studioEntries, codeEntries, debugEntries, accountEntries, playerEntries, filesEntries, storageEntries, projectEntries, teamEntries, shopEntries, marketEntries)
|
||||
|
||||
func Entries() []Entry { return entries }
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package gallery
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestShopDemosLogTheirActions(t *testing.T) {
|
||||
// Clicks that only focus a component may log nothing.
|
||||
quiet := map[string]bool{"Potions": true, "KEYPAD": true}
|
||||
for _, tc := range []struct {
|
||||
path string
|
||||
steps []string
|
||||
}{
|
||||
{"/c/437-wallet", []string{"FIND GOLD"}}, {"/c/438-shopitem", []string{"BUY POTION"}},
|
||||
{"/c/439-cart", []string{"REMOVE ETHER"}}, {"/c/441-checkout", []string{"NEXT ▶"}},
|
||||
{"/c/442-currencyconvert", []string{"CONVERT"}}, {"/c/444-quantity", []string{"Potions", "key:Right"}},
|
||||
{"/c/445-pricingtiers", []string{"SILVER, 5 GEMS"}}, {"/c/446-coupon", []string{"COPY"}},
|
||||
{"/c/447-dailyreward", []string{"CLAIM"}}, {"/c/449-tradewindow", []string{"CONFIRM", "BROM CONFIRMS"}},
|
||||
{"/c/450-vendingmachine", []string{"INSERT COIN"}},
|
||||
} {
|
||||
a, tt := open(tc.path)
|
||||
slug := tc.path[3:]
|
||||
for _, step := range tc.steps {
|
||||
before := len(a.logs[slug])
|
||||
if k, ok := strings.CutPrefix(step, "key:"); ok {
|
||||
tt.Key(0, letters[k])
|
||||
} else {
|
||||
click(t, tt, step)
|
||||
}
|
||||
if len(a.logs[slug]) <= before && !quiet[step] {
|
||||
t.Errorf("%s: %s logged nothing: %q", slug, step, a.logs[slug])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user