Files
libloot-python/src/main.cpp
T

143 lines
5.0 KiB
C++
Raw Normal View History

2016-08-07 21:23:23 +01:00
/* LOOT
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
Fallout: New Vegas.
Copyright (C) 2012-2016 WrinklyNinja
This file is part of LOOT.
LOOT is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
LOOT is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LOOT. If not, see
<https://www.gnu.org/licenses/>.
*/
#include <loot/api.h>
#include <pybind11/pybind11.h>
2016-08-10 19:03:50 +01:00
#include <pybind11/stl.h>
2017-03-25 13:50:40 +00:00
#include "convenience.h"
#include "wrapper_version.h"
2017-03-25 13:50:40 +00:00
using pybind11::arg;
using pybind11::enum_;
using pybind11::class_;
using pybind11::metaclass;
2016-08-10 19:03:50 +01:00
2017-03-25 13:50:40 +00:00
namespace loot {
void bindEnums(pybind11::module& module) {
2016-08-19 19:46:19 +01:00
enum_<GameType>(module, "GameType")
2016-08-19 17:08:54 +01:00
.value("tes4", GameType::tes4)
.value("tes5", GameType::tes5)
2016-11-06 15:09:06 +00:00
.value("tes5se", GameType::tes5se)
2016-08-19 17:08:54 +01:00
.value("fo3", GameType::fo3)
.value("fonv", GameType::fonv)
.value("fo4", GameType::fo4);
2016-08-10 19:03:50 +01:00
2017-03-25 13:50:40 +00:00
enum_<LogVerbosity>(module, "LogVerbosity")
.value("off", LogVerbosity::off)
.value("trace", LogVerbosity::trace)
.value("warning", LogVerbosity::warning);
2016-08-16 08:12:50 +01:00
2016-08-19 19:46:19 +01:00
enum_<MessageType>(module, "MessageType")
2016-08-10 19:03:50 +01:00
.value("say", MessageType::say)
.value("warn", MessageType::warn)
.value("error", MessageType::error);
2016-08-19 19:46:19 +01:00
enum_<PluginCleanliness>(module, "PluginCleanliness")
2016-08-16 08:12:50 +01:00
.value("clean", PluginCleanliness::clean)
.value("dirty", PluginCleanliness::dirty)
.value("do_not_clean", PluginCleanliness::do_not_clean)
.value("unknown", PluginCleanliness::unknown);
2017-03-25 13:50:40 +00:00
}
2016-08-16 08:12:50 +01:00
2017-03-25 13:50:40 +00:00
void bindMetadataClasses(pybind11::module& module) {
2016-08-19 19:46:19 +01:00
class_<MasterlistInfo>(module, "MasterlistInfo")
2016-08-16 08:12:50 +01:00
.def_readwrite("revision_id", &MasterlistInfo::revision_id)
.def_readwrite("revision_date", &MasterlistInfo::revision_date)
.def_readwrite("is_modified", &MasterlistInfo::is_modified);
2017-03-25 13:50:40 +00:00
class_<SimpleMessage>(module, "SimpleMessage")
2016-08-24 19:02:18 +01:00
.def_readwrite("type", &SimpleMessage::type)
.def_readwrite("language", &SimpleMessage::language)
.def_readwrite("text", &SimpleMessage::text);
2016-08-15 20:51:24 +01:00
2016-08-19 19:46:19 +01:00
class_<PluginTags>(module, "PluginTags")
2016-08-15 20:51:24 +01:00
.def_readwrite("added", &PluginTags::added)
.def_readwrite("removed", &PluginTags::removed)
.def_readwrite("userlist_modified", &PluginTags::userlist_modified);
2017-03-25 13:50:40 +00:00
class_<PluginMetadata>(module, "PluginMetadata")
.def("get_simple_messages", &PluginMetadata::GetSimpleMessages);
}
void bindVersionClasses(pybind11::module& module) {
2017-03-20 17:50:17 +00:00
class_<LootVersion>(module, "Version", metaclass())
2016-08-10 19:03:50 +01:00
.def_readonly_static("major", &LootVersion::major)
.def_readonly_static("minor", &LootVersion::minor)
.def_readonly_static("patch", &LootVersion::patch)
2016-08-16 08:12:50 +01:00
.def_readonly_static("revision", &LootVersion::revision)
2016-10-05 19:31:23 +01:00
.def_static("string", LootVersion::string);
2016-08-10 19:03:50 +01:00
2017-03-20 17:50:17 +00:00
class_<WrapperVersion>(module, "WrapperVersion", metaclass())
.def_readonly_static("major", &WrapperVersion::major)
.def_readonly_static("minor", &WrapperVersion::minor)
.def_readonly_static("patch", &WrapperVersion::patch)
.def_readonly_static("revision", &WrapperVersion::revision)
2016-10-05 19:31:23 +01:00
.def_static("string", WrapperVersion::string);
2017-03-25 13:50:40 +00:00
}
2017-03-25 13:50:40 +00:00
void bindInterfaceClasses(pybind11::module& module) {
2016-08-19 19:46:19 +01:00
class_<DatabaseInterface, std::shared_ptr<DatabaseInterface>>(module, "DatabaseInterface")
2017-03-20 17:50:17 +00:00
.def("load_lists", &DatabaseInterface::LoadLists, arg("masterlist_path"), arg("userlist_path") = "")
2016-08-19 19:46:19 +01:00
.def("eval_lists", &DatabaseInterface::EvalLists)
.def("update_masterlist", &DatabaseInterface::UpdateMasterlist)
.def("get_masterlist_revision", &DatabaseInterface::GetMasterlistRevision)
2017-03-25 13:50:40 +00:00
.def("get_plugin_metadata", &DatabaseInterface::GetPluginMetadata,
arg("plugin"),
arg("includeUserMetadata") = true,
arg("evaluateConditions") = false)
.def("get_plugin_tags", &GetPluginTags)
.def("get_plugin_cleanliness", &GetPluginCleanliness)
2016-08-19 19:46:19 +01:00
.def("write_minimal_list", &DatabaseInterface::WriteMinimalList);
2017-03-25 13:50:40 +00:00
}
void bindClasses(pybind11::module& module) {
bindMetadataClasses(module);
bindVersionClasses(module);
bindInterfaceClasses(module);
}
void bindFunctions(pybind11::module& module) {
module.def("set_logging_verbosity", &SetLoggingVerbosity);
module.def("set_log_file", &SetLogFile);
2016-08-10 19:03:50 +01:00
2016-08-19 19:46:19 +01:00
module.def("is_compatible", &IsCompatible);
2016-08-10 19:03:50 +01:00
2017-03-25 13:50:40 +00:00
module.def("initialise_locale", &InitialiseLocale);
2017-03-20 17:50:17 +00:00
module.def("create_database", &CreateDatabase, arg("game"), arg("game_path") = "", arg("game_local_path") = "");
2017-03-25 13:50:40 +00:00
}
}
PYBIND11_PLUGIN(loot_api) {
pybind11::module module("loot_api", "A Python module that wraps the LOOT API, generated by pybind11.");
loot::bindEnums(module);
loot::bindClasses(module);
loot::bindFunctions(module);
2016-08-10 19:03:50 +01:00
return module.ptr();
2016-08-07 21:23:23 +01:00
}