Add new resources system in app library
This commit is contained in:
parent
bf90a8edd9
commit
93d5c55c68
3 changed files with 53 additions and 0 deletions
17
libs/app/include/psemek/app/resource.hpp
Normal file
17
libs/app/include/psemek/app/resource.hpp
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <psemek/io/stream.hpp>
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace psemek::app
|
||||||
|
{
|
||||||
|
|
||||||
|
std::filesystem::path resource_root();
|
||||||
|
void set_resource_root(std::filesystem::path const & root);
|
||||||
|
|
||||||
|
// Implemented by a backend library
|
||||||
|
std::unique_ptr<io::istream> open_resource(std::filesystem::path const & relative_path);
|
||||||
|
|
||||||
|
}
|
||||||
24
libs/app/source/resource.cpp
Normal file
24
libs/app/source/resource.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#include <psemek/app/resource.hpp>
|
||||||
|
#include <psemek/util/executable_path.hpp>
|
||||||
|
|
||||||
|
namespace psemek::app
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
static std::filesystem::path global_resource_root = util::executable_path().parent_path();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::filesystem::path resource_root()
|
||||||
|
{
|
||||||
|
return global_resource_root;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_resource_root(std::filesystem::path const & root)
|
||||||
|
{
|
||||||
|
global_resource_root = root;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
12
libs/sdl2/source/resource.cpp
Normal file
12
libs/sdl2/source/resource.cpp
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
#include <psemek/app/resource.hpp>
|
||||||
|
#include <psemek/io/file_stream.hpp>
|
||||||
|
|
||||||
|
namespace psemek::app
|
||||||
|
{
|
||||||
|
|
||||||
|
std::unique_ptr<io::istream> open_resource(std::filesystem::path const & relative_path)
|
||||||
|
{
|
||||||
|
return std::make_unique<io::file_istream>(app::resource_root() / relative_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue