Merge branch 'esmtool_esm4_globals' into 'master'

Support more fields in esmtool for ESM4

See merge request OpenMW/openmw!2659
7220-lua-add-a-general-purpose-lexical-parser
psi29a 2 years ago
commit 3a9a60a453

@ -986,4 +986,4 @@ std::string recordFlags(uint32_t flags)
properties += "Invalid ";
properties += Misc::StringUtils::format("(0x%08X)", flags);
return properties;
}
}

@ -10,6 +10,7 @@
#include <components/esm4/reader.hpp>
#include <components/esm4/readerutils.hpp>
#include <components/esm4/records.hpp>
#include <components/esm4/typetraits.hpp>
#include <components/to_utf8/to_utf8.hpp>
namespace EsmTool
@ -57,97 +58,6 @@ namespace EsmTool
return "Unknown (" + std::to_string(type) + ")";
}
template <class T, class = std::void_t<>>
struct HasFormId : std::false_type
{
};
template <class T>
struct HasFormId<T, std::void_t<decltype(T::mFormId)>> : std::true_type
{
};
template <class T>
constexpr bool hasFormId = HasFormId<T>::value;
template <class T, class = std::void_t<>>
struct HasRefId : std::false_type
{
};
template <class T>
struct HasRefId<T, std::void_t<decltype(T::mId)>> : std::true_type
{
};
template <class T>
constexpr bool hasRefId = HasRefId<T>::value;
template <class T, class = std::void_t<>>
struct HasFlags : std::false_type
{
};
template <class T>
struct HasFlags<T, std::void_t<decltype(T::mFlags)>> : std::true_type
{
};
template <class T>
constexpr bool hasFlags = HasFlags<T>::value;
template <class T, class = std::void_t<>>
struct HasEditorId : std::false_type
{
};
template <class T>
struct HasEditorId<T, std::void_t<decltype(T::mEditorId)>> : std::true_type
{
};
template <class T>
constexpr bool hasEditorId = HasEditorId<T>::value;
template <class T, class = std::void_t<>>
struct HasModel : std::false_type
{
};
template <class T>
struct HasModel<T, std::void_t<decltype(T::mModel)>> : std::true_type
{
};
template <class T>
constexpr bool hasModel = HasModel<T>::value;
template <class T, class = std::void_t<>>
struct HasNif : std::false_type
{
};
template <class T>
struct HasNif<T, std::void_t<decltype(T::mNif)>> : std::true_type
{
};
template <class T>
constexpr bool hasNif = HasNif<T>::value;
template <class T, class = std::void_t<>>
struct HasKf : std::false_type
{
};
template <class T>
struct HasKf<T, std::void_t<decltype(T::mKf)>> : std::true_type
{
};
template <class T>
constexpr bool hasKf = HasKf<T>::value;
template <class T>
struct WriteArray
{
@ -181,20 +91,28 @@ namespace EsmTool
return;
std::cout << "\n Record: " << ESM::NAME(reader.hdr().record.typeId).toStringView();
if constexpr (hasFormId<T>)
if constexpr (ESM4::hasFormId<T>)
std::cout << "\n FormId: " << value.mFormId;
if constexpr (hasRefId<T>)
std::cout << "\n FormId: " << value.mId;
if constexpr (hasFlags<T>)
if constexpr (ESM4::hasId<T>)
std::cout << "\n Id: " << value.mId;
if constexpr (ESM4::hasFlags<T>)
std::cout << "\n Record flags: " << recordFlags(value.mFlags);
if constexpr (hasEditorId<T>)
if constexpr (ESM4::hasParentFormId<T>)
std::cout << "\n ParentFormId: " << value.mParentFormId;
if constexpr (ESM4::hasParent<T>)
std::cout << "\n Parent: " << value.mParent;
if constexpr (ESM4::hasEditorId<T>)
std::cout << "\n EditorId: " << value.mEditorId;
if constexpr (hasModel<T>)
if constexpr (ESM4::hasModel<T>)
std::cout << "\n Model: " << value.mModel;
if constexpr (hasNif<T>)
if constexpr (ESM4::hasNif<T>)
std::cout << "\n Nif:" << WriteArray("\n - ", value.mNif);
if constexpr (hasKf<T>)
if constexpr (ESM4::hasKf<T>)
std::cout << "\n Kf:" << WriteArray("\n - ", value.mKf);
if constexpr (ESM4::hasType<T>)
std::cout << "\n Type: " << value.mType;
if constexpr (ESM4::hasValue<T>)
std::cout << "\n Value: " << value.mValue;
std::cout << '\n';
}

@ -194,6 +194,7 @@ add_component_dir (esm4
reference
script
readerutils
typetraits
)
add_component_dir (misc

@ -49,9 +49,9 @@
// longer/shorter/same as loading the subrecords.
void ESM4::Cell::load(ESM4::Reader& reader)
{
auto formId = reader.hdr().record.id;
reader.adjustFormId(formId);
mId = ESM::RefId::formIdRefId(formId);
mFormId = reader.hdr().record.id;
reader.adjustFormId(mFormId);
mId = ESM::RefId::formIdRefId(mFormId);
mFlags = reader.hdr().record.flags;
mParent = reader.currWorld();
@ -73,7 +73,7 @@ void ESM4::Cell::load(ESM4::Reader& reader)
// WARN: we need to call setCurrCell (and maybe setCurrCellGrid?) again before loading
// cell child groups if we are loading them after restoring the context
// (may be easier to update the context before saving?)
reader.setCurrCell(formId); // save for LAND (and other children) to access later
reader.setCurrCell(mFormId); // save for LAND (and other children) to access later
std::uint32_t esmVer = reader.esmVersion();
bool isFONV = esmVer == ESM::VER_132 || esmVer == ESM::VER_133 || esmVer == ESM::VER_134;

@ -62,11 +62,12 @@ namespace ESM4
// The cells need to be organised under world spaces.
struct Cell
{
FormId mParent; // world formId (for grouping cells), from the loading sequence
ESM::RefId mId; // from the header
FormId mFormId; // from the header
ESM::RefId mId;
std::uint32_t mFlags; // from the header, see enum type RecordFlag for details
FormId mParent; // world formId (for grouping cells), from the loading sequence
std::string mEditorId;
std::string mFullName;
std::uint16_t mCellFlags; // TES5 can also be 8 bits

@ -34,11 +34,12 @@
void ESM4::Reference::load(ESM4::Reader& reader)
{
auto formId = reader.hdr().record.id;
reader.adjustFormId(formId);
mId = ESM::RefId::formIdRefId(formId);
mFormId = reader.hdr().record.id;
reader.adjustFormId(mFormId);
mId = ESM::RefId::formIdRefId(mFormId);
mFlags = reader.hdr().record.flags;
mParent = ESM::RefId::formIdRefId(reader.currCell()); // NOTE: only for persistent refs?
mParentFormId = reader.currCell(); // NOTE: only for persistent refs?
mParent = ESM::RefId::formIdRefId(mParentFormId);
// TODO: Let the engine apply this? Saved games?
// mInitiallyDisabled = ((mFlags & ESM4::Rec_Disabled) != 0) ? true : false;

@ -74,10 +74,13 @@ namespace ESM4
struct Reference
{
ESM::RefId mParent; // cell FormId (currently persistent refs only), from the loading sequence
// NOTE: for exterior cells it will be the dummy cell FormId
FormId mFormId; // from the header
ESM::RefId mId;
FormId mParentFormId; // cell FormId (currently persistent refs only), from the loading sequence
// NOTE: for exterior cells it will be the dummy cell FormId
ESM::RefId mParent;
ESM::RefId mId; // from the header
std::uint32_t mFlags; // from the header, see enum type RecordFlag for details
std::string mEditorId;

@ -34,9 +34,9 @@
void ESM4::Static::load(ESM4::Reader& reader)
{
FormId formId = reader.hdr().record.id;
reader.adjustFormId(formId);
mId = ESM::RefId::formIdRefId(formId);
mFormId = reader.hdr().record.id;
reader.adjustFormId(mFormId);
mId = ESM::RefId::formIdRefId(mFormId);
mFlags = reader.hdr().record.flags;
while (reader.getSubRecordHeader())

@ -43,7 +43,9 @@ namespace ESM4
struct Static
{
ESM::RefId mId; // from the header
FormId mFormId; // from the header
ESM::RefId mId;
std::uint32_t mFlags; // from the header, see enum type RecordFlag for details
std::string mEditorId;

@ -81,4 +81,4 @@ namespace ESM4
};
}
#endif // !OPENMW_COMPONENTS_ESM4_READERUTILS
#endif // OPENMW_COMPONENTS_ESM4_READERUTILS

@ -0,0 +1,152 @@
#ifndef OPENMW_COMPONENTS_ESM4_TYPETRAITS
#define OPENMW_COMPONENTS_ESM4_TYPETRAITS
#include <type_traits>
namespace ESM4
{
template <class T, class = std::void_t<>>
struct HasFormId : std::false_type
{
};
template <class T>
struct HasFormId<T, std::void_t<decltype(T::mFormId)>> : std::true_type
{
};
template <class T>
inline constexpr bool hasFormId = HasFormId<T>::value;
template <class T, class = std::void_t<>>
struct HasId : std::false_type
{
};
template <class T>
struct HasId<T, std::void_t<decltype(T::mId)>> : std::true_type
{
};
template <class T>
inline constexpr bool hasId = HasId<T>::value;
template <class T, class = std::void_t<>>
struct HasParentFormId : std::false_type
{
};
template <class T>
struct HasParentFormId<T, std::void_t<decltype(T::mParentFormId)>> : std::true_type
{
};
template <class T>
inline constexpr bool hasParentFormId = HasParentFormId<T>::value;
template <class T, class = std::void_t<>>
struct HasParent : std::false_type
{
};
template <class T>
struct HasParent<T, std::void_t<decltype(T::mParent)>> : std::true_type
{
};
template <class T>
inline constexpr bool hasParent = HasParent<T>::value;
template <class T, class = std::void_t<>>
struct HasFlags : std::false_type
{
};
template <class T>
struct HasFlags<T, std::void_t<decltype(T::mFlags)>> : std::true_type
{
};
template <class T>
inline constexpr bool hasFlags = HasFlags<T>::value;
template <class T, class = std::void_t<>>
struct HasEditorId : std::false_type
{
};
template <class T>
struct HasEditorId<T, std::void_t<decltype(T::mEditorId)>> : std::true_type
{
};
template <class T>
inline constexpr bool hasEditorId = HasEditorId<T>::value;
template <class T, class = std::void_t<>>
struct HasModel : std::false_type
{
};
template <class T>
struct HasModel<T, std::void_t<decltype(T::mModel)>> : std::true_type
{
};
template <class T>
inline constexpr bool hasModel = HasModel<T>::value;
template <class T, class = std::void_t<>>
struct HasNif : std::false_type
{
};
template <class T>
struct HasNif<T, std::void_t<decltype(T::mNif)>> : std::true_type
{
};
template <class T>
inline constexpr bool hasNif = HasNif<T>::value;
template <class T, class = std::void_t<>>
struct HasKf : std::false_type
{
};
template <class T>
struct HasKf<T, std::void_t<decltype(T::mKf)>> : std::true_type
{
};
template <class T>
inline constexpr bool hasKf = HasKf<T>::value;
template <class T, class = std::void_t<>>
struct HasType : std::false_type
{
};
template <class T>
struct HasType<T, std::void_t<decltype(T::mType)>> : std::true_type
{
};
template <class T>
inline constexpr bool hasType = HasType<T>::value;
template <class T, class = std::void_t<>>
struct HasValue : std::false_type
{
};
template <class T>
struct HasValue<T, std::void_t<decltype(T::mValue)>> : std::true_type
{
};
template <class T>
inline constexpr bool hasValue = HasValue<T>::value;
}
#endif // OPENMW_COMPONENTS_ESM4_TYPETRAITS
Loading…
Cancel
Save