1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00
OpenMW/apps/openmw/mwlua/luabindings.cpp

58 lines
2.1 KiB
C++
Raw Normal View History

2020-12-18 23:21:10 +01:00
#include "luabindings.hpp"
#include <components/lua/luastate.hpp>
#include "eventqueue.hpp"
#include "worldview.hpp"
namespace MWLua
{
2021-01-29 01:54:54 +01:00
static sol::table definitionList(LuaUtil::LuaState& lua, std::initializer_list<std::string> values)
{
sol::table res(lua.sol(), sol::create);
for (const std::string& v : values)
res[v] = v;
return lua.makeReadOnly(res);
}
2020-12-18 23:21:10 +01:00
sol::table initCorePackage(const Context& context)
{
sol::table api(context.mLua->sol(), sol::create);
api["sendGlobalEvent"] = [context](std::string eventName, const sol::object& eventData)
{
context.mGlobalEventQueue->push_back({std::move(eventName), LuaUtil::serialize(eventData, context.mSerializer)});
};
2021-03-12 18:29:51 +01:00
api["getGameTimeInSeconds"] = [world=context.mWorldView]() { return world->getGameTimeInSeconds(); };
api["getGameTimeInHours"] = [world=context.mWorldView]() { return world->getGameTimeInHours(); };
2021-01-29 01:54:54 +01:00
api["OBJECT_TYPE"] = definitionList(*context.mLua,
{
"Activator", "Armor", "Book", "Clothing", "Creature", "Door", "Ingredient",
"Light", "Miscellaneous", "NPC", "Player", "Potion", "Static", "Weapon"
});
2020-12-18 23:21:10 +01:00
return context.mLua->makeReadOnly(api);
}
sol::table initWorldPackage(const Context& context)
{
sol::table api(context.mLua->sol(), sol::create);
WorldView* worldView = context.mWorldView;
api["activeActors"] = GObjectList{worldView->getActorsInScene()};
return context.mLua->makeReadOnly(api);
}
sol::table initNearbyPackage(const Context& context)
{
sol::table api(context.mLua->sol(), sol::create);
WorldView* worldView = context.mWorldView;
2021-01-29 01:54:54 +01:00
api["activators"] = LObjectList{worldView->getActivatorsInScene()};
2020-12-18 23:21:10 +01:00
api["actors"] = LObjectList{worldView->getActorsInScene()};
2021-01-29 01:54:54 +01:00
api["containers"] = LObjectList{worldView->getContainersInScene()};
api["doors"] = LObjectList{worldView->getDoorsInScene()};
2020-12-18 23:21:10 +01:00
api["items"] = LObjectList{worldView->getItemsInScene()};
return context.mLua->makeReadOnly(api);
}
}