|
|
|
#include "texture.hpp"
|
|
|
|
#include <SFML/Graphics/Image.hpp>
|
|
|
|
#include "dbc.hpp"
|
|
|
|
#include <fmt/core.h>
|
|
|
|
#include "config.hpp"
|
|
|
|
#include "constants.hpp"
|
|
|
|
|
|
|
|
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_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/undead_peasant-spritesheet.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});
|
|
|
|
|
|
|
|
sword.sprite_texture = new sf::Texture("assets/cinqueda_1-512.png");
|
|
|
|
sword.sprite_texture->setSmooth(false);
|
|
|
|
sword.sprite = new sf::Sprite(*sword.sprite_texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|