Intermediate refactor to move everything over to using the textures module rather than everyone using one TexturePack thing.

This commit is contained in:
Zed A. Shaw 2025-02-21 03:00:56 -05:00
parent 6c1d851e85
commit f3e1413022
23 changed files with 129 additions and 64 deletions

View file

@ -7,14 +7,14 @@
using std::shared_ptr, std::make_shared;
sf::Image TexturePack::load_image(std::string filename) {
sf::Image TextureManager::load_image(std::string filename) {
sf::Image texture;
bool good = texture.loadFromFile(filename);
dbc::check(good, fmt::format("failed to load {}", filename));
return texture;
}
void TexturePack::load_sprites() {
void TextureManager::load_sprites() {
Config assets("assets/config.json");
for(auto& el : assets["sprites"].items()) {
@ -28,13 +28,11 @@ void TexturePack::load_sprites() {
sprite_textures[name] = {sprite, texture};
}
sword = sprite_textures["sword"];
floor = load_image(assets["sprites"]["floor"]);
ceiling = load_image(assets["sprites"]["ceiling"]);
}
void TexturePack::load_tiles() {
void TextureManager::load_tiles() {
Config assets("assets/tiles.json");
auto &tiles = assets.json();
@ -50,11 +48,11 @@ void TexturePack::load_tiles() {
}
}
const uint32_t* TexturePack::get_surface(size_t num) {
const uint32_t* TextureManager::get_surface(size_t num) {
return (const uint32_t *)surfaces[num].getPixelsPtr();
}
matrix::Matrix TexturePack::convert_char_to_texture(matrix::Matrix &tile_ids) {
matrix::Matrix TextureManager::convert_char_to_texture(matrix::Matrix &tile_ids) {
auto result = matrix::make(matrix::width(tile_ids), matrix::height(tile_ids));
for(matrix::each_cell it(tile_ids); it.next();) {
@ -65,7 +63,7 @@ matrix::Matrix TexturePack::convert_char_to_texture(matrix::Matrix &tile_ids) {
return result;
}
SpriteTexture TexturePack::get(std::string name) {
SpriteTexture TextureManager::get(std::string name) {
dbc::check(sprite_textures.contains(name),
fmt::format("!!!!! texture pack does not contain {} sprite", name));
return sprite_textures.at(name);