Merge branch 'bookluabinds' into 'master'

Lua API for Book records

See merge request OpenMW/openmw!1886
openmw-fix_osx_build_maybe
psi29a 3 years ago
commit 67421a400a

@ -62,7 +62,7 @@ add_openmw_dir (mwlua
luamanagerimp object worldview userdataserializer eventqueue
luabindings localscripts playerscripts objectbindings cellbindings asyncbindings settingsbindings
camerabindings uibindings inputbindings nearbybindings postprocessingbindings stats debugbindings
types/types types/door types/actor types/container types/weapon types/npc types/creature types/activator
types/types types/door types/actor types/container types/weapon types/npc types/creature types/activator types/book
)
add_openmw_dir (mwsound

@ -0,0 +1,52 @@
#include "types.hpp"
#include <components/esm3/loadbook.hpp>
#include <apps/openmw/mwworld/esmstore.hpp>
#include "../luabindings.hpp"
namespace sol
{
template <>
struct is_automagical<ESM::Book> : std::false_type {};
}
namespace MWLua
{
void addBookBindings(sol::table book, const Context& context)
{
sol::table skill(context.mLua->sol(), sol::create);
book["SKILL"] = LuaUtil::makeStrictReadOnly(skill);
for (int id = ESM::Skill::Block; id < ESM::Skill::Length; ++id)
{
std::string skillName = Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[id]);
skill[skillName] = skillName;
}
const MWWorld::Store<ESM::Book>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Book>();
book["record"] = sol::overload(
[](const Object& obj) -> const ESM::Book* { return obj.ptr().get<ESM::Book>()->mBase; },
[store](const std::string& recordId) -> const ESM::Book* { return store->find(recordId); });
sol::usertype<ESM::Book> record = context.mLua->sol().new_usertype<ESM::Book>("ESM3_Book");
record[sol::meta_function::to_string] = [](const ESM::Book& rec) { return "ESM3_Book[" + rec.mId + "]"; };
record["id"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mId; });
record["name"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mModel; });
record["mwscript"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mScript; });
record["icon"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mIcon; });
record["text"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mText; });
record["enchant"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mEnchant; });
record["isScroll"] = sol::readonly_property([](const ESM::Book& rec) -> bool { return rec.mData.mIsScroll; });
record["value"] = sol::readonly_property([](const ESM::Book& rec) -> int { return rec.mData.mValue; });
record["weight"] = sol::readonly_property([](const ESM::Book& rec) -> float { return rec.mData.mWeight; });
record["enchantCapacity"] = sol::readonly_property([](const ESM::Book& rec) -> float { return rec.mData.mEnchant * 0.1f; });
record["skill"] = sol::readonly_property([](const ESM::Book& rec) -> sol::optional<std::string>
{
if (rec.mData.mSkillId >= 0)
return Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[rec.mData.mSkillId]);
else
return sol::nullopt;
});
}
}

@ -160,7 +160,6 @@ namespace MWLua
addType(ObjectTypeName::Player, {ESM::REC_INTERNAL_PLAYER}, ObjectTypeName::NPC);
addType(ObjectTypeName::Armor, {ESM::REC_ARMO}, ObjectTypeName::Item);
addType(ObjectTypeName::Book, {ESM::REC_BOOK}, ObjectTypeName::Item);
addType(ObjectTypeName::Clothing, {ESM::REC_CLOT}, ObjectTypeName::Item);
addType(ObjectTypeName::Ingredient, {ESM::REC_INGR}, ObjectTypeName::Item);
addType(ObjectTypeName::Light, {ESM::REC_LIGH}, ObjectTypeName::Item);
@ -173,6 +172,7 @@ namespace MWLua
addType(ObjectTypeName::Repair, {ESM::REC_REPA}, ObjectTypeName::Item);
addActivatorBindings(addType(ObjectTypeName::Activator, {ESM::REC_ACTI}), context);
addBookBindings(addType(ObjectTypeName::Book, {ESM::REC_BOOK}), context);
addContainerBindings(addType(ObjectTypeName::Container, {ESM::REC_CONT}), context);
addDoorBindings(addType(ObjectTypeName::Door, {ESM::REC_DOOR}), context);
addType(ObjectTypeName::Static, {ESM::REC_STAT});

@ -25,6 +25,7 @@ namespace MWLua
// used in initTypesPackage
void addActivatorBindings(sol::table activator, const Context& context);
void addBookBindings(sol::table book, const Context& context);
void addContainerBindings(sol::table container, const Context& context);
void addDoorBindings(sol::table door, const Context& context);
void addActorBindings(sol::table actor, const Context& context);

@ -55,7 +55,7 @@ namespace MWLua
record["health"] = sol::readonly_property([](const ESM::Weapon& rec) -> int { return rec.mData.mHealth; });
record["speed"] = sol::readonly_property([](const ESM::Weapon& rec) -> float { return rec.mData.mSpeed; });
record["reach"] = sol::readonly_property([](const ESM::Weapon& rec) -> float { return rec.mData.mReach; });
record["enchant"] = sol::readonly_property([](const ESM::Weapon& rec) -> float { return rec.mData.mEnchant * 0.1f; });
record["enchantCapacity"] = sol::readonly_property([](const ESM::Weapon& rec) -> float { return rec.mData.mEnchant * 0.1f; });
record["chopMinDamage"] = sol::readonly_property([](const ESM::Weapon& rec) -> int { return rec.mData.mChop[0]; });
record["chopMaxDamage"] = sol::readonly_property([](const ESM::Weapon& rec) -> int { return rec.mData.mChop[1]; });
record["slashMinDamage"] = sol::readonly_property([](const ESM::Weapon& rec) -> int { return rec.mData.mSlash[0]; });

@ -532,6 +532,60 @@
-- @param openmw.core#GameObject object
-- @return #boolean
--- Book.SKILL
-- @type BookSKILL
-- @field #string acrobatics "acrobatics"
-- @field #string alchemy "alchemy"
-- @field #string alteration "alteration"
-- @field #string armorer "armorer"
-- @field #string athletics "athletics"
-- @field #string axe "axe"
-- @field #string block "block"
-- @field #string bluntWeapon "bluntweapon"
-- @field #string conjuration "conjuration"
-- @field #string destruction "destruction"
-- @field #string enchant "enchant"
-- @field #string handToHand "handtohand"
-- @field #string heavyArmor "heavyarmor"
-- @field #string illusion "illusion"
-- @field #string lightArmor "lightarmor"
-- @field #string longBlade "longblade"
-- @field #string marksman "marksman"
-- @field #string mediumArmor "mediumarmor"
-- @field #string mercantile "mercantile"
-- @field #string mysticism "mysticism"
-- @field #string restoration "restoration"
-- @field #string security "security"
-- @field #string shortBlade "shortblade"
-- @field #string sneak "sneak"
-- @field #string spear "spear"
-- @field #string speechcraft "speechcraft"
-- @field #string unarmored "unarmored"
--- @{#BookSKILL}
-- @field [parent=#Book] #BookSKILL SKILL
---
-- Returns the read-only @{#BookRecord} of a book
-- @function [parent=#Book] record
-- @param #any objectOrRecordId
-- @return #BookRecord
---
-- @type BookRecord
-- @field #string id The record ID of the book
-- @field #string name Name of the book
-- @field #string model VFS path to the model
-- @field #string mwscript MWScript on this book (can be empty)
-- @field #string icon VFS path to the icon
-- @field #string enchant The enchantment ID of this book (can be empty)
-- @field #string text The text content of the book
-- @field #number weight
-- @field #number value
-- @field #string skill The skill that this book teaches. See @{#Book.SKILL}
-- @field #boolean isScroll
-- @field #number enchantCapacity
--- @{#Clothing} functions
@ -670,7 +724,7 @@
-- @field #number health
-- @field #number speed
-- @field #number reach
-- @field #number enchant
-- @field #number enchantCapacity
-- @field #number chopMinDamage
-- @field #number chopMaxDamage
-- @field #number slashMinDamage

Loading…
Cancel
Save