Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
FileSystem.h
Go to the documentation of this file.
1/**
2 * @file FileSystem.h
3 * @ingroup mnd_io
4 * @brief Asset-path resolution and file loading for the engine.
5 *
6 * FileSystem abstracts the difference between source-tree paths and the
7 * runtime asset directory. The assets folder is resolved relative to the
8 * executable using the ASSETS_DIR constant baked in via config.h at build
9 * time. Access through Engine::GetFileSystem().
10 *
11 * @see Engine::GetFileSystem, FileReader
12 */
13
14#pragma once
15
16#include <filesystem>
17
18namespace mnd
19{
20
21/**
22 * @brief Resolves asset paths and loads files into memory.
23 *
24 * Owned by the Engine singleton. All relative paths passed to Load* methods
25 * are resolved against GetAssetsFolder().
26 */
28{
29public:
30 /**
31 * @brief Return the directory containing the running executable.
32 * @return Absolute path to the executable's parent directory.
33 */
34 std::filesystem::path GetExecutableFolder() const;
35
36 /**
37 * @brief Return the runtime assets directory.
38 *
39 * Resolved as ASSETS_DIR relative to the executable folder. CMake copies
40 * the source-tree @c assets/ folder here post-build.
41 *
42 * @return Absolute path to the assets directory.
43 */
44 std::filesystem::path GetAssetsFolder() const;
45
46 /**
47 * @brief Load an arbitrary file into a byte buffer.
48 * @param path Absolute or relative path to the file.
49 * @return File contents as a vector of bytes.
50 */
51 std::vector<char> LoadFile(const std::filesystem::path &path);
52
53 /**
54 * @brief Load a file from the assets directory into a byte buffer.
55 * @param relativePath Path relative to GetAssetsFolder().
56 * @return File contents as a vector of bytes.
57 */
58 std::vector<char> LoadAssetFile(const std::string &relativePath);
59
60 /**
61 * @brief Load a text file from the assets directory into a string.
62 * @param relativePath Path relative to GetAssetsFolder().
63 * @return File contents as a UTF-8 string.
64 */
65 std::string LoadAssetFileText(const std::string &relativePath);
66};
67
68} // namespace mnd
Resolves asset paths and loads files into memory.
Definition FileSystem.h:28
std::filesystem::path GetExecutableFolder() const
Return the directory containing the running executable.
std::vector< char > LoadFile(const std::filesystem::path &path)
Load an arbitrary file into a byte buffer.
std::string LoadAssetFileText(const std::string &relativePath)
Load a text file from the assets directory into a string.
std::vector< char > LoadAssetFile(const std::string &relativePath)
Load a file from the assets directory into a byte buffer.
std::filesystem::path GetAssetsFolder() const
Return the runtime assets directory.