Had to update everything to use Config::path_to for Config::BASE_DIR loading.

master
Zed A. Shaw 2 days ago
parent eda7c30fc1
commit 2ef5a52928
  1. 3
      backend.cpp
  2. 9
      shaders.cpp
  3. 10
      sound.cpp
  4. 2
      sound.hpp
  5. 9
      textures.cpp

@ -2,6 +2,7 @@
#include "shaders.hpp"
#include "sound.hpp"
#include "textures.hpp"
#include "config.hpp"
namespace sfml {
guecs::SpriteTexture Backend::texture_get(const string& name) {
@ -59,7 +60,7 @@ namespace sfml {
theme.BG_COLOR = theme.MID;
theme.BORDER_COLOR = theme.LIGHT_DARK;
theme.BG_COLOR_DARK = theme.BLACK;
theme.FONT_FILE_NAME = "assets/text.ttf";
theme.FONT_FILE_NAME = Config::path_to("assets/text.ttf").string();
return theme;
}

@ -1,5 +1,5 @@
#include "guecs/sfml/shaders.hpp"
#include "guecs/sfml/config.hpp"
#include "shaders.hpp"
#include "config.hpp"
#include "dbc.hpp"
#include <SFML/Graphics/Image.hpp>
#include <fmt/core.h>
@ -17,9 +17,10 @@ namespace shaders {
}
bool load_shader(std::string name, nlohmann::json& settings) {
std::string file_name = settings["file_name"];
auto file_name = settings["file_name"];
auto file_path = Config::path_to(file_name);
auto ptr = std::make_shared<sf::Shader>();
bool good = ptr->loadFromFile(file_name, sf::Shader::Type::Fragment);
bool good = ptr->loadFromFile(file_path, sf::Shader::Type::Fragment);
if(good) {
configure_shader_defaults(ptr);

@ -1,5 +1,5 @@
#include "guecs/sfml/sound.hpp"
#include "guecs/sfml/config.hpp"
#include "sound.hpp"
#include "config.hpp"
#include "dbc.hpp"
#include <fmt/core.h>
@ -31,14 +31,14 @@ namespace sound {
Config assets("assets/config.json");
for(auto& el : assets["sounds"].items()) {
load(el.key(), el.value());
load(el.key(), Config::path_to(el.value()));
}
initialized = true;
}
}
void load(const std::string& name, const std::string& sound_path) {
dbc::check(fs::exists(sound_path), fmt::format("sound file {} does not exist", sound_path));
void load(const std::string& name, const std::filesystem::path& sound_path) {
dbc::check(fs::exists(sound_path), fmt::format("sound file {} does not exist", sound_path.string()));
// create the buffer and keep in the buffer map
auto buffer = make_shared<sf::SoundBuffer>(sound_path);

@ -16,7 +16,7 @@ namespace sound {
};
void init();
void load(const std::string& name, const std::string& path);
void load(const std::string& name, const std::filesystem::path& path);
void play(const std::string& name, bool loop=false);
void play_at(const std::string& name, float x, float y, float z);
void stop(const std::string& name);

@ -15,7 +15,9 @@ namespace textures {
Config assets("assets/config.json");
for(auto& [name, settings] : assets["sprites"].items()) {
auto texture = make_shared<sf::Texture>(settings["path"]);
auto file_name = settings["path"];
auto file_path = Config::path_to(file_name);
auto texture = make_shared<sf::Texture>(file_path);
texture->setSmooth(assets["graphics"]["smooth_textures"]);
auto sprite = make_shared<sf::Sprite>(*texture);
@ -52,8 +54,9 @@ namespace textures {
sf::Image load_image(const std::string& filename) {
sf::Image texture;
bool good = texture.loadFromFile(filename);
dbc::check(good, fmt::format("failed to load {}", filename));
auto file_path = Config::path_to(filename);
bool good = texture.loadFromFile(file_path);
dbc::check(good, fmt::format("failed to load {}", file_path.string()));
return texture;
}
};

Loading…
Cancel
Save