mirror of
https://gitlab.com/square-game-liberation-front/F.E.I.S.git
synced 2024-11-15 03:27:41 +01:00
force utf8 encoding when passing a string to the loadFromFile API of SFML
This commit is contained in:
parent
c943ccaee2
commit
a844dc4cba
@ -5,6 +5,8 @@
|
||||
#include <fmt/core.h>
|
||||
#include <SFML/Audio/SoundBuffer.hpp>
|
||||
|
||||
#include "utf8_strings.hpp"
|
||||
|
||||
FakePitchedSoundStream::FakePitchedSoundStream(
|
||||
const std::filesystem::path& path_to_sample,
|
||||
float pitch_
|
||||
@ -12,7 +14,7 @@ FakePitchedSoundStream::FakePitchedSoundStream(
|
||||
pitch(pitch_),
|
||||
sample(std::make_shared<sf::SoundBuffer>())
|
||||
{
|
||||
if (not sample->loadFromFile(path_to_sample)) {
|
||||
if (not sample->loadFromFile(to_utf8_encoded_string(path_to_sample))) {
|
||||
throw std::runtime_error(fmt::format("Could not load audio sample : {}", path_to_sample.string()));
|
||||
}
|
||||
finish_initializing_the_sample();
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "src/better_timing.hpp"
|
||||
#include "src/custom_sfml_audio/synced_sound_streams.hpp"
|
||||
#include "variant_visitor.hpp"
|
||||
#include "utf8_strings.hpp"
|
||||
|
||||
EditorState::EditorState(const std::filesystem::path& assets_, config::Config& config_) :
|
||||
config(config_),
|
||||
@ -1396,7 +1397,7 @@ void EditorState::reload_jacket() {
|
||||
|
||||
if (
|
||||
not std::filesystem::exists(jacket_path)
|
||||
or not jacket->loadFromFile(jacket_path.string())
|
||||
or not jacket->loadFromFile(to_utf8_encoded_string(jacket_path))
|
||||
) {
|
||||
jacket.reset();
|
||||
} else {
|
||||
|
@ -13,6 +13,8 @@
|
||||
#include <SFML/Graphics/Texture.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
|
||||
#include "utf8_strings.hpp"
|
||||
|
||||
using opt_tex_ref = std::optional<std::reference_wrapper<const sf::Texture>>;
|
||||
|
||||
/*
|
||||
@ -65,7 +67,7 @@ std::array<sf::Texture, number> load_tex_with_prefix(
|
||||
);
|
||||
std::filesystem::path texFile = folder / filename;
|
||||
sf::Texture tex;
|
||||
if (!tex.loadFromFile(texFile.string())) {
|
||||
if (!tex.loadFromFile(to_utf8_encoded_string(texFile))) {
|
||||
throw std::runtime_error(fmt::format(
|
||||
"Unable to load texture folder {}, failed on texture {}",
|
||||
folder.string(),
|
||||
|
@ -77,7 +77,7 @@ int main() {
|
||||
std::filesystem::directory_iterator(assets_folder / "textures" / "markers")) {
|
||||
if (folder.is_directory()) {
|
||||
sf::Texture markerPreview;
|
||||
markerPreview.loadFromFile((folder.path() / "ma15.png").string());
|
||||
markerPreview.loadFromFile(to_utf8_encoded_string(folder.path() / "ma15.png"));
|
||||
markerPreview.setSmooth(true);
|
||||
markerPreviews.insert({folder, markerPreview});
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <fmt/core.h>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "utf8_strings.hpp"
|
||||
|
||||
Marker first_available_marker_in(const std::filesystem::path& assets_folder) {
|
||||
for (auto& folder : std::filesystem::directory_iterator(assets_folder / "textures" / "markers")) {
|
||||
try {
|
||||
@ -20,7 +22,7 @@ Marker::Marker(const std::filesystem::path& folder_):
|
||||
const auto emplace_back = [&](std::vector<sf::Texture>& vec, const std::string& file){
|
||||
auto& tex = vec.emplace_back();
|
||||
const auto path = folder / file;
|
||||
if (not tex.loadFromFile(path.string())) {
|
||||
if (not tex.loadFromFile(to_utf8_encoded_string(path))) {
|
||||
throw std::runtime_error(fmt::format(
|
||||
"Unable to load marker {} - failed on image {}",
|
||||
folder.string(),
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "playfield.hpp"
|
||||
|
||||
#include "toolbox.hpp"
|
||||
#include "utf8_strings.hpp"
|
||||
|
||||
const std::string texture_file = "textures/edit_textures/game_front_edit_tex_1.tex.png";
|
||||
|
||||
@ -8,7 +9,7 @@ Playfield::Playfield(std::filesystem::path assets_folder) :
|
||||
long_note(assets_folder / "textures" / "long"),
|
||||
texture_path(assets_folder / texture_file)
|
||||
{
|
||||
if (!base_texture.loadFromFile(texture_path)) {
|
||||
if (!base_texture.loadFromFile(to_utf8_encoded_string(texture_path))) {
|
||||
std::cerr << "Unable to load texture " << texture_path;
|
||||
throw std::runtime_error("Unable to load texture " + texture_path.string());
|
||||
}
|
||||
|
@ -3,12 +3,13 @@
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include "toolbox.hpp"
|
||||
#include "utf8_strings.hpp"
|
||||
|
||||
SoundEffect::SoundEffect(std::filesystem::path path) :
|
||||
shouldPlay(false),
|
||||
buffer(),
|
||||
volume(10) {
|
||||
if (!buffer.loadFromFile(path.string())) {
|
||||
if (!buffer.loadFromFile(to_utf8_encoded_string(path))) {
|
||||
throw std::runtime_error("Unable to load sound : " + path.string());
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,10 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "utf8_strings.hpp"
|
||||
|
||||
BlankScreen::BlankScreen(std::filesystem::path assets) : gris_de_fond(sf::Color(38, 38, 38)) {
|
||||
if (!tex_FEIS_logo.loadFromFile(assets / "textures" / "FEIS_logo.png")) {
|
||||
if (!tex_FEIS_logo.loadFromFile(to_utf8_encoded_string(assets / "textures" / "FEIS_logo.png"))) {
|
||||
throw std::string("Unable to load assets/textures/FEIS_logo.png");
|
||||
}
|
||||
tex_FEIS_logo.setSmooth(true);
|
||||
|
@ -2,13 +2,15 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "utf8_strings.hpp"
|
||||
|
||||
const std::string texture_file = "textures/edit_textures/game_front_edit_tex_1.tex.png";
|
||||
|
||||
DensityGraph::DensityGraph(std::filesystem::path assets, const config::Config& config) :
|
||||
texture_path(assets / texture_file),
|
||||
collision_zone(config.editor.collision_zone)
|
||||
{
|
||||
if (!base_texture.loadFromFile(texture_path)) {
|
||||
if (!base_texture.loadFromFile(to_utf8_encoded_string(texture_path))) {
|
||||
std::cerr << "Unable to load texture " << texture_path;
|
||||
throw std::runtime_error("Unable to load texture " + texture_path.string());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user