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
|
#include "GameInterface.h"
#include <pybind11/pybind11.h>
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();
}
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(py::module& scope, py::dict& globals)
{
// Add the Game object declaration
py::class_<ScriptGame> game(scope, "Game");
game.def(py::init<const game::IGamePtr&>());
game.def("getKeyValue", &ScriptGame::getKeyValue);
// Add the module declaration to the given python namespace
py::class_<GameInterface> gameManager(scope, "GameManager");
gameManager.def("getUserEnginePath", &GameInterface::getUserEnginePath);
gameManager.def("getModPath", &GameInterface::getModPath);
gameManager.def("getModBasePath", &GameInterface::getModBasePath);
gameManager.def("currentGame", &GameInterface::currentGame);
gameManager.def("getVFSSearchPaths", &GameInterface::getVFSSearchPaths);
// Now point the Python variable "GlobalGameManager" to this instance
globals["GlobalGameManager"] = this;
}
} // namespace script
|