Skip to content

Commit

Permalink
Expose load_current_load_order_state() via GameInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Nov 4, 2017
1 parent 5357858 commit 1275a11
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
17 changes: 15 additions & 2 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,26 @@ Functions
Initialise the current global locale using the given ID. Wraps
:cpp:func:`loot::InitialiseLocale`.

.. py:function:: loot_api.create_database(game : loot_api.GameType, [game_path : unicode = u'', [game_local_path : unicode = u'']]) -> loot_api.DatabaseInterface
.. py:function:: loot_api.create_game_handle(game : loot_api.GameType, [game_path : unicode = u'', [game_local_path : unicode = u'']]) -> loot_api.GameInterface
Initialise a new database handle. Wraps :cpp:func:`loot::CreateDatabase`.
Initialise a new game handle. Wraps :cpp:func:`loot::CreateGameHandle`.

Classes
=======

.. py:class:: loot_api.GameInterface
Wraps :cpp:class:`loot::GameInterface`.

.. py:function:: loot_api.get_database() -> loot_api.DatabaseInterface
Get a database handle. Wraps :cpp:func:`loot::GetDatabase`.

.. py:function:: loot_api.load_current_load_order_state() -> NoneType
Load the current load order state, discarding any previously held state.
Wraps :cpp:func:`loot::LoadCurrentLoadOrderState`.

.. py:class:: loot_api.DatabaseInterface
Wraps :cpp:class:`loot::DatabaseInterface`.
Expand Down
5 changes: 0 additions & 5 deletions src/convenience.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ along with LOOT. If not, see
#include <loot/api.h>

namespace loot {
std::shared_ptr<DatabaseInterface> CreateDatabase(const GameType game, const std::string & game_path, const std::string & game_local_path) {
auto gameHandle = CreateGameHandle(game, game_path, game_local_path);

return gameHandle->GetDatabase();
}
PluginTags GetPluginTags(const std::shared_ptr<DatabaseInterface> db, const std::string& plugin, bool evaluateConditions) {
PluginTags tags;

Expand Down
4 changes: 0 additions & 4 deletions src/convenience.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ along with LOOT. If not, see
#include "plugin_tags.h"

namespace loot {
std::shared_ptr<DatabaseInterface> CreateDatabase(const GameType game,
const std::string& game_path = "",
const std::string& game_local_path = "");

PluginTags GetPluginTags(const std::shared_ptr<DatabaseInterface> db,
const std::string& plugin,
bool evaluateConditions = false);
Expand Down
9 changes: 8 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ void bindVersionClasses(pybind11::module& module) {
}

void bindInterfaceClasses(pybind11::module& module) {
class_<GameInterface, std::shared_ptr<GameInterface>>(module, "GameInterface")
.def("load_current_load_order_state", &GameInterface::LoadCurrentLoadOrderState)
.def("get_database", &GameInterface::GetDatabase);

class_<DatabaseInterface, std::shared_ptr<DatabaseInterface>>(module, "DatabaseInterface")
.def("load_lists", &DatabaseInterface::LoadLists, arg("masterlist_path"), arg("userlist_path") = "")
.def("update_masterlist", &DatabaseInterface::UpdateMasterlist)
Expand Down Expand Up @@ -133,7 +137,10 @@ void bindFunctions(pybind11::module& module) {

module.def("initialise_locale", &InitialiseLocale);

module.def("create_database", &CreateDatabase, arg("game"), arg("game_path") = "", arg("game_local_path") = "");
module.def("create_game_handle", &CreateGameHandle,
arg("game"),
arg("game_path") = "",
arg("game_local_path") = "");
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from loot_api import GameType
from loot_api import SimpleMessage
from loot_api import MessageType
from loot_api import create_database
from loot_api import create_game_handle
from loot_api import is_compatible
from loot_api import set_logging_callback
from loot_api import initialise_locale
Expand Down Expand Up @@ -58,7 +58,8 @@ def test_wrapper_version(self):
self.assertEqual(WrapperVersion.string(), "3.0.0")

def test_create_db(self):
db = create_database(GameType.tes4, self.game_path, self.local_path)
game = create_game_handle(GameType.tes4, self.game_path, self.local_path)
db = game.get_database()
self.assertNotEqual(db, None)

class TestDatabaseInterface(GameFixture):
Expand All @@ -67,7 +68,10 @@ class TestDatabaseInterface(GameFixture):
def setUp(self):
super(TestDatabaseInterface, self).setUp()

self.db = create_database(GameType.tes4, self.game_path, self.local_path)
game = create_game_handle(GameType.tes4, self.game_path, self.local_path)
game.load_current_load_order_state()

self.db = game.get_database()

def test_load_lists(self):
self.db.load_lists(self.masterlist_path, u'')
Expand Down

0 comments on commit 1275a11

Please sign in to comment.