Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Migrated GameInterface
  • Loading branch information
codereader committed Jul 20, 2017
1 parent 6f6d719 commit 1cca241
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
40 changes: 21 additions & 19 deletions plugins/script/interfaces/GameInterface.cpp
@@ -1,8 +1,9 @@
#include "GameInterface.h"

#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <pybind11/pybind11.h>

namespace script {
namespace script
{

ScriptGame::ScriptGame(const game::IGamePtr& game) :
_game(game)
Expand All @@ -13,7 +14,6 @@ std::string ScriptGame::getKeyValue(const std::string& key) const
return (_game != NULL) ? _game->getKeyValue(key) : "";
}


// -----------------------------------------------

std::string GameInterface::getUserEnginePath()
Expand Down Expand Up @@ -41,11 +41,13 @@ std::string GameInterface::getFSGameBase()
return GlobalGameManager().getFSGameBase();
}

ScriptGame GameInterface::currentGame() {
ScriptGame GameInterface::currentGame()
{
return ScriptGame(GlobalGameManager().currentGame());
}

GameInterface::PathList GameInterface::getVFSSearchPaths() {
GameInterface::PathList GameInterface::getVFSSearchPaths()
{
game::IGameManager::PathList paths = GlobalGameManager().getVFSSearchPaths();

PathList pathVector;
Expand All @@ -55,26 +57,26 @@ GameInterface::PathList GameInterface::getVFSSearchPaths() {
}

// IScriptInterface implementation
void GameInterface::registerInterface(boost::python::object& nspace)
void GameInterface::registerInterface(py::module& scope, py::dict& globals)
{
// Add the Game object declaration
nspace["Game"] = boost::python::class_<ScriptGame>("Game", boost::python::init<const game::IGamePtr&>())
.def("getKeyValue", &ScriptGame::getKeyValue)
;
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
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)
;
py::class_<GameInterface> gameManager(scope, "GameManager");

gameManager.def("getUserEnginePath", &GameInterface::getUserEnginePath);
gameManager.def("getModPath", &GameInterface::getModPath);
gameManager.def("getModBasePath", &GameInterface::getModBasePath);
gameManager.def("getFSGame", &GameInterface::getFSGame);
gameManager.def("getFSGameBase", &GameInterface::getFSGameBase);
gameManager.def("currentGame", &GameInterface::currentGame);
gameManager.def("getVFSSearchPaths", &GameInterface::getVFSSearchPaths);

// Now point the Python variable "GlobalGameManager" to this instance
nspace["GlobalGameManager"] = boost::python::ptr(this);
globals["GlobalGameManager"] = this;
}

} // namespace script
12 changes: 4 additions & 8 deletions plugins/script/interfaces/GameInterface.h
@@ -1,13 +1,12 @@
#ifndef _GAME_INTERFACE_H_
#define _GAME_INTERFACE_H_
#pragma once

#include <boost/python.hpp>
#include "iscript.h"

#include "igame.h"
#include <vector>

namespace script {
namespace script
{

class ScriptGame
{
Expand All @@ -34,10 +33,7 @@ class GameInterface :
PathList getVFSSearchPaths();

// IScriptInterface implementation
void registerInterface(boost::python::object& nspace);
void registerInterface(py::module& scope, py::dict& globals) override;
};
typedef std::shared_ptr<GameInterface> GameInterfacePtr;

} // namespace script

#endif /* _GAME_INTERFACE_H_ */

0 comments on commit 1cca241

Please sign in to comment.