| 593 | } |
| 594 | |
| 595 | func TestTMXLevel(t *testing.T) { |
| 596 | // Create an image in memory |
| 597 | imgbuf := bytes.NewBuffer([]byte{}) |
| 598 | img := image.NewRGBA(image.Rect(0, 0, 457, 305)) |
| 599 | err := png.Encode(imgbuf, img) |
| 600 | if err != nil { |
| 601 | t.Errorf("Unable to encode png from image") |
| 602 | } |
| 603 | |
| 604 | // Load the image |
| 605 | err = engo.Files.LoadReaderData("test.png", imgbuf) |
| 606 | if err != nil { |
| 607 | t.Errorf("Unable to load test png. Error was: %v", err) |
| 608 | } |
| 609 | |
| 610 | // Load the template |
| 611 | buf := bytes.NewBuffer([]byte{}) |
| 612 | tmpl, err := template.New("test").Parse(testTMXtmpl) |
| 613 | if err != nil { |
| 614 | t.Error("Error parsing tmx template") |
| 615 | } |
| 616 | err = tmpl.Execute(buf, tmxData{ |
| 617 | Orientation: "orthogonal", |
| 618 | RenderOrder: "right-down", |
| 619 | }) |
| 620 | if err != nil { |
| 621 | t.Error("Error executing tmx template") |
| 622 | } |
| 623 | |
| 624 | // Load tmx |
| 625 | err = engo.Files.LoadReaderData("test.tmx", buf) |
| 626 | if err != nil { |
| 627 | t.Errorf("Unable to load tmx file for testing. Error was: %v", err) |
| 628 | } |
| 629 | |
| 630 | resource, err := engo.Files.Resource("test.tmx") |
| 631 | if err != nil { |
| 632 | t.Errorf("Unable to retrieve resource. Error was: %v", err) |
| 633 | } |
| 634 | tmxResource := resource.(TMXResource) |
| 635 | |
| 636 | bounds := tmxResource.Level.Bounds() |
| 637 | exp := engo.AABB{ |
| 638 | Min: engo.Point{X: 0, Y: 0}, |
| 639 | Max: engo.Point{X: 48, Y: 48}, |
| 640 | } |
| 641 | 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 { |
| 642 | t.Errorf("Bounds was not returned correctly\nWanted: %v\nGot: %v", exp, bounds) |
| 643 | } |
| 644 | |
| 645 | if tmxResource.Level.Width() != 3 { |
| 646 | t.Error("Level width was not returned correctly.") |
| 647 | } |
| 648 | |
| 649 | if tmxResource.Level.Height() != 3 { |
| 650 | t.Error("Level height was not returned correctly.") |
| 651 | } |
| 652 | |