mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-27 06:11:34 +00:00
Add get and set birth sign
This commit is contained in:
parent
f7aa9f8d94
commit
f114d409c8
2 changed files with 39 additions and 0 deletions
|
@ -8,7 +8,11 @@
|
||||||
#include "apps/openmw/mwbase/world.hpp"
|
#include "apps/openmw/mwbase/world.hpp"
|
||||||
#include "apps/openmw/mwmechanics/npcstats.hpp"
|
#include "apps/openmw/mwmechanics/npcstats.hpp"
|
||||||
#include "apps/openmw/mwworld/class.hpp"
|
#include "apps/openmw/mwworld/class.hpp"
|
||||||
|
#include "apps/openmw/mwworld/esmstore.hpp"
|
||||||
#include "apps/openmw/mwworld/globals.hpp"
|
#include "apps/openmw/mwworld/globals.hpp"
|
||||||
|
#include "apps/openmw/mwworld/player.hpp"
|
||||||
|
|
||||||
|
#include <components/esm3/loadbsgn.hpp>
|
||||||
|
|
||||||
namespace MWLua
|
namespace MWLua
|
||||||
{
|
{
|
||||||
|
@ -35,6 +39,20 @@ namespace sol
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
ESM::RefId toBirthSignId(const sol::object& recordOrId)
|
||||||
|
{
|
||||||
|
if (recordOrId.is<ESM::BirthSign>())
|
||||||
|
return recordOrId.as<const ESM::BirthSign*>()->mId;
|
||||||
|
std::string_view textId = LuaUtil::cast<std::string_view>(recordOrId);
|
||||||
|
ESM::RefId id = ESM::RefId::deserializeText(textId);
|
||||||
|
if (!MWBase::Environment::get().getESMStore()->get<ESM::BirthSign>().search(id))
|
||||||
|
throw std::runtime_error("Failed to find birth sign: " + std::string(textId));
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWLua
|
namespace MWLua
|
||||||
{
|
{
|
||||||
static void verifyPlayer(const Object& player)
|
static void verifyPlayer(const Object& player)
|
||||||
|
@ -173,5 +191,15 @@ namespace MWLua
|
||||||
};
|
};
|
||||||
|
|
||||||
player["birthSigns"] = initCoreBirthSignBindings(context);
|
player["birthSigns"] = initCoreBirthSignBindings(context);
|
||||||
|
player["getBirthSign"] = [](const Object& player) -> std::string {
|
||||||
|
verifyPlayer(player);
|
||||||
|
return MWBase::Environment::get().getWorld()->getPlayer().getBirthSign().serializeText();
|
||||||
|
};
|
||||||
|
player["setBirthSign"] = [](const Object& player, const sol::object& recordOrId) {
|
||||||
|
verifyPlayer(player);
|
||||||
|
if (!dynamic_cast<const GObject*>(&player))
|
||||||
|
throw std::runtime_error("Only global scripts can change birth signs");
|
||||||
|
MWBase::Environment::get().getWorld()->getPlayer().setBirthSign(toBirthSignId(recordOrId));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1045,6 +1045,17 @@
|
||||||
-- Values that can be used with getControlSwitch/setControlSwitch.
|
-- Values that can be used with getControlSwitch/setControlSwitch.
|
||||||
-- @field [parent=#Player] #CONTROL_SWITCH CONTROL_SWITCH
|
-- @field [parent=#Player] #CONTROL_SWITCH CONTROL_SWITCH
|
||||||
|
|
||||||
|
---
|
||||||
|
-- @function [parent=#Player] getBirthSign
|
||||||
|
-- @param openmw.core#GameObject player
|
||||||
|
-- @return #string The player's birth sign
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Can be used only in global scripts. Note that this does not update the player's spells.
|
||||||
|
-- @function [parent=#Player] setBirthSign
|
||||||
|
-- @param openmw.core#GameObject player
|
||||||
|
-- @param #any recordOrId Record or string ID of the birth sign to assign
|
||||||
|
|
||||||
--- @{#BirthSigns}: Birth Sign Data
|
--- @{#BirthSigns}: Birth Sign Data
|
||||||
-- @field [parent=#Player] #BirthSigns birthSigns
|
-- @field [parent=#Player] #BirthSigns birthSigns
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue