| 538 | } |
| 539 | |
| 540 | func TestTMXAsset(t *testing.T) { |
| 541 | // Create an image in memory |
| 542 | imgbuf := bytes.NewBuffer([]byte{}) |
| 543 | img := image.NewRGBA(image.Rect(0, 0, 457, 305)) |
| 544 | err := png.Encode(imgbuf, img) |
| 545 | if err != nil { |
| 546 | t.Errorf("Unable to encode png from image") |
| 547 | } |
| 548 | |
| 549 | // Load the image |
| 550 | err = engo.Files.LoadReaderData("test.png", imgbuf) |
| 551 | if err != nil { |
| 552 | t.Errorf("Unable to load test png. Error was: %v", err) |
| 553 | } |
| 554 | |
| 555 | // Load the template |
| 556 | buf := bytes.NewBuffer([]byte{}) |
| 557 | tmpl, err := template.New("test").Parse(testTMXtmpl) |
| 558 | if err != nil { |
| 559 | t.Error("Error parsing tmx template") |
| 560 | } |
| 561 | err = tmpl.Execute(buf, tmxData{ |
| 562 | Orientation: "orthogonal", |
| 563 | RenderOrder: "right-down", |
| 564 | }) |
| 565 | if err != nil { |
| 566 | t.Error("Error executing tmx template") |
| 567 | } |
| 568 | |
| 569 | // Load tmx |
| 570 | err = engo.Files.LoadReaderData("test.tmx", buf) |
| 571 | if err != nil { |
| 572 | t.Errorf("Unable to load tmx file for testing. Error was: %v", err) |
| 573 | } |
| 574 | |
| 575 | resource, err := engo.Files.Resource("test.tmx") |
| 576 | if err != nil { |
| 577 | t.Errorf("Unable to retrieve resource. Error was: %v", err) |
| 578 | } |
| 579 | tmxResource := resource.(TMXResource) |
| 580 | url := tmxResource.URL() |
| 581 | if url != "test.tmx" { |
| 582 | t.Errorf("URL did not match expected\nWanted: %v\nGot: %v", "test.tmx", url) |
| 583 | } |
| 584 | |
| 585 | // Unload it |
| 586 | engo.Files.Unload("test.tmx") |
| 587 | |
| 588 | // Check that it's unloaded |
| 589 | resource, err = engo.Files.Resource("test.tmx") |
| 590 | if err == nil { |
| 591 | t.Error("After unloading, resource was retireved.") |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | func TestTMXLevel(t *testing.T) { |
| 596 | // Create an image in memory |