fix(misc): hold wheel beta result

This commit is contained in:
2026-07-06 12:31:37 +07:00
parent 9dc99d4abc
commit 9b728aa41e
2 changed files with 34 additions and 12 deletions
+25 -7
View File
@@ -252,11 +252,12 @@ func TestWheelOfNamesBeta_RenderGIFTiming(t *testing.T) {
if err != nil {
t.Fatalf("DecodeAll: %v", err)
}
if len(decoded.Image) != wheelBetaSpinFrames+1 {
t.Fatalf("frames = %d, want %d", len(decoded.Image), wheelBetaSpinFrames+1)
if len(decoded.Image) != wheelBetaSpinFrames+wheelBetaHoldFrames {
t.Fatalf("frames = %d, want %d", len(decoded.Image), wheelBetaSpinFrames+wheelBetaHoldFrames)
}
totalDelay := 0
spinDelay := 0
holdDelay := 0
for i, delay := range decoded.Delay {
totalDelay += delay
if i < wheelBetaSpinFrames && delay != wheelBetaSpinDelay {
@@ -264,25 +265,42 @@ func TestWheelOfNamesBeta_RenderGIFTiming(t *testing.T) {
}
if i < wheelBetaSpinFrames {
spinDelay += delay
continue
}
if delay != wheelBetaHoldDelay {
t.Fatalf("hold delay[%d] = %d, want %d", i, delay, wheelBetaHoldDelay)
}
holdDelay += delay
}
if spinDelay != wheelBetaSpinDuration*100 {
t.Fatalf("spin delay total = %dcs, want %dcs", spinDelay, wheelBetaSpinDuration*100)
}
if got := decoded.Delay[len(decoded.Delay)-1]; got != wheelBetaHoldDelay {
t.Fatalf("hold delay = %d, want %d", got, wheelBetaHoldDelay)
}
if got := decoded.Delay[len(decoded.Delay)-1]; got != wheelBetaHoldDuration*100 {
t.Fatalf("hold delay total = %dcs, want %dcs", got, wheelBetaHoldDuration*100)
if holdDelay != wheelBetaHoldDuration*100 {
t.Fatalf("hold delay total = %dcs, want %dcs", holdDelay, wheelBetaHoldDuration*100)
}
if totalDelay != wheelBetaDuration*100 {
t.Fatalf("total delay = %dcs, want %dcs", totalDelay, wheelBetaDuration*100)
}
if equalPalettedFrames(decoded.Image[wheelBetaSpinFrames-1], decoded.Image[wheelBetaSpinFrames]) {
t.Fatalf("first result frame matches last spin frame, want visible RESULT transition")
}
for i := wheelBetaSpinFrames + 1; i < len(decoded.Image); i++ {
if !equalPalettedFrames(decoded.Image[wheelBetaSpinFrames], decoded.Image[i]) {
t.Fatalf("result hold frame %d differs from first result frame", i)
}
}
if decoded.LoopCount != -1 {
t.Fatalf("loop count = %d, want -1", decoded.LoopCount)
}
}
func equalPalettedFrames(a, b *image.Paletted) bool {
if !a.Rect.Eq(b.Rect) || a.Stride != b.Stride {
return false
}
return bytes.Equal(a.Pix, b.Pix)
}
func TestWheelOfNamesBeta_CurrentOptionTracksPointer(t *testing.T) {
for winner := range []string{"Alice", "Bob", "Carol", "Dana"} {
rotation := finalWheelRotation(4, winner)
+9 -5
View File
@@ -17,7 +17,8 @@ const (
wheelBetaHoldDuration = 3
wheelBetaSpinDelay = 20
wheelBetaSpinFrames = wheelBetaSpinDuration * 100 / wheelBetaSpinDelay
wheelBetaHoldDelay = wheelBetaHoldDuration * 100
wheelBetaHoldFrames = wheelBetaHoldDuration * 100 / wheelBetaSpinDelay
wheelBetaHoldDelay = wheelBetaSpinDelay
wheelBetaDuration = wheelBetaSpinDuration + wheelBetaHoldDuration
)
@@ -44,8 +45,8 @@ func renderWheelOfNamesBetaGIF(options []string, winner int) ([]byte, error) {
return nil, fmt.Errorf("winner index %d out of range %d", winner, len(options))
}
frames := make([]*image.Paletted, 0, wheelBetaSpinFrames+1)
delays := make([]int, 0, wheelBetaSpinFrames+1)
frames := make([]*image.Paletted, 0, wheelBetaSpinFrames+wheelBetaHoldFrames)
delays := make([]int, 0, wheelBetaSpinFrames+wheelBetaHoldFrames)
finalRotation := finalWheelRotation(len(options), winner)
startRotation := finalRotation - 8*2*math.Pi
for i := 0; i < wheelBetaSpinFrames; i++ {
@@ -56,8 +57,11 @@ func renderWheelOfNamesBetaGIF(options []string, winner int) ([]byte, error) {
frames = append(frames, renderWheelBetaFrame(options, winner, rotation, false))
delays = append(delays, wheelBetaSpinDelay)
}
frames = append(frames, renderWheelBetaFrame(options, winner, finalRotation, true))
delays = append(delays, wheelBetaHoldDelay)
resultFrame := renderWheelBetaFrame(options, winner, finalRotation, true)
for i := 0; i < wheelBetaHoldFrames; i++ {
frames = append(frames, resultFrame)
delays = append(delays, wheelBetaHoldDelay)
}
var buf bytes.Buffer
err := gif.EncodeAll(&buf, &gif.GIF{