-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.h
52 lines (45 loc) · 1.24 KB
/
map.h
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
#ifndef MAP_H
#define MAP_H
#include <filesystem>
#include "lua/lua.hpp"
#include <type_traits>
#include "pge/olcPixelGameEngine.h"
class Map
{
private:
const std::filesystem::path mapFilePath = {"assets/scripts/mapmanager.lua"};
lua_State* L;
public:
Map();
~Map();
int GetPos(std::string layer, olc::vi2d pos);
void SetPos(std::string layer, olc::vi2d pos, int val);
template<typename T> T GetLayerProperty(std::string layer, std::string property)
{
lua_getglobal(this->L, "GetLayerProperty");
lua_pushstring(this->L, layer.c_str());
lua_pushstring(this->L, property.c_str());
lua_pcall(this->L, 2, 1, 0);
T val;
if constexpr (std::is_same_v<T, std::string>)
{
val = T(lua_tostring(this->L, -1));
}
else if constexpr (std::is_same_v<T, bool>)
{
val = lua_toboolean(this->L, -1);
}
else if constexpr (std::is_integral<T>::value)
{
val = lua_tointeger(this->L, -1);
}
else if constexpr (std::is_floating_point<T>::value)
{
val = lua_tonumber(this->L, -1);
}
lua_pop(this->L, 1);
return val;
}
void Load();
};
#endif // MAP_H