MCPcopy
hub / github.com/EngoEngine/engo / TestTMXLevelIsometric

Function TestTMXLevelIsometric

common/tmx_test.go:668–723  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

666}
667
668func TestTMXLevelIsometric(t *testing.T) {
669 // Create an image in memory
670 imgbuf := bytes.NewBuffer([]byte{})
671 img := image.NewRGBA(image.Rect(0, 0, 457, 305))
672 err := png.Encode(imgbuf, img)
673 if err != nil {
674 t.Errorf("Unable to encode png from image")
675 }
676
677 // Load the image
678 err = engo.Files.LoadReaderData("test.png", imgbuf)
679 if err != nil {
680 t.Errorf("Unable to load test png. Error was: %v", err)
681 }
682
683 // Load the template
684 buf := bytes.NewBuffer([]byte{})
685 tmpl, err := template.New("test").Parse(testTMXtmpl)
686 if err != nil {
687 t.Error("Error parsing tmx template")
688 }
689 err = tmpl.Execute(buf, tmxData{
690 Orientation: "isometric",
691 RenderOrder: "right-down",
692 })
693 if err != nil {
694 t.Error("Error executing tmx template")
695 }
696
697 // Load tmx
698 err = engo.Files.LoadReaderData("test.tmx", buf)
699 if err != nil {
700 t.Errorf("Unable to load tmx file for testing. Error was: %v", err)
701 }
702
703 resource, err := engo.Files.Resource("test.tmx")
704 if err != nil {
705 t.Errorf("Unable to retrieve resource. Error was: %v", err)
706 }
707 tmxResource := resource.(TMXResource)
708
709 bounds := tmxResource.Level.Bounds()
710 exp := engo.AABB{
711 Min: engo.Point{X: -16, Y: 0},
712 Max: engo.Point{X: 32, Y: 56},
713 }
714 if bounds.Min.X != exp.Min.X || bounds.Min.Y != exp.Min.Y || bounds.Max.X != exp.Max.X || bounds.Max.Y != exp.Max.Y {
715 t.Errorf("Bounds was not returned correctly\nWanted: %v\nGot: %v", exp, bounds)
716 }
717
718 tile := tmxResource.Level.GetTile(engo.Point{X: 20, Y: 20})
719 expTile := engo.Point{X: 16, Y: 16}
720 if tile.Point.X != expTile.X || tile.Point.Y != expTile.Y {
721 t.Errorf("Tile was not returned correctly\nWanted: %v\nGot: %v", expTile, tile.Point)
722 }
723}

Callers

nothing calls this directly

Calls 6

LoadReaderDataMethod · 0.80
BoundsMethod · 0.80
GetTileMethod · 0.80
ResourceMethod · 0.65
NewMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected