From 7dbccc914a146cee05ad5330864f35bd96c9b6c7 Mon Sep 17 00:00:00 2001 From: kuyondo Date: Fri, 20 May 2022 06:03:12 +0800 Subject: [PATCH] no skill returns nil --- apps/openmw/mwlua/types/book.cpp | 10 ++++-- files/lua_api/openmw/types.lua | 56 ++++++++++++++++---------------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/apps/openmw/mwlua/types/book.cpp b/apps/openmw/mwlua/types/book.cpp index 597c1a07a0..3fcdbec86d 100644 --- a/apps/openmw/mwlua/types/book.cpp +++ b/apps/openmw/mwlua/types/book.cpp @@ -19,7 +19,7 @@ namespace MWLua sol::table skill(context.mLua->sol(), sol::create); book["SKILL"] = LuaUtil::makeStrictReadOnly(skill); for (int id = ESM::Skill::Block; id < ESM::Skill::Length; ++id) - skill[(ESM::Skill::sSkillNames[id])] = id; + skill[Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[id])] = Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[id]); const MWWorld::Store* store = &MWBase::Environment::get().getWorld()->getStore().get(); book["record"] = sol::overload( @@ -35,9 +35,15 @@ namespace MWLua 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; }); + record["skill"] = sol::readonly_property([](const ESM::Book& rec) -> sol::optional + { + if (rec.mData.mSkillId >= 0) + return Misc::StringUtils::lowerCase(ESM::Skill::sSkillNames[rec.mData.mSkillId]); + else + return sol::nullopt; + }); } } diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index d7a917711b..d9a4d36439 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -534,33 +534,33 @@ --- 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 +-- @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 @@ -582,7 +582,7 @@ -- @field #string text The text content of the book -- @field #number weight -- @field #number value --- @field #number skill See @{#Book.SKILL} The skill that this book teaches +-- @field #string skill The skill that this book teaches. See @{#Book.SKILL} -- @field #boolean isScroll -- @field #number enchantCapacity