You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
#include "texture.hpp"
|
|
#include <SFML/Graphics/Image.hpp>
|
|
#include "dbc.hpp"
|
|
#include <fmt/core.h>
|
|
#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<sf::Texture>(path);
|
|
|
|
texture->setSmooth(false);
|
|
auto sprite = make_shared<sf::Sprite>(*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];
|
|
}
|
|
|