1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-28 13:09:42 +00:00

[Lua] Add nearby.players and world.players

This commit is contained in:
Petr Mikheev 2023-06-17 19:56:25 +02:00
parent 0b9bcf58e2
commit 9d15629ae2
6 changed files with 15 additions and 0 deletions

View file

@ -222,6 +222,7 @@ namespace MWLua
addTimeBindings(api, context, true);
addCellGetters(api, context);
api["activeActors"] = GObjectList{ worldView->getActorsInScene() };
api["players"] = GObjectList{ worldView->getPlayers() };
api["createObject"] = [](std::string_view recordId, sol::optional<int> count) -> GObject {
// Doesn't matter which cell to use because the new object will be in disabled state.
MWWorld::CellStore* cell = MWBase::Environment::get().getWorldScene()->getCurrentCell();

View file

@ -246,6 +246,7 @@ namespace MWLua
return;
if (!mPlayer.isEmpty())
throw std::logic_error("Player is initialized twice");
mWorldView.setPlayer(ptr);
mWorldView.objectAddedToScene(ptr);
mPlayer = ptr;
LocalScripts* localScripts = ptr.getRefData().getLuaScripts();

View file

@ -136,6 +136,7 @@ namespace MWLua
api["containers"] = LObjectList{ worldView->getContainersInScene() };
api["doors"] = LObjectList{ worldView->getDoorsInScene() };
api["items"] = LObjectList{ worldView->getItemsInScene() };
api["players"] = LObjectList{ worldView->getPlayers() };
api["NAVIGATOR_FLAGS"]
= LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, DetourNavigator::Flag>({

View file

@ -51,10 +51,13 @@ namespace MWLua
ObjectIdList getContainersInScene() const { return mContainersInScene.mList; }
ObjectIdList getDoorsInScene() const { return mDoorsInScene.mList; }
ObjectIdList getItemsInScene() const { return mItemsInScene.mList; }
ObjectIdList getPlayers() const { return mPlayers; }
void objectAddedToScene(const MWWorld::Ptr& ptr);
void objectRemovedFromScene(const MWWorld::Ptr& ptr);
void setPlayer(const MWWorld::Ptr& player) { *mPlayers = { getId(player) }; }
void load(ESM::ESMReader& esm);
void save(ESM::ESMWriter& esm) const;
@ -78,6 +81,7 @@ namespace MWLua
ObjectGroup mContainersInScene;
ObjectGroup mDoorsInScene;
ObjectGroup mItemsInScene;
ObjectIdList mPlayers = std::make_shared<std::vector<ObjectId>>();
double mSimulationTime = 0;
bool mPaused = false;

View file

@ -26,6 +26,10 @@
-- Everything that can be picked up in the nearby.
-- @field [parent=#nearby] openmw.core#ObjectList items
---
-- List of nearby players. Currently (since multiplayer is not yet implemented) always has one element.
-- @field [parent=#nearby] openmw.core#ObjectList players
---
-- Return an object by RefNum/FormId.
-- Note: the function always returns @{openmw.core#GameObject} and doesn't validate that

View file

@ -10,6 +10,10 @@
-- List of currently active actors.
-- @field [parent=#world] openmw.core#ObjectList activeActors
---
-- List of players. Currently (since multiplayer is not yet implemented) always has one element.
-- @field [parent=#world] openmw.core#ObjectList players
---
-- Loads a named cell
-- @function [parent=#world] getCellByName