mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-19 19:39:41 +00:00
Add lua binding for books
This commit is contained in:
parent
43f4a0cfc5
commit
cad68a5566
5 changed files with 125 additions and 1 deletions
|
@ -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
|
||||
|
|
68
apps/openmw/mwlua/types/book.cpp
Normal file
68
apps/openmw/mwlua/types/book.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
#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)
|
||||
{
|
||||
book["SKILL"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, int>({
|
||||
{"Acrobatics", ESM::Skill::Acrobatics},
|
||||
{"Alchemy", ESM::Skill::Alchemy},
|
||||
{"Alteration", ESM::Skill::Alteration},
|
||||
{"Armorer", ESM::Skill::Armorer},
|
||||
{"Athletics", ESM::Skill::Athletics},
|
||||
{"Axe", ESM::Skill::Axe},
|
||||
{"Block", ESM::Skill::Block},
|
||||
{"BluntWeapon", ESM::Skill::BluntWeapon},
|
||||
{"Conjuration", ESM::Skill::Conjuration},
|
||||
{"Destruction", ESM::Skill::Destruction},
|
||||
{"Enchant", ESM::Skill::Enchant},
|
||||
{"HandToHand", ESM::Skill::HandToHand},
|
||||
{"HeavyArmor", ESM::Skill::HeavyArmor},
|
||||
{"Illusion", ESM::Skill::Illusion},
|
||||
{"LightArmor", ESM::Skill::LightArmor},
|
||||
{"LongBlade", ESM::Skill::LongBlade},
|
||||
{"Marksman", ESM::Skill::Marksman},
|
||||
{"MediumArmor", ESM::Skill::MediumArmor},
|
||||
{"Mercantile", ESM::Skill::Mercantile},
|
||||
{"Mysticism", ESM::Skill::Mysticism},
|
||||
{"Restoration", ESM::Skill::Restoration},
|
||||
{"Security", ESM::Skill::Security},
|
||||
{"ShortBlade", ESM::Skill::ShortBlade},
|
||||
{"Sneak", ESM::Skill::Sneak},
|
||||
{"Spear", ESM::Skill::Spear},
|
||||
{"Speechcraft", ESM::Skill::Speechcraft},
|
||||
{"Unarmored", ESM::Skill::Unarmored},
|
||||
}));
|
||||
|
||||
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["skill"] = sol::readonly_property([](const ESM::Book& rec) -> int { return rec.mData.mSkillId; });
|
||||
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; });
|
||||
}
|
||||
}
|
|
@ -173,6 +173,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);
|
||||
|
|
|
@ -532,6 +532,60 @@
|
|||
-- @param openmw.core#GameObject object
|
||||
-- @return #boolean
|
||||
|
||||
--- Book.SKILL
|
||||
-- @type BookSKILL
|
||||
-- @field #number Acrobatics
|
||||
-- @field #number Alchemy
|
||||
-- @field #number Alteration
|
||||
-- @field #number Armorer
|
||||
-- @field #number Athletics
|
||||
-- @field #number Axe
|
||||
-- @field #number Block
|
||||
-- @field #number BluntWeapon
|
||||
-- @field #number Conjuration
|
||||
-- @field #number Destruction
|
||||
-- @field #number Enchant
|
||||
-- @field #number HandToHand
|
||||
-- @field #number HeavyArmor
|
||||
-- @field #number Illusion
|
||||
-- @field #number LightArmor
|
||||
-- @field #number LongBlade
|
||||
-- @field #number Marksman
|
||||
-- @field #number MediumArmor
|
||||
-- @field #number Mercantile
|
||||
-- @field #number Mysticism
|
||||
-- @field #number Restoration
|
||||
-- @field #number Security
|
||||
-- @field #number ShortBlade
|
||||
-- @field #number Sneak
|
||||
-- @field #number Spear
|
||||
-- @field #number Speechcraft
|
||||
-- @field #number 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 #number skill See @{#Book.SKILL}
|
||||
-- @field #boolean isScroll
|
||||
-- @field #number enchantCapacity
|
||||
|
||||
--- @{#Clothing} functions
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue