Skip to content

Commit

Permalink
Merge branch 'noscript' into 'master'
Browse files Browse the repository at this point in the history
Make mwscript return nil for records that don't have a script

See merge request OpenMW/openmw!4236
  • Loading branch information
psi29a committed Jul 9, 2024
2 parents 82f6845 + ee653eb commit 7d0fca1
Show file tree
Hide file tree
Showing 20 changed files with 95 additions and 77 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
set(OPENMW_VERSION_MAJOR 0)
set(OPENMW_VERSION_MINOR 49)
set(OPENMW_VERSION_RELEASE 0)
set(OPENMW_LUA_API_REVISION 63)
set(OPENMW_LUA_API_REVISION 64)
set(OPENMW_POSTPROCESSING_API_REVISION 1)

set(OPENMW_VERSION_COMMITHASH "")
Expand Down
6 changes: 4 additions & 2 deletions apps/openmw/mwlua/types/activator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <components/esm3/loadacti.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>

Expand Down Expand Up @@ -51,7 +52,8 @@ namespace MWLua
record["model"] = sol::readonly_property([](const ESM::Activator& rec) -> std::string {
return Misc::ResourceHelpers::correctMeshPath(rec.mModel);
});
record["mwscript"] = sol::readonly_property(
[](const ESM::Activator& rec) -> std::string { return rec.mScript.serializeText(); });
record["mwscript"] = sol::readonly_property([](const ESM::Activator& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
}
}
6 changes: 4 additions & 2 deletions apps/openmw/mwlua/types/apparatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <components/esm3/loadappa.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>

Expand Down Expand Up @@ -39,8 +40,9 @@ namespace MWLua
record["model"] = sol::readonly_property([](const ESM::Apparatus& rec) -> std::string {
return Misc::ResourceHelpers::correctMeshPath(rec.mModel);
});
record["mwscript"] = sol::readonly_property(
[](const ESM::Apparatus& rec) -> std::string { return rec.mScript.serializeText(); });
record["mwscript"] = sol::readonly_property([](const ESM::Apparatus& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
record["icon"] = sol::readonly_property([vfs](const ESM::Apparatus& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
Expand Down
12 changes: 5 additions & 7 deletions apps/openmw/mwlua/types/armor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <components/esm3/loadarmo.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>

Expand Down Expand Up @@ -98,13 +99,10 @@ namespace MWLua
record["icon"] = sol::readonly_property([vfs](const ESM::Armor& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
record["enchant"] = sol::readonly_property([](const ESM::Armor& rec) -> sol::optional<std::string> {
if (rec.mEnchant.empty())
return sol::nullopt;
return rec.mEnchant.serializeText();
});
record["mwscript"]
= sol::readonly_property([](const ESM::Armor& rec) -> std::string { return rec.mScript.serializeText(); });
record["enchant"] = sol::readonly_property(
[](const ESM::Armor& rec) -> sol::optional<std::string> { return LuaUtil::serializeRefId(rec.mEnchant); });
record["mwscript"] = sol::readonly_property(
[](const ESM::Armor& rec) -> sol::optional<std::string> { return LuaUtil::serializeRefId(rec.mScript); });
record["weight"] = sol::readonly_property([](const ESM::Armor& rec) -> float { return rec.mData.mWeight; });
record["value"] = sol::readonly_property([](const ESM::Armor& rec) -> int { return rec.mData.mValue; });
record["type"] = sol::readonly_property([](const ESM::Armor& rec) -> int { return rec.mData.mType; });
Expand Down
16 changes: 6 additions & 10 deletions apps/openmw/mwlua/types/book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <components/esm3/loadbook.hpp>
#include <components/esm3/loadskil.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>

Expand Down Expand Up @@ -104,27 +105,22 @@ namespace MWLua
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 Misc::ResourceHelpers::correctMeshPath(rec.mModel); });
record["mwscript"]
= sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mScript.serializeText(); });
record["mwscript"] = sol::readonly_property(
[](const ESM::Book& rec) -> sol::optional<std::string> { return LuaUtil::serializeRefId(rec.mScript); });
record["icon"] = sol::readonly_property([vfs](const ESM::Book& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
record["text"] = sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mText; });
record["enchant"] = sol::readonly_property([](const ESM::Book& rec) -> sol::optional<std::string> {
if (rec.mEnchant.empty())
return sol::nullopt;
return rec.mEnchant.serializeText();
});
record["enchant"] = sol::readonly_property(
[](const ESM::Book& rec) -> sol::optional<std::string> { return LuaUtil::serializeRefId(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> {
ESM::RefId skill = ESM::Skill::indexToRefId(rec.mData.mSkillId);
if (!skill.empty())
return skill.serializeText();
return sol::nullopt;
return LuaUtil::serializeRefId(skill);
});
}
}
10 changes: 5 additions & 5 deletions apps/openmw/mwlua/types/clothing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <components/esm3/loadclot.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>

Expand Down Expand Up @@ -94,12 +95,11 @@ namespace MWLua
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
record["enchant"] = sol::readonly_property([](const ESM::Clothing& rec) -> sol::optional<std::string> {
if (rec.mEnchant.empty())
return sol::nullopt;
return rec.mEnchant.serializeText();
return LuaUtil::serializeRefId(rec.mEnchant);
});
record["mwscript"] = sol::readonly_property([](const ESM::Clothing& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
record["mwscript"] = sol::readonly_property(
[](const ESM::Clothing& rec) -> std::string { return rec.mScript.serializeText(); });
record["weight"] = sol::readonly_property([](const ESM::Clothing& rec) -> float { return rec.mData.mWeight; });
record["value"] = sol::readonly_property([](const ESM::Clothing& rec) -> int { return rec.mData.mValue; });
record["type"] = sol::readonly_property([](const ESM::Clothing& rec) -> int { return rec.mData.mType; });
Expand Down
6 changes: 4 additions & 2 deletions apps/openmw/mwlua/types/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <components/esm3/loadcont.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>

Expand Down Expand Up @@ -51,8 +52,9 @@ namespace MWLua
record["model"] = sol::readonly_property([](const ESM::Container& rec) -> std::string {
return Misc::ResourceHelpers::correctMeshPath(rec.mModel);
});
record["mwscript"] = sol::readonly_property(
[](const ESM::Container& rec) -> std::string { return rec.mScript.serializeText(); });
record["mwscript"] = sol::readonly_property([](const ESM::Container& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
record["weight"] = sol::readonly_property([](const ESM::Container& rec) -> float { return rec.mWeight; });
record["isOrganic"] = sol::readonly_property(
[](const ESM::Container& rec) -> bool { return rec.mFlags & ESM::Container::Organic; });
Expand Down
6 changes: 4 additions & 2 deletions apps/openmw/mwlua/types/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <components/esm3/loadcrea.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>

Expand Down Expand Up @@ -36,8 +37,9 @@ namespace MWLua
record["name"] = sol::readonly_property([](const ESM::Creature& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property(
[](const ESM::Creature& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel); });
record["mwscript"] = sol::readonly_property(
[](const ESM::Creature& rec) -> std::string { return rec.mScript.serializeText(); });
record["mwscript"] = sol::readonly_property([](const ESM::Creature& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
record["baseCreature"] = sol::readonly_property(
[](const ESM::Creature& rec) -> std::string { return rec.mOriginal.serializeText(); });
record["soulValue"] = sol::readonly_property([](const ESM::Creature& rec) -> int { return rec.mData.mSoul; });
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwlua/types/door.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <components/esm3/loaddoor.hpp>
#include <components/esm4/loaddoor.hpp>
#include <components/lua/util.hpp>
#include <components/lua/utilpackage.hpp>
#include <components/misc/convert.hpp>
#include <components/misc/resourcehelpers.hpp>
Expand Down Expand Up @@ -64,8 +65,8 @@ namespace MWLua
record["name"] = sol::readonly_property([](const ESM::Door& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property(
[](const ESM::Door& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel); });
record["mwscript"]
= sol::readonly_property([](const ESM::Door& rec) -> std::string { return rec.mScript.serializeText(); });
record["mwscript"] = sol::readonly_property(
[](const ESM::Door& rec) -> sol::optional<std::string> { return LuaUtil::serializeRefId(rec.mScript); });
record["openSound"] = sol::readonly_property(
[](const ESM::Door& rec) -> std::string { return rec.mOpenSound.serializeText(); });
record["closeSound"] = sol::readonly_property(
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwlua/types/ingredient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ namespace MWLua
record["model"] = sol::readonly_property([](const ESM::Ingredient& rec) -> std::string {
return Misc::ResourceHelpers::correctMeshPath(rec.mModel);
});
record["mwscript"] = sol::readonly_property(
[](const ESM::Ingredient& rec) -> std::string { return rec.mScript.serializeText(); });
record["mwscript"] = sol::readonly_property([](const ESM::Ingredient& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
record["icon"] = sol::readonly_property([vfs](const ESM::Ingredient& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwlua/types/light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <components/esm3/loadligh.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>

Expand Down Expand Up @@ -96,8 +97,8 @@ namespace MWLua
});
record["sound"]
= sol::readonly_property([](const ESM::Light& rec) -> std::string { return rec.mSound.serializeText(); });
record["mwscript"]
= sol::readonly_property([](const ESM::Light& rec) -> std::string { return rec.mScript.serializeText(); });
record["mwscript"] = sol::readonly_property(
[](const ESM::Light& rec) -> sol::optional<std::string> { return LuaUtil::serializeRefId(rec.mScript); });
record["weight"] = sol::readonly_property([](const ESM::Light& rec) -> float { return rec.mData.mWeight; });
record["value"] = sol::readonly_property([](const ESM::Light& rec) -> int { return rec.mData.mValue; });
record["duration"] = sol::readonly_property([](const ESM::Light& rec) -> int { return rec.mData.mTime; });
Expand Down
6 changes: 4 additions & 2 deletions apps/openmw/mwlua/types/lockpick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <components/esm3/loadlock.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>

Expand Down Expand Up @@ -31,8 +32,9 @@ namespace MWLua
record["name"] = sol::readonly_property([](const ESM::Lockpick& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property(
[](const ESM::Lockpick& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel); });
record["mwscript"] = sol::readonly_property(
[](const ESM::Lockpick& rec) -> std::string { return rec.mScript.serializeText(); });
record["mwscript"] = sol::readonly_property([](const ESM::Lockpick& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
record["icon"] = sol::readonly_property([vfs](const ESM::Lockpick& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
Expand Down
11 changes: 5 additions & 6 deletions apps/openmw/mwlua/types/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <components/esm3/loadcrea.hpp>
#include <components/esm3/loadmisc.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>

Expand Down Expand Up @@ -70,10 +71,7 @@ namespace MWLua
};
miscellaneous["getSoul"] = [](const Object& object) -> sol::optional<std::string> {
ESM::RefId soul = object.ptr().getCellRef().getSoul();
if (soul.empty())
return sol::nullopt;
else
return soul.serializeText();
return LuaUtil::serializeRefId(soul);
};
miscellaneous["soul"] = miscellaneous["getSoul"]; // for compatibility; should be removed later

Expand All @@ -87,8 +85,9 @@ namespace MWLua
record["model"] = sol::readonly_property([](const ESM::Miscellaneous& rec) -> std::string {
return Misc::ResourceHelpers::correctMeshPath(rec.mModel);
});
record["mwscript"] = sol::readonly_property(
[](const ESM::Miscellaneous& rec) -> std::string { return rec.mScript.serializeText(); });
record["mwscript"] = sol::readonly_property([](const ESM::Miscellaneous& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
record["icon"] = sol::readonly_property([vfs](const ESM::Miscellaneous& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
Expand Down
4 changes: 2 additions & 2 deletions apps/openmw/mwlua/types/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ namespace MWLua
= sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mRace.serializeText(); });
record["class"]
= sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mClass.serializeText(); });
record["mwscript"]
= sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mScript.serializeText(); });
record["mwscript"] = sol::readonly_property(
[](const ESM::NPC& rec) -> sol::optional<std::string> { return LuaUtil::serializeRefId(rec.mScript); });
record["hair"]
= sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mHair.serializeText(); });
record["baseDisposition"]
Expand Down
4 changes: 2 additions & 2 deletions apps/openmw/mwlua/types/potion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ namespace MWLua
record["icon"] = sol::readonly_property([vfs](const ESM::Potion& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
record["mwscript"]
= sol::readonly_property([](const ESM::Potion& rec) -> std::string { return rec.mScript.serializeText(); });
record["mwscript"] = sol::readonly_property(
[](const ESM::Potion& rec) -> sol::optional<std::string> { return LuaUtil::serializeRefId(rec.mScript); });
record["weight"] = sol::readonly_property([](const ESM::Potion& rec) -> float { return rec.mData.mWeight; });
record["value"] = sol::readonly_property([](const ESM::Potion& rec) -> int { return rec.mData.mValue; });
record["effects"] = sol::readonly_property([context](const ESM::Potion& rec) -> sol::table {
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwlua/types/probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <components/esm3/loadprob.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>

Expand Down Expand Up @@ -31,8 +32,8 @@ namespace MWLua
record["name"] = sol::readonly_property([](const ESM::Probe& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property(
[](const ESM::Probe& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel); });
record["mwscript"]
= sol::readonly_property([](const ESM::Probe& rec) -> std::string { return rec.mScript.serializeText(); });
record["mwscript"] = sol::readonly_property(
[](const ESM::Probe& rec) -> sol::optional<std::string> { return LuaUtil::serializeRefId(rec.mScript); });
record["icon"] = sol::readonly_property([vfs](const ESM::Probe& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwlua/types/repair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <components/esm3/loadrepa.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>

Expand Down Expand Up @@ -31,8 +32,8 @@ namespace MWLua
record["name"] = sol::readonly_property([](const ESM::Repair& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property(
[](const ESM::Repair& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel); });
record["mwscript"]
= sol::readonly_property([](const ESM::Repair& rec) -> std::string { return rec.mScript.serializeText(); });
record["mwscript"] = sol::readonly_property(
[](const ESM::Repair& rec) -> sol::optional<std::string> { return LuaUtil::serializeRefId(rec.mScript); });
record["icon"] = sol::readonly_property([vfs](const ESM::Repair& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
Expand Down
Loading

0 comments on commit 7d0fca1

Please sign in to comment.