Debian Codegraph @

plugins/script/interfaces/GameInterface.cpp

raw
1 #include "GameInterface.h"
2
3 #include <pybind11/pybind11.h>
4
5 namespace script
6 {
7
8 ScriptGame::ScriptGame(const game::IGamePtr& game) :
9 _game(game)
10 {}
11
12 std::string ScriptGame::getKeyValue(const std::string& key) const
13 {
14 return (_game != NULL) ? _game->getKeyValue(key) : "";
15 }
16
17 // -----------------------------------------------
18
19 std::string GameInterface::getUserEnginePath()
20 {
21 return GlobalGameManager().getUserEnginePath();
22 }
23
24 std::string GameInterface::getModPath()
25 {
26 return GlobalGameManager().getModPath();
27 }
28
29 std::string GameInterface::getModBasePath()
30 {
31 return GlobalGameManager().getModBasePath();
32 }
33
34 ScriptGame GameInterface::currentGame()
35 {
36 return ScriptGame(GlobalGameManager().currentGame());
37 }
38
39 GameInterface::PathList GameInterface::getVFSSearchPaths()
40 {
41 game::IGameManager::PathList paths = GlobalGameManager().getVFSSearchPaths();
42
43 PathList pathVector;
44 pathVector.assign(paths.begin(), paths.end()); // copy the list
45
46 return pathVector;
47 }
48
49 // IScriptInterface implementation
50 void GameInterface::registerInterface(py::module& scope, py::dict& globals)
51 {
52 // Add the Game object declaration
53 py::class_<ScriptGame> game(scope, "Game");
54 game.def(py::init<const game::IGamePtr&>());
55 game.def("getKeyValue", &ScriptGame::getKeyValue);
56
57 // Add the module declaration to the given python namespace
58 py::class_<GameInterface> gameManager(scope, "GameManager");
59
60 gameManager.def("getUserEnginePath", &GameInterface::getUserEnginePath);
61 gameManager.def("getModPath", &GameInterface::getModPath);
62 gameManager.def("getModBasePath", &GameInterface::getModBasePath);
63 gameManager.def("currentGame", &GameInterface::currentGame);
64 gameManager.def("getVFSSearchPaths", &GameInterface::getVFSSearchPaths);
65
66 // Now point the Python variable "GlobalGameManager" to this instance
67 globals["GlobalGameManager"] = this;
68 }
69
70 } // namespace script