Now mostly working with GUECS but shaders are still busted. Have to find out why they stopped working.
This commit is contained in:
parent
a5f6a82611
commit
ac22a11c9f
27 changed files with 162 additions and 1210 deletions
45
textures.cpp
45
textures.cpp
|
@ -1,8 +1,8 @@
|
|||
#include "textures.hpp"
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include "dbc.hpp"
|
||||
#include <fmt/core.h>
|
||||
#include "textures.hpp"
|
||||
#include "config.hpp"
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <memory>
|
||||
|
||||
namespace textures {
|
||||
|
@ -15,7 +15,7 @@ namespace textures {
|
|||
Config assets("assets/config.json");
|
||||
|
||||
for(auto& [name, settings] : assets["sprites"].items()) {
|
||||
auto texture = make_shared<sf::Texture>(Config::path_to(settings["path"]));
|
||||
auto texture = make_shared<sf::Texture>(settings["path"]);
|
||||
|
||||
texture->setSmooth(assets["graphics"]["smooth_textures"]);
|
||||
auto sprite = make_shared<sf::Sprite>(*texture);
|
||||
|
@ -24,32 +24,18 @@ namespace textures {
|
|||
int height = settings["frame_height"];
|
||||
sprite->setTextureRect({{0,0}, {width, height}});
|
||||
|
||||
TMGR.sprite_textures.try_emplace(name, name, sprite, texture);
|
||||
}
|
||||
}
|
||||
|
||||
void load_tiles() {
|
||||
Config assets("assets/tiles.json");
|
||||
auto &tiles = assets.json();
|
||||
|
||||
for(auto &el : tiles.items()) {
|
||||
auto &config = el.value();
|
||||
TMGR.surfaces.emplace_back(load_image(config["texture"]));
|
||||
wchar_t tid = config["display"];
|
||||
int surface_i = TMGR.surfaces.size() - 1;
|
||||
TMGR.char_to_texture[tid] = surface_i;
|
||||
TMGR.sprite_textures.try_emplace(name, sprite, texture);
|
||||
}
|
||||
}
|
||||
|
||||
void init() {
|
||||
if(!initialized) {
|
||||
load_tiles();
|
||||
load_sprites();
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
SpriteTexture get(std::string name) {
|
||||
SpriteTexture get(const std::string& name) {
|
||||
dbc::check(initialized, "you forgot to call textures::init()");
|
||||
dbc::check(TMGR.sprite_textures.contains(name),
|
||||
fmt::format("!!!!! texture pack does not contain {} sprite", name));
|
||||
|
@ -64,25 +50,10 @@ namespace textures {
|
|||
return result;
|
||||
}
|
||||
|
||||
sf::Image load_image(std::string filename) {
|
||||
sf::Image load_image(const std::string& filename) {
|
||||
sf::Image texture;
|
||||
bool good = texture.loadFromFile(Config::path_to(filename));
|
||||
bool good = texture.loadFromFile(filename);
|
||||
dbc::check(good, fmt::format("failed to load {}", filename));
|
||||
return texture;
|
||||
}
|
||||
|
||||
const uint32_t* get_surface(size_t num) {
|
||||
return (const uint32_t *)TMGR.surfaces[num].getPixelsPtr();
|
||||
}
|
||||
|
||||
matrix::Matrix 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();) {
|
||||
wchar_t tid = tile_ids[it.y][it.x];
|
||||
result[it.y][it.x] = TMGR.char_to_texture.at(tid);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue