mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 20:29:57 +00:00
Lua door opening api
This commit is contained in:
parent
5553b00b84
commit
1abe28e797
2 changed files with 106 additions and 25 deletions
|
@ -1,5 +1,7 @@
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
|
|
||||||
|
#include "../localscripts.hpp"
|
||||||
|
|
||||||
#include <components/esm3/loaddoor.hpp>
|
#include <components/esm3/loaddoor.hpp>
|
||||||
#include <components/esm4/loaddoor.hpp>
|
#include <components/esm4/loaddoor.hpp>
|
||||||
#include <components/lua/util.hpp>
|
#include <components/lua/util.hpp>
|
||||||
|
@ -8,6 +10,7 @@
|
||||||
#include <components/misc/resourcehelpers.hpp>
|
#include <components/misc/resourcehelpers.hpp>
|
||||||
#include <components/resource/resourcesystem.hpp>
|
#include <components/resource/resourcesystem.hpp>
|
||||||
|
|
||||||
|
#include "apps/openmw/mwworld/class.hpp"
|
||||||
#include "apps/openmw/mwworld/worldmodel.hpp"
|
#include "apps/openmw/mwworld/worldmodel.hpp"
|
||||||
|
|
||||||
namespace sol
|
namespace sol
|
||||||
|
@ -38,6 +41,45 @@ namespace MWLua
|
||||||
|
|
||||||
void addDoorBindings(sol::table door, const Context& context)
|
void addDoorBindings(sol::table door, const Context& context)
|
||||||
{
|
{
|
||||||
|
door["STATE"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, MWWorld::DoorState>({
|
||||||
|
{ "Idle", MWWorld::DoorState::Idle },
|
||||||
|
{ "Opening", MWWorld::DoorState::Opening },
|
||||||
|
{ "Closing", MWWorld::DoorState::Closing },
|
||||||
|
}));
|
||||||
|
door["getDoorState"] = [](const Object& o) -> MWWorld::DoorState {
|
||||||
|
auto door = doorPtr(o);
|
||||||
|
return door.getClass().getDoorState(door);
|
||||||
|
};
|
||||||
|
door["isOpen"] = [](const Object& o) {
|
||||||
|
auto door = doorPtr(o);
|
||||||
|
bool doorIsIdle = door.getClass().getDoorState(door) == MWWorld::DoorState::Idle;
|
||||||
|
bool doorIsOpen = door.getRefData().getPosition().rot[2] != door.getCellRef().getPosition().rot[2];
|
||||||
|
|
||||||
|
return doorIsIdle && doorIsOpen;
|
||||||
|
};
|
||||||
|
door["isClosed"] = [](const Object& o) {
|
||||||
|
auto door = doorPtr(o);
|
||||||
|
bool doorIsIdle = door.getClass().getDoorState(door) == MWWorld::DoorState::Idle;
|
||||||
|
bool doorIsOpen = door.getRefData().getPosition().rot[2] != door.getCellRef().getPosition().rot[2];
|
||||||
|
|
||||||
|
return doorIsIdle && !doorIsOpen;
|
||||||
|
};
|
||||||
|
door["activateDoor"] = [](const Object& o, sol::optional<bool> openState) {
|
||||||
|
bool allowChanges
|
||||||
|
= dynamic_cast<const GObject*>(&o) != nullptr || dynamic_cast<const SelfObject*>(&o) != nullptr;
|
||||||
|
if (!allowChanges)
|
||||||
|
throw std::runtime_error("Can only be used in global scripts or in local scripts on self.");
|
||||||
|
|
||||||
|
auto door = doorPtr(o);
|
||||||
|
auto world = MWBase::Environment::get().getWorld();
|
||||||
|
|
||||||
|
if (!openState.has_value())
|
||||||
|
world->activateDoor(door);
|
||||||
|
else if (*openState)
|
||||||
|
world->activateDoor(door, MWWorld::DoorState::Opening);
|
||||||
|
else
|
||||||
|
world->activateDoor(door, MWWorld::DoorState::Closing);
|
||||||
|
};
|
||||||
door["isTeleport"] = [](const Object& o) { return doorPtr(o).getCellRef().getTeleport(); };
|
door["isTeleport"] = [](const Object& o) { return doorPtr(o).getCellRef().getTeleport(); };
|
||||||
door["destPosition"]
|
door["destPosition"]
|
||||||
= [](const Object& o) -> osg::Vec3f { return doorPtr(o).getCellRef().getDoorDest().asVec3(); };
|
= [](const Object& o) -> osg::Vec3f { return doorPtr(o).getCellRef().getDoorDest().asVec3(); };
|
||||||
|
|
|
@ -2123,6 +2123,16 @@
|
||||||
-- @extends #Lockable
|
-- @extends #Lockable
|
||||||
-- @field #Lockable baseType @{#Lockable}
|
-- @field #Lockable baseType @{#Lockable}
|
||||||
|
|
||||||
|
--- Door.STATE
|
||||||
|
-- @type DoorSTATE
|
||||||
|
-- @field #number Idle The door is either closed or open (usually closed).
|
||||||
|
-- @field #number Opening The door is in the process of opening.
|
||||||
|
-- @field #number Closing The door is in the process of closing.
|
||||||
|
|
||||||
|
--- @{#DoorSTATE}
|
||||||
|
-- @field [parent=#Door] #DoorSTATE STATE
|
||||||
|
-- @usage local state = types.Door.STATE["Idle"]
|
||||||
|
|
||||||
---
|
---
|
||||||
-- A read-only list of all @{#DoorRecord}s in the world database.
|
-- A read-only list of all @{#DoorRecord}s in the world database.
|
||||||
-- Implements [iterables#List](iterables.html#List) of #DoorRecord.
|
-- Implements [iterables#List](iterables.html#List) of #DoorRecord.
|
||||||
|
@ -2166,6 +2176,35 @@
|
||||||
-- @param #any objectOrRecordId
|
-- @param #any objectOrRecordId
|
||||||
-- @return #DoorRecord
|
-- @return #DoorRecord
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Gets the state of the door.
|
||||||
|
-- @function [parent=#Door] getDoorState
|
||||||
|
-- @param openmw.core#GameObject object
|
||||||
|
-- @return #DoorSTATE
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Checks if the door is fully open.
|
||||||
|
-- Returns false if the door is currently opening or closing.
|
||||||
|
-- @function [parent=#Door] isOpen
|
||||||
|
-- @param openmw.core#GameObject object
|
||||||
|
-- @return #boolean
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Checks if the door is fully closed.
|
||||||
|
-- Returns false if the door is currently opening or closing.
|
||||||
|
-- @function [parent=#Door] isClosed
|
||||||
|
-- @param openmw.core#GameObject object
|
||||||
|
-- @return #boolean
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Opens/Closes the door. Can only be used in global scripts or on self.
|
||||||
|
-- @function [parent=#Door] activateDoor
|
||||||
|
-- @param openmw.core#GameObject object
|
||||||
|
-- @param #boolean openState Optional whether the door should be opened or closed. If not provided, the door will switch to the opposite state.
|
||||||
|
-- @usage types.Door.activateDoor(doorObject)
|
||||||
|
-- @usage types.Door.activateDoor(doorObject, true)
|
||||||
|
-- @usage types.Door.activateDoor(doorObject, false)
|
||||||
|
|
||||||
---
|
---
|
||||||
-- @type DoorRecord
|
-- @type DoorRecord
|
||||||
-- @field #string id Record id
|
-- @field #string id Record id
|
||||||
|
|
Loading…
Reference in a new issue