mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-21 18:40:01 +00:00
Add get and set birth sign
This commit is contained in:
parent
f7aa9f8d94
commit
f114d409c8
@ -8,7 +8,11 @@
|
||||
#include "apps/openmw/mwbase/world.hpp"
|
||||
#include "apps/openmw/mwmechanics/npcstats.hpp"
|
||||
#include "apps/openmw/mwworld/class.hpp"
|
||||
#include "apps/openmw/mwworld/esmstore.hpp"
|
||||
#include "apps/openmw/mwworld/globals.hpp"
|
||||
#include "apps/openmw/mwworld/player.hpp"
|
||||
|
||||
#include <components/esm3/loadbsgn.hpp>
|
||||
|
||||
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
|
||||
{
|
||||
static void verifyPlayer(const Object& player)
|
||||
@ -173,5 +191,15 @@ namespace MWLua
|
||||
};
|
||||
|
||||
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.
|
||||
-- @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
|
||||
-- @field [parent=#Player] #BirthSigns birthSigns
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user