Add the frame width/height to SpriteTexture. Closes #13

This commit is contained in:
Zed A. Shaw 2025-06-27 01:21:50 -04:00
parent ea92dcc3c4
commit 19682fd0bc
4 changed files with 39 additions and 12 deletions

View file

@ -2,26 +2,42 @@
#include <fmt/core.h>
#include <string>
#include "textures.hpp"
#include "levelmanager.hpp"
#include "constants.hpp"
#include "components.hpp"
using namespace fmt;
TEST_CASE("test texture management", "[textures]") {
components::init();
textures::init();
auto spider = textures::get("hairy_spider");
REQUIRE(spider.sprite != nullptr);
REQUIRE(spider.texture != nullptr);
REQUIRE(spider.frame_size.x == TEXTURE_WIDTH);
REQUIRE(spider.frame_size.y == TEXTURE_HEIGHT);
auto image = textures::load_image("assets/sprites/hairy_spider.png");
auto img_ptr = textures::get_surface(0);
REQUIRE(img_ptr != nullptr);
size_t floor_tile = textures::get_id("floor_tile");
size_t gray_stone = textures::get_id("gray_stone_floor_light");
LevelManager levels;
GameLevel level = levels.current();
auto& tiles = level.map->tiles();
auto& walls = level.map->walls();
REQUIRE(matrix::width(tiles) == matrix::width(walls));
REQUIRE(matrix::height(tiles) == matrix::height(walls));
auto floor_ptr = textures::get_surface(floor_tile);
REQUIRE(floor_ptr != nullptr);
auto gray_stone_ptr = textures::get_surface(gray_stone);
REQUIRE(gray_stone_ptr != nullptr);
auto& light = textures::get_ambient_light();
REQUIRE(light.size() > 0);
REQUIRE(light[floor_tile] == 0);
REQUIRE(light[gray_stone] > 0);
auto& tiles = textures::get_map_tile_set();
REQUIRE(tiles.size() > 0);
REQUIRE(tiles[floor_tile] > 0);
REQUIRE(tiles[gray_stone] > 0);
auto ceiling = textures::get_ceiling(floor_tile);
REQUIRE(ceiling != nullptr);
}