#include "texture.hpp" #include #include "dbc.hpp" #include #include "config.hpp" #include "constants.hpp" using std::shared_ptr, std::make_shared; sf::Image TexturePack::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() { Config assets("assets/config.json"); for(auto& el : assets["sprites"].items()) { string path = el.value(); auto texture = make_shared(path); texture->setSmooth(false); auto sprite = make_shared(*texture); string name = el.key(); sprite_textures[name] = {sprite, texture}; } sword = sprite_textures["sword"]; } void TexturePack::position_sprite(double x, double y, string name) { sprites.emplace_back(x, y, sprite_textures[name]); } void TexturePack::load_textures() { Config assets("assets/config.json"); for(string tile_path : assets["textures"]) { images.emplace_back(load_image(tile_path)); } floor = load_image(assets["sprites"]["floor"]); ceiling = load_image(assets["sprites"]["ceiling"]); } const uint32_t* TexturePack::get_texture(size_t num) { return (const uint32_t *)images[num].getPixelsPtr(); } Sprite &TexturePack::get_sprite(size_t sprite_num) { return sprites[sprite_num]; }