Skip to content

Commit

Permalink
Merge branch 'vfs_normalized_path_20' into 'master'
Browse files Browse the repository at this point in the history
Use normalized path for correctMeshPath and getLODMeshName (#8138)

See merge request OpenMW/openmw!4455
  • Loading branch information
psi29a committed Nov 17, 2024
2 parents ebc7ecd + 22817dd commit 79dbbce
Show file tree
Hide file tree
Showing 38 changed files with 199 additions and 127 deletions.
6 changes: 3 additions & 3 deletions apps/openmw/mwlua/types/activator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm3/loadacti.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
Expand Down Expand Up @@ -49,9 +51,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Activator& rec) -> std::string { return rec.mId.serializeText(); });
record["name"] = sol::readonly_property([](const ESM::Activator& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property([](const ESM::Activator& rec) -> std::string {
return Misc::ResourceHelpers::correctMeshPath(rec.mModel);
});
addModelProperty(record);
record["mwscript"] = sol::readonly_property([](const ESM::Activator& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
Expand Down
6 changes: 3 additions & 3 deletions apps/openmw/mwlua/types/apparatus.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm3/loadappa.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
Expand Down Expand Up @@ -39,9 +41,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Apparatus& rec) -> std::string { return rec.mId.serializeText(); });
record["name"] = sol::readonly_property([](const ESM::Apparatus& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property([](const ESM::Apparatus& rec) -> std::string {
return Misc::ResourceHelpers::correctMeshPath(rec.mModel);
});
addModelProperty(record);
record["mwscript"] = sol::readonly_property([](const ESM::Apparatus& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwlua/types/armor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm3/loadarmo.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
Expand Down Expand Up @@ -96,8 +98,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Armor& rec) -> std::string { return rec.mId.serializeText(); });
record["name"] = sol::readonly_property([](const ESM::Armor& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property(
[](const ESM::Armor& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel); });
addModelProperty(record);
record["icon"] = sol::readonly_property([vfs](const ESM::Armor& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
Expand Down
8 changes: 4 additions & 4 deletions apps/openmw/mwlua/types/book.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "types.hpp"

#include <components/misc/strings/algorithm.hpp>
#include <components/misc/strings/lower.hpp>
#include "modelproperty.hpp"

#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/misc/strings/algorithm.hpp>
#include <components/misc/strings/lower.hpp>
#include <components/resource/resourcesystem.hpp>

#include "apps/openmw/mwbase/environment.hpp"
Expand Down Expand Up @@ -104,8 +105,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Book& rec) -> std::string { return rec.mId.serializeText(); });
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); });
addModelProperty(record);
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 {
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwlua/types/clothing.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm3/loadclot.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
Expand Down Expand Up @@ -91,8 +93,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Clothing& rec) -> std::string { return rec.mId.serializeText(); });
record["name"] = sol::readonly_property([](const ESM::Clothing& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property(
[](const ESM::Clothing& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel); });
addModelProperty(record);
record["icon"] = sol::readonly_property([vfs](const ESM::Clothing& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
Expand Down
6 changes: 3 additions & 3 deletions apps/openmw/mwlua/types/container.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm3/loadcont.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
Expand Down Expand Up @@ -49,9 +51,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Container& rec) -> std::string { return rec.mId.serializeText(); });
record["name"] = sol::readonly_property([](const ESM::Container& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property([](const ESM::Container& rec) -> std::string {
return Misc::ResourceHelpers::correctMeshPath(rec.mModel);
});
addModelProperty(record);
record["mwscript"] = sol::readonly_property([](const ESM::Container& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
Expand Down
7 changes: 4 additions & 3 deletions apps/openmw/mwlua/types/creature.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "types.hpp"

#include "../stats.hpp"
#include "actor.hpp"
#include "types.hpp"
#include "modelproperty.hpp"

#include <components/esm3/loadcrea.hpp>
#include <components/lua/luastate.hpp>
Expand Down Expand Up @@ -37,8 +39,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Creature& rec) -> std::string { return rec.mId.serializeText(); });
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); });
addModelProperty(record);
record["mwscript"] = sol::readonly_property([](const ESM::Creature& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
Expand Down
8 changes: 4 additions & 4 deletions apps/openmw/mwlua/types/door.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include "../localscripts.hpp"

#include <components/esm3/loaddoor.hpp>
Expand Down Expand Up @@ -107,8 +109,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Door& rec) -> std::string { return rec.mId.serializeText(); });
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); });
addModelProperty(record);
record["mwscript"] = sol::readonly_property(
[](const ESM::Door& rec) -> sol::optional<std::string> { return LuaUtil::serializeRefId(rec.mScript); });
record["openSound"] = sol::readonly_property(
Expand Down Expand Up @@ -145,8 +146,7 @@ namespace MWLua
record["id"] = sol::readonly_property(
[](const ESM4::Door& rec) -> std::string { return ESM::RefId(rec.mId).serializeText(); });
record["name"] = sol::readonly_property([](const ESM4::Door& rec) -> std::string { return rec.mFullName; });
record["model"] = sol::readonly_property(
[](const ESM4::Door& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel); });
addModelProperty(record);
record["isAutomatic"] = sol::readonly_property(
[](const ESM4::Door& rec) -> bool { return rec.mDoorFlags & ESM4::Door::Flag_AutomaticDoor; });
}
Expand Down
6 changes: 3 additions & 3 deletions apps/openmw/mwlua/types/ingredient.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm3/loadalch.hpp>
#include <components/esm3/loadingr.hpp>
#include <components/lua/luastate.hpp>
Expand Down Expand Up @@ -31,9 +33,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Ingredient& rec) -> std::string { return rec.mId.serializeText(); });
record["name"] = sol::readonly_property([](const ESM::Ingredient& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property([](const ESM::Ingredient& rec) -> std::string {
return Misc::ResourceHelpers::correctMeshPath(rec.mModel);
});
addModelProperty(record);
record["mwscript"] = sol::readonly_property([](const ESM::Ingredient& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwlua/types/light.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm3/loadligh.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
Expand Down Expand Up @@ -90,8 +92,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Light& rec) -> std::string { return rec.mId.serializeText(); });
record["name"] = sol::readonly_property([](const ESM::Light& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property(
[](const ESM::Light& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel); });
addModelProperty(record);
record["icon"] = sol::readonly_property([vfs](const ESM::Light& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwlua/types/lockpick.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm3/loadlock.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
Expand Down Expand Up @@ -30,8 +32,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Lockpick& rec) -> std::string { return rec.mId.serializeText(); });
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); });
addModelProperty(record);
record["mwscript"] = sol::readonly_property([](const ESM::Lockpick& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
Expand Down
6 changes: 3 additions & 3 deletions apps/openmw/mwlua/types/misc.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm3/loadcrea.hpp>
#include <components/esm3/loadmisc.hpp>
#include <components/lua/luastate.hpp>
Expand Down Expand Up @@ -81,9 +83,7 @@ namespace MWLua
record["id"] = sol::readonly_property(
[](const ESM::Miscellaneous& rec) -> std::string { return rec.mId.serializeText(); });
record["name"] = sol::readonly_property([](const ESM::Miscellaneous& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property([](const ESM::Miscellaneous& rec) -> std::string {
return Misc::ResourceHelpers::correctMeshPath(rec.mModel);
});
addModelProperty(record);
record["mwscript"] = sol::readonly_property([](const ESM::Miscellaneous& rec) -> sol::optional<std::string> {
return LuaUtil::serializeRefId(rec.mScript);
});
Expand Down
21 changes: 21 additions & 0 deletions apps/openmw/mwlua/types/modelproperty.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef OPENMW_APPS_OPENMW_MWLUA_TYPES_MODELPROPERTY_H
#define OPENMW_APPS_OPENMW_MWLUA_TYPES_MODELPROPERTY_H

#include <components/misc/resourcehelpers.hpp>
#include <components/vfs/pathutil.hpp>

#include <sol/property.hpp>
#include <sol/usertype.hpp>

namespace MWLua
{
template <class T>
void addModelProperty(sol::usertype<T>& recordType)
{
recordType["model"] = sol::readonly_property([](const T& recordValue) -> std::string {
return Misc::ResourceHelpers::correctMeshPath(VFS::Path::Normalized(recordValue.mModel)).value();
});
}
}

#endif
7 changes: 4 additions & 3 deletions apps/openmw/mwlua/types/npc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "actor.hpp"
#include "types.hpp"

#include "actor.hpp"
#include "modelproperty.hpp"

#include <components/esm3/loadfact.hpp>
#include <components/esm3/loadnpc.hpp>
#include <components/lua/luastate.hpp>
Expand Down Expand Up @@ -93,8 +95,7 @@ namespace MWLua
= sol::readonly_property([](const ESM::NPC& rec) -> int { return (int)rec.mNpdt.mDisposition; });
record["head"]
= sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mHead.serializeText(); });
record["model"] = sol::readonly_property(
[](const ESM::NPC& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel); });
addModelProperty(record);
record["isEssential"]
= sol::readonly_property([](const ESM::NPC& rec) -> bool { return rec.mFlags & ESM::NPC::Essential; });
record["isMale"] = sol::readonly_property([](const ESM::NPC& rec) -> bool { return rec.isMale(); });
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwlua/types/potion.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm3/loadalch.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
Expand Down Expand Up @@ -76,8 +78,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Potion& rec) -> std::string { return rec.mId.serializeText(); });
record["name"] = sol::readonly_property([](const ESM::Potion& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property(
[](const ESM::Potion& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel); });
addModelProperty(record);
record["icon"] = sol::readonly_property([vfs](const ESM::Potion& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwlua/types/probe.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm3/loadprob.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
Expand Down Expand Up @@ -30,8 +32,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Probe& rec) -> std::string { return rec.mId.serializeText(); });
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); });
addModelProperty(record);
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 {
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwlua/types/repair.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm3/loadrepa.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
Expand Down Expand Up @@ -30,8 +32,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Repair& rec) -> std::string { return rec.mId.serializeText(); });
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); });
addModelProperty(record);
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 {
Expand Down
5 changes: 3 additions & 2 deletions apps/openmw/mwlua/types/static.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm3/loadstat.hpp>
#include <components/lua/luastate.hpp>
#include <components/misc/resourcehelpers.hpp>
Expand All @@ -24,7 +26,6 @@ namespace MWLua
= [](const ESM::Static& rec) -> std::string { return "ESM3_Static[" + rec.mId.toDebugString() + "]"; };
record["id"]
= sol::readonly_property([](const ESM::Static& rec) -> std::string { return rec.mId.serializeText(); });
record["model"] = sol::readonly_property(
[](const ESM::Static& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel); });
addModelProperty(record);
}
}
6 changes: 3 additions & 3 deletions apps/openmw/mwlua/types/terminal.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm4/loadterm.hpp>
#include <components/lua/utilpackage.hpp>
#include <components/misc/convert.hpp>
Expand Down Expand Up @@ -33,8 +35,6 @@ namespace MWLua
record["resultText"]
= sol::readonly_property([](const ESM4::Terminal& rec) -> std::string { return rec.mResultText; });
record["name"] = sol::readonly_property([](const ESM4::Terminal& rec) -> std::string { return rec.mFullName; });
record["model"] = sol::readonly_property([](const ESM4::Terminal& rec) -> std::string {
return Misc::ResourceHelpers::correctMeshPath(rec.mModel);
});
addModelProperty(record);
}
}
5 changes: 3 additions & 2 deletions apps/openmw/mwlua/types/weapon.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "types.hpp"

#include "modelproperty.hpp"

#include <components/esm3/loadweap.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/util.hpp>
Expand Down Expand Up @@ -129,8 +131,7 @@ namespace MWLua
record["id"]
= sol::readonly_property([](const ESM::Weapon& rec) -> std::string { return rec.mId.serializeText(); });
record["name"] = sol::readonly_property([](const ESM::Weapon& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property(
[](const ESM::Weapon& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel); });
addModelProperty(record);
record["icon"] = sol::readonly_property([vfs](const ESM::Weapon& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
Expand Down
Loading

0 comments on commit 79dbbce

Please sign in to comment.