@@ -409,12 +409,7 @@ func testSpr(t *testing.T, spr func(spriteNo int, x int, y int)) {
409
409
}
410
410
for name , test := range tests {
411
411
t .Run (name , func (t * testing.T ) {
412
- pi .ScreenWidth = 8
413
- pi .ScreenHeight = 8
414
- pi .Resources = fstest.MapFS {
415
- "sprite-sheet.png" : & fstest.MapFile {Data : spriteSheet16x16 },
416
- }
417
- pi .BootOrPanic ()
412
+ boot (8 , 8 , spriteSheet16x16 )
418
413
expectedScreen := decodePNG (t , "internal/testimage/" + test .expectedScreenFile )
419
414
// when
420
415
pi .Camera (test .cameraX , test .cameraY )
@@ -439,12 +434,7 @@ func testSpr(t *testing.T, spr func(spriteNo int, x int, y int)) {
439
434
}
440
435
for name , test := range tests {
441
436
t .Run (name , func (t * testing.T ) {
442
- pi .ScreenWidth = 8
443
- pi .ScreenHeight = 8
444
- pi .Resources = fstest.MapFS {
445
- "sprite-sheet.png" : & fstest.MapFile {Data : spriteSheet16x16 },
446
- }
447
- pi .BootOrPanic ()
437
+ boot (8 , 8 , spriteSheet16x16 )
448
438
expectedScreen := decodePNG (t , "internal/testimage/" + test .expectedScreenFile )
449
439
// when
450
440
pi .Clip (test .clipX , test .clipY , test .clipW , test .clipH )
@@ -456,13 +446,7 @@ func testSpr(t *testing.T, spr func(spriteNo int, x int, y int)) {
456
446
})
457
447
458
448
t .Run ("should not draw color 0 by default" , func (t * testing.T ) {
459
- pi .Reset ()
460
- pi .ScreenWidth = 8
461
- pi .ScreenHeight = 8
462
- pi .Resources = fstest.MapFS {
463
- "sprite-sheet.png" : & fstest.MapFile {Data : spriteSheet16x16 },
464
- }
465
- pi .BootOrPanic ()
449
+ boot (8 , 8 , spriteSheet16x16 )
466
450
spr (2 , 0 , 0 )
467
451
// when
468
452
spr (1 , 0 , 0 )
@@ -472,13 +456,7 @@ func testSpr(t *testing.T, spr func(spriteNo int, x int, y int)) {
472
456
})
473
457
474
458
t .Run ("should not draw color 0 after PaltReset" , func (t * testing.T ) {
475
- pi .Reset ()
476
- pi .ScreenWidth = 8
477
- pi .ScreenHeight = 8
478
- pi .Resources = fstest.MapFS {
479
- "sprite-sheet.png" : & fstest.MapFile {Data : spriteSheet16x16 },
480
- }
481
- pi .BootOrPanic ()
459
+ boot (8 , 8 , spriteSheet16x16 )
482
460
spr (2 , 0 , 0 )
483
461
pi .Palt (0 , false ) // make color 0 opaque
484
462
// when
@@ -490,13 +468,7 @@ func testSpr(t *testing.T, spr func(spriteNo int, x int, y int)) {
490
468
})
491
469
492
470
t .Run ("should not draw transparent colors" , func (t * testing.T ) {
493
- pi .Reset ()
494
- pi .ScreenWidth = 8
495
- pi .ScreenHeight = 8
496
- pi .Resources = fstest.MapFS {
497
- "sprite-sheet.png" : & fstest.MapFile {Data : spriteSheet16x16 },
498
- }
499
- pi .BootOrPanic ()
471
+ boot (8 , 8 , spriteSheet16x16 )
500
472
spr (2 , 0 , 0 )
501
473
// when
502
474
pi .Palt (0 , false )
@@ -568,12 +540,7 @@ func testSprSize(t *testing.T, sprSize func(spriteNo int, x, y int, w, h float64
568
540
}
569
541
for name , test := range tests {
570
542
t .Run (name , func (t * testing.T ) {
571
- pi .ScreenWidth = 16
572
- pi .ScreenHeight = 16
573
- pi .Resources = fstest.MapFS {
574
- "sprite-sheet.png" : & fstest.MapFile {Data : spriteSheet16x16 },
575
- }
576
- pi .BootOrPanic ()
543
+ boot (16 , 16 , spriteSheet16x16 )
577
544
expectedScreen := decodePNG (t , "internal/testimage/" + test .expectedScreenFile )
578
545
// when
579
546
sprSize (test .spriteNo , test .x , test .y , test .w , test .h )
@@ -603,12 +570,7 @@ func TestSprSizeFlip(t *testing.T) {
603
570
}
604
571
for name , test := range tests {
605
572
t .Run (name , func (t * testing.T ) {
606
- pi .ScreenWidth = 8
607
- pi .ScreenHeight = 8
608
- pi .Resources = fstest.MapFS {
609
- "sprite-sheet.png" : & fstest.MapFile {Data : spriteSheet16x16 },
610
- }
611
- pi .BootOrPanic ()
573
+ boot (8 , 8 , spriteSheet16x16 )
612
574
expectedScreen := decodePNG (t , "internal/testimage/" + test .expectedScreenFile )
613
575
// when
614
576
pi .SprSizeFlip (0 , 0 , 0 , 1.0 , test .h , test .flipX , test .flipY )
@@ -619,13 +581,7 @@ func TestSprSizeFlip(t *testing.T) {
619
581
})
620
582
621
583
t .Run ("should not draw transparent colors" , func (t * testing.T ) {
622
- pi .Reset ()
623
- pi .ScreenWidth = 8
624
- pi .ScreenHeight = 8
625
- pi .Resources = fstest.MapFS {
626
- "sprite-sheet.png" : & fstest.MapFile {Data : spriteSheet16x16 },
627
- }
628
- pi .BootOrPanic ()
584
+ boot (8 , 8 , spriteSheet16x16 )
629
585
pi .SprSizeFlip (2 , 0 , 0 , 1.0 , 1.0 , true , false )
630
586
// when
631
587
pi .Palt (0 , false )
@@ -654,3 +610,13 @@ func decodePNG(t *testing.T, file string) image.Image {
654
610
require .NoError (t , err )
655
611
return data
656
612
}
613
+
614
+ func boot (screenWidth , screenHeight int , spriteSheet []byte ) {
615
+ pi .Reset ()
616
+ pi .ScreenWidth = screenWidth
617
+ pi .ScreenHeight = screenHeight
618
+ pi .Resources = fstest.MapFS {
619
+ "sprite-sheet.png" : & fstest.MapFile {Data : spriteSheet },
620
+ }
621
+ pi .BootOrPanic ()
622
+ }
0 commit comments