mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-29 04:06:40 +00:00
Merge branch 'esmtool_esm4_globals' into 'master'
Support more fields in esmtool for ESM4 See merge request OpenMW/openmw!2659
This commit is contained in:
commit
3a9a60a453
11 changed files with 197 additions and 119 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include <components/esm4/reader.hpp>
|
#include <components/esm4/reader.hpp>
|
||||||
#include <components/esm4/readerutils.hpp>
|
#include <components/esm4/readerutils.hpp>
|
||||||
#include <components/esm4/records.hpp>
|
#include <components/esm4/records.hpp>
|
||||||
|
#include <components/esm4/typetraits.hpp>
|
||||||
#include <components/to_utf8/to_utf8.hpp>
|
#include <components/to_utf8/to_utf8.hpp>
|
||||||
|
|
||||||
namespace EsmTool
|
namespace EsmTool
|
||||||
|
@ -57,97 +58,6 @@ namespace EsmTool
|
||||||
return "Unknown (" + std::to_string(type) + ")";
|
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>
|
template <class T>
|
||||||
struct WriteArray
|
struct WriteArray
|
||||||
{
|
{
|
||||||
|
@ -181,20 +91,28 @@ namespace EsmTool
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::cout << "\n Record: " << ESM::NAME(reader.hdr().record.typeId).toStringView();
|
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;
|
std::cout << "\n FormId: " << value.mFormId;
|
||||||
if constexpr (hasRefId<T>)
|
if constexpr (ESM4::hasId<T>)
|
||||||
std::cout << "\n FormId: " << value.mId;
|
std::cout << "\n Id: " << value.mId;
|
||||||
if constexpr (hasFlags<T>)
|
if constexpr (ESM4::hasFlags<T>)
|
||||||
std::cout << "\n Record flags: " << recordFlags(value.mFlags);
|
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;
|
std::cout << "\n EditorId: " << value.mEditorId;
|
||||||
if constexpr (hasModel<T>)
|
if constexpr (ESM4::hasModel<T>)
|
||||||
std::cout << "\n Model: " << value.mModel;
|
std::cout << "\n Model: " << value.mModel;
|
||||||
if constexpr (hasNif<T>)
|
if constexpr (ESM4::hasNif<T>)
|
||||||
std::cout << "\n Nif:" << WriteArray("\n - ", value.mNif);
|
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);
|
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';
|
std::cout << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -194,6 +194,7 @@ add_component_dir (esm4
|
||||||
reference
|
reference
|
||||||
script
|
script
|
||||||
readerutils
|
readerutils
|
||||||
|
typetraits
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (misc
|
add_component_dir (misc
|
||||||
|
|
|
@ -49,9 +49,9 @@
|
||||||
// longer/shorter/same as loading the subrecords.
|
// longer/shorter/same as loading the subrecords.
|
||||||
void ESM4::Cell::load(ESM4::Reader& reader)
|
void ESM4::Cell::load(ESM4::Reader& reader)
|
||||||
{
|
{
|
||||||
auto formId = reader.hdr().record.id;
|
mFormId = reader.hdr().record.id;
|
||||||
reader.adjustFormId(formId);
|
reader.adjustFormId(mFormId);
|
||||||
mId = ESM::RefId::formIdRefId(formId);
|
mId = ESM::RefId::formIdRefId(mFormId);
|
||||||
mFlags = reader.hdr().record.flags;
|
mFlags = reader.hdr().record.flags;
|
||||||
mParent = reader.currWorld();
|
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
|
// WARN: we need to call setCurrCell (and maybe setCurrCellGrid?) again before loading
|
||||||
// cell child groups if we are loading them after restoring the context
|
// cell child groups if we are loading them after restoring the context
|
||||||
// (may be easier to update the context before saving?)
|
// (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();
|
std::uint32_t esmVer = reader.esmVersion();
|
||||||
bool isFONV = esmVer == ESM::VER_132 || esmVer == ESM::VER_133 || esmVer == ESM::VER_134;
|
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.
|
// The cells need to be organised under world spaces.
|
||||||
struct Cell
|
struct Cell
|
||||||
{
|
{
|
||||||
FormId mParent; // world formId (for grouping cells), from the loading sequence
|
FormId mFormId; // from the header
|
||||||
|
ESM::RefId mId;
|
||||||
ESM::RefId mId; // from the header
|
|
||||||
std::uint32_t mFlags; // from the header, see enum type RecordFlag for details
|
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 mEditorId;
|
||||||
std::string mFullName;
|
std::string mFullName;
|
||||||
std::uint16_t mCellFlags; // TES5 can also be 8 bits
|
std::uint16_t mCellFlags; // TES5 can also be 8 bits
|
||||||
|
|
|
@ -34,11 +34,12 @@
|
||||||
|
|
||||||
void ESM4::Reference::load(ESM4::Reader& reader)
|
void ESM4::Reference::load(ESM4::Reader& reader)
|
||||||
{
|
{
|
||||||
auto formId = reader.hdr().record.id;
|
mFormId = reader.hdr().record.id;
|
||||||
reader.adjustFormId(formId);
|
reader.adjustFormId(mFormId);
|
||||||
mId = ESM::RefId::formIdRefId(formId);
|
mId = ESM::RefId::formIdRefId(mFormId);
|
||||||
mFlags = reader.hdr().record.flags;
|
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?
|
// TODO: Let the engine apply this? Saved games?
|
||||||
// mInitiallyDisabled = ((mFlags & ESM4::Rec_Disabled) != 0) ? true : false;
|
// mInitiallyDisabled = ((mFlags & ESM4::Rec_Disabled) != 0) ? true : false;
|
||||||
|
|
|
@ -74,10 +74,13 @@ namespace ESM4
|
||||||
|
|
||||||
struct Reference
|
struct Reference
|
||||||
{
|
{
|
||||||
ESM::RefId mParent; // cell FormId (currently persistent refs only), from the loading sequence
|
FormId mFormId; // from the header
|
||||||
// NOTE: for exterior cells it will be the dummy cell FormId
|
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::uint32_t mFlags; // from the header, see enum type RecordFlag for details
|
||||||
|
|
||||||
std::string mEditorId;
|
std::string mEditorId;
|
||||||
|
|
|
@ -34,9 +34,9 @@
|
||||||
|
|
||||||
void ESM4::Static::load(ESM4::Reader& reader)
|
void ESM4::Static::load(ESM4::Reader& reader)
|
||||||
{
|
{
|
||||||
FormId formId = reader.hdr().record.id;
|
mFormId = reader.hdr().record.id;
|
||||||
reader.adjustFormId(formId);
|
reader.adjustFormId(mFormId);
|
||||||
mId = ESM::RefId::formIdRefId(formId);
|
mId = ESM::RefId::formIdRefId(mFormId);
|
||||||
mFlags = reader.hdr().record.flags;
|
mFlags = reader.hdr().record.flags;
|
||||||
|
|
||||||
while (reader.getSubRecordHeader())
|
while (reader.getSubRecordHeader())
|
||||||
|
|
|
@ -43,7 +43,9 @@ namespace ESM4
|
||||||
|
|
||||||
struct Static
|
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::uint32_t mFlags; // from the header, see enum type RecordFlag for details
|
||||||
|
|
||||||
std::string mEditorId;
|
std::string mEditorId;
|
||||||
|
|
|
@ -81,4 +81,4 @@ namespace ESM4
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !OPENMW_COMPONENTS_ESM4_READERUTILS
|
#endif // OPENMW_COMPONENTS_ESM4_READERUTILS
|
||||||
|
|
152
components/esm4/typetraits.hpp
Normal file
152
components/esm4/typetraits.hpp
Normal file
|
@ -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…
Reference in a new issue