/
GameInterface.cpp
80 lines (61 loc) · 2.12 KB
/
GameInterface.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "GameInterface.h"
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
namespace script {
ScriptGame::ScriptGame(const game::IGamePtr& game) :
_game(game)
{}
std::string ScriptGame::getKeyValue(const std::string& key) const
{
return (_game != NULL) ? _game->getKeyValue(key) : "";
}
// -----------------------------------------------
std::string GameInterface::getUserEnginePath()
{
return GlobalGameManager().getUserEnginePath();
}
std::string GameInterface::getModPath()
{
return GlobalGameManager().getModPath();
}
std::string GameInterface::getModBasePath()
{
return GlobalGameManager().getModBasePath();
}
std::string GameInterface::getFSGame()
{
return GlobalGameManager().getFSGame();
}
std::string GameInterface::getFSGameBase()
{
return GlobalGameManager().getFSGameBase();
}
ScriptGame GameInterface::currentGame() {
return ScriptGame(GlobalGameManager().currentGame());
}
GameInterface::PathList GameInterface::getVFSSearchPaths() {
game::IGameManager::PathList paths = GlobalGameManager().getVFSSearchPaths();
PathList pathVector;
pathVector.assign(paths.begin(), paths.end()); // copy the list
return pathVector;
}
// IScriptInterface implementation
void GameInterface::registerInterface(boost::python::object& nspace)
{
// Add the Game object declaration
nspace["Game"] = boost::python::class_<ScriptGame>("Game", boost::python::init<const game::IGamePtr&>())
.def("getKeyValue", &ScriptGame::getKeyValue)
;
// Add the module declaration to the given python namespace
nspace["GlobalGameManager"] = boost::python::class_<GameInterface>("GlobalGameManager")
.def("getUserEnginePath", &GameInterface::getUserEnginePath)
.def("getModPath", &GameInterface::getModPath)
.def("getModBasePath", &GameInterface::getModBasePath)
.def("getFSGame", &GameInterface::getFSGame)
.def("getFSGameBase", &GameInterface::getFSGameBase)
.def("currentGame", &GameInterface::currentGame)
.def("getVFSSearchPaths", &GameInterface::getVFSSearchPaths)
;
// Now point the Python variable "GlobalGameManager" to this instance
nspace["GlobalGameManager"] = boost::python::ptr(this);
}
} // namespace script