aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/Asset.h
blob: 0f6b0b32e181717e7e3b63b0184c385afbb3501e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once

#include <string>
#include <unordered_map>

namespace crepe {

/**
 * \brief Asset location helper
 *
 * This class is used to locate game asset files, and should *always* be used
 * instead of reading file paths directly.
 */
class Asset {
public:
	/**
	 * \param src  Unique identifier to asset
	 */
	Asset(const std::string & src);
	/**
	 * \param src  Unique identifier to asset
	 */
	Asset(const char * src);

public:
	/**
	 * \brief Get the path to this asset
	 * \return path to this asset
	 */
	const std::string & get_path() const noexcept;

private:
	//! path to asset
	const std::string src;

private:
	std::string find_asset(const std::string & src) const;
	/**
	 * \returns The path to the current executable
	 */
	std::string whereami() const noexcept;
};

} // namespace crepe

namespace std {

template<> struct hash<const crepe::Asset> {
	size_t operator()(const crepe::Asset & asset) const noexcept;
};

}