|
|
|
#include "texture.hpp"
|
|
|
|
#include <SFML/Graphics/Image.hpp>
|
|
|
|
#include "dbc.hpp"
|
|
|
|
#include <fmt/core.h>
|
|
|
|
#include "config.hpp"
|
|
|
|
|
|
|
|
Image TexturePack::load_image(std::string filename) {
|
|
|
|
Image texture(TEXTURE_WIDTH * TEXTURE_HEIGHT);
|
|
|
|
sf::Image img;
|
|
|
|
bool good = img.loadFromFile(filename);
|
|
|
|
dbc::check(good, fmt::format("failed to load {}", filename));
|
|
|
|
|
|
|
|
uint32_t *pixbuf = (uint32_t *)img.getPixelsPtr();
|
|
|
|
std::copy_n(pixbuf, texture.size(), texture.begin());
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TexturePack::load_textures() {
|
|
|
|
Config assets("assets/config.json");
|
|
|
|
for(string tile_path : assets["textures"]) {
|
|
|
|
images.emplace_back(load_image(tile_path));
|
|
|
|
}
|
|
|
|
|
|
|
|
for(string tile_path : assets["sprites"]) {
|
|
|
|
images.emplace_back(load_image(tile_path));
|
|
|
|
}
|
|
|
|
|
|
|
|
floor = load_image(assets["floor"]);
|
|
|
|
ceiling = load_image(assets["ceiling"]);
|
|
|
|
|
|
|
|
sf::Texture* sprite_texture = new sf::Texture("assets/evil_eye_test-256.png");
|
|
|
|
sprite_texture->setSmooth(false);
|
|
|
|
sf::Sprite* sf_sprite = new sf::Sprite(*sprite_texture);
|
|
|
|
|
|
|
|
sprites.push_back({4.0, 3.55, 6, sf_sprite, sprite_texture});
|
|
|
|
}
|
|
|
|
|
|
|
|
Image& TexturePack::get_texture(size_t num) {
|
|
|
|
return images[num];
|
|
|
|
}
|
|
|
|
|
|
|
|
Sprite &TexturePack::get_sprite(size_t sprite_num) {
|
|
|
|
return sprites[sprite_num];
|
|
|
|
}
|