Merge branch 'lua_getters' into 'master'

Rename some functions in Lua API from `aaa` to `getAaa` (for consistency with `setAaa`)

Closes #7356

See merge request OpenMW/openmw!3004
simplify_debugging
psi29a 2 years ago
commit 0a8c801d66

@ -68,7 +68,7 @@ namespace MWLua
{
auto* lua = context.mLua;
sol::table api(lua->sol(), sol::create);
api["API_REVISION"] = 36;
api["API_REVISION"] = 37;
api["quit"] = [lua]() {
Log(Debug::Warning) << "Quit requested by a Lua script.\n" << lua->debugTraceback();
MWBase::Environment::get().getStateManager()->requestQuit();

@ -122,13 +122,14 @@ namespace MWLua
{ "CarriedLeft", MWWorld::InventoryStore::Slot_CarriedLeft },
{ "Ammunition", MWWorld::InventoryStore::Slot_Ammunition } }));
actor["stance"] = [](const Object& o) {
actor["getStance"] = [](const Object& o) {
const MWWorld::Class& cls = o.ptr().getClass();
if (cls.isActor())
return cls.getCreatureStats(o.ptr()).getDrawState();
else
throw std::runtime_error("Actor expected");
};
actor["stance"] = actor["getStance"]; // for compatibility; should be removed later
actor["setStance"] = [](const SelfObject& self, int stance) {
const MWWorld::Class& cls = self.ptr().getClass();
if (!cls.isActor())
@ -177,19 +178,24 @@ namespace MWLua
const MWWorld::Class& cls = o.ptr().getClass();
return cls.getMaxSpeed(o.ptr()) > 0;
};
actor["runSpeed"] = [](const Object& o) {
actor["getRunSpeed"] = [](const Object& o) {
const MWWorld::Class& cls = o.ptr().getClass();
return cls.getRunSpeed(o.ptr());
};
actor["walkSpeed"] = [](const Object& o) {
actor["getWalkSpeed"] = [](const Object& o) {
const MWWorld::Class& cls = o.ptr().getClass();
return cls.getWalkSpeed(o.ptr());
};
actor["currentSpeed"] = [](const Object& o) {
actor["getCurrentSpeed"] = [](const Object& o) {
const MWWorld::Class& cls = o.ptr().getClass();
return cls.getCurrentSpeed(o.ptr());
};
// for compatibility; should be removed later
actor["runSpeed"] = actor["getRunSpeed"];
actor["walkSpeed"] = actor["getWalkSpeed"];
actor["currentSpeed"] = actor["getCurrentSpeed"];
actor["isOnGround"]
= [](const LObject& o) { return MWBase::Environment::get().getWorld()->isOnGround(o.ptr()); };
actor["isSwimming"]
@ -231,7 +237,8 @@ namespace MWLua
else
return sol::make_object(lua, LObject(*it));
};
actor["equipment"] = sol::overload(getAllEquipment, getEquipmentFromSlot);
actor["getEquipment"] = sol::overload(getAllEquipment, getEquipmentFromSlot);
actor["equipment"] = actor["getEquipment"]; // for compatibility; should be removed later
actor["hasEquipped"] = [](const Object& o, const Object& item) {
const MWWorld::Ptr& ptr = o.ptr();
if (!ptr.getClass().hasInventoryStore(ptr))

@ -38,13 +38,14 @@ namespace MWLua
object.ptr().getCellRef().setSoul(creature);
};
miscellaneous["soul"] = [](const Object& object) -> sol::optional<std::string> {
miscellaneous["getSoul"] = [](const Object& object) -> sol::optional<std::string> {
ESM::RefId soul = object.ptr().getCellRef().getSoul();
if (soul.empty())
return sol::nullopt;
else
return soul.serializeText();
};
miscellaneous["soul"] = miscellaneous["getSoul"]; // for compatibility; should be removed later
sol::usertype<ESM::Miscellaneous> record
= context.mLua->sol().new_usertype<ESM::Miscellaneous>("ESM3_Miscellaneous");
record[sol::meta_function::to_string]

@ -104,7 +104,7 @@ local function updateVanity(dt)
end
local function updateSmoothedSpeed(dt)
local speed = Actor.currentSpeed(self)
local speed = Actor.getCurrentSpeed(self)
speed = speed / (1 + speed / 500)
local maxDelta = 300 * dt
smoothedSpeed = smoothedSpeed + util.clamp(speed - smoothedSpeed, -maxDelta, maxDelta)
@ -153,7 +153,7 @@ local function updateStandingPreview()
third_person.standingPreview = false
return
end
local standingStill = Actor.currentSpeed(self) == 0 and Actor.stance(self) == Actor.STANCE.Nothing
local standingStill = Actor.getCurrentSpeed(self) == 0 and Actor.getStance(self) == Actor.STANCE.Nothing
if standingStill and mode == MODE.ThirdPerson then
third_person.standingPreview = true
camera.setMode(MODE.Preview)

@ -30,7 +30,7 @@ local sampleArc = function(x) return 1 - math.cos(x * halfArc) end
local arcHeight = sampleArc(1)
function M.update(dt, smoothedSpeed)
local speed = Actor.currentSpeed(self)
local speed = Actor.getCurrentSpeed(self)
speed = speed / (1 + speed / 500) -- limit bobbing frequency if the speed is very high
totalMovement = totalMovement + speed * dt
if not M.enabled or camera.getMode() ~= camera.MODE.FirstPerson then

@ -31,7 +31,7 @@ end
function M.onFrame(dt)
if core.isWorldPaused() then return end
local newActive = M.enabled and Actor.stance(self) == Actor.STANCE.Nothing
local newActive = M.enabled and Actor.getStance(self) == Actor.STANCE.Nothing
if newActive and not active then
turnOn()
elseif not newActive and active then

@ -85,7 +85,7 @@ end
local function updateState()
local mode = camera.getMode()
local oldState = state
if Actor.stance(self) ~= Actor.STANCE.Nothing and mode == MODE.ThirdPerson then
if Actor.getStance(self) ~= Actor.STANCE.Nothing and mode == MODE.ThirdPerson then
state = STATE.Combat
elseif Actor.isSwimming(self) then
state = STATE.Swimming
@ -94,7 +94,7 @@ local function updateState()
elseif not state then
state = defaultShoulder
end
if (mode == MODE.ThirdPerson or Actor.currentSpeed(self) > 0 or state ~= oldState or noThirdPersonLastFrame)
if (mode == MODE.ThirdPerson or Actor.getCurrentSpeed(self) > 0 or state ~= oldState or noThirdPersonLastFrame)
and (state == STATE.LeftShoulder or state == STATE.RightShoulder) then
if autoSwitchShoulder then
trySwitchShoulder()

@ -71,19 +71,19 @@
---
-- Speed of running. For dead actors it still returns a positive value.
-- @function [parent=#Actor] runSpeed
-- @function [parent=#Actor] getRunSpeed
-- @param openmw.core#GameObject actor
-- @return #number
---
-- Speed of walking. For dead actors it still returns a positive value.
-- @function [parent=#Actor] walkSpeed
-- @function [parent=#Actor] getWalkSpeed
-- @param openmw.core#GameObject actor
-- @return #number
---
-- Current speed.
-- @function [parent=#Actor] currentSpeed
-- @function [parent=#Actor] getCurrentSpeed
-- @param openmw.core#GameObject actor
-- @return #number
@ -101,7 +101,7 @@
---
-- Returns the current stance (whether a weapon/spell is readied), see the list of @{#STANCE} values.
-- @function [parent=#Actor] stance
-- @function [parent=#Actor] getStance
-- @param openmw.core#GameObject actor
-- @return #number
@ -114,7 +114,7 @@
---
-- Returns `true` if the item is equipped on the actor.
-- @function [parent=#Actor] isEquipped
-- @function [parent=#Actor] hasEquipped
-- @param openmw.core#GameObject actor
-- @param openmw.core#GameObject item
-- @return #boolean
@ -131,7 +131,7 @@
-- See @{#EQUIPMENT_SLOT}. Returns empty table if the actor doesn't have
-- equipment slots.
-- 2) With two arguments: returns an item equipped to the given slot.
-- @function [parent=#Actor] equipment
-- @function [parent=#Actor] getEquipment
-- @param openmw.core#GameObject actor
-- @param #number slot Optional number of the equipment slot
-- @return #EquipmentTable, openmw.core#GameObject
@ -848,7 +848,7 @@
---
-- Returns the read-only soul of a miscellaneous item
-- @function [parent=#Miscellaneous] soul
-- @function [parent=#Miscellaneous] getSoul
-- @param openmw.core#GameObject object
-- @return #string

Loading…
Cancel
Save