mirror of https://github.com/OpenMW/openmw.git
Support loading ESM4 GMST records
parent
a9c7354338
commit
87ac85223a
@ -0,0 +1,68 @@
|
||||
#include "loadgmst.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "reader.hpp"
|
||||
|
||||
namespace ESM4
|
||||
{
|
||||
namespace
|
||||
{
|
||||
GameSetting::Data readData(FormId formId, std::string_view editorId, Reader& reader)
|
||||
{
|
||||
if (editorId.empty())
|
||||
throw std::runtime_error(
|
||||
"Unknown ESM4 GMST (" + std::to_string(formId) + ") data type: editor id is empty");
|
||||
const char type = editorId[0];
|
||||
switch (type)
|
||||
{
|
||||
case 'i':
|
||||
{
|
||||
std::int32_t value = 0;
|
||||
reader.get(value);
|
||||
return value;
|
||||
}
|
||||
case 'f':
|
||||
{
|
||||
float value = 0;
|
||||
reader.get(value);
|
||||
return value;
|
||||
}
|
||||
case 's':
|
||||
{
|
||||
std::string value;
|
||||
reader.getZString(value);
|
||||
return value;
|
||||
}
|
||||
default:
|
||||
throw std::runtime_error(
|
||||
"Unsupported ESM4 GMST (" + std::to_string(formId) + ") data type: " + std::string(editorId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameSetting::load(Reader& reader)
|
||||
{
|
||||
mFormId = reader.hdr().record.id;
|
||||
reader.adjustFormId(mFormId);
|
||||
mFlags = reader.hdr().record.flags;
|
||||
|
||||
while (reader.getSubRecordHeader())
|
||||
{
|
||||
const ESM4::SubRecordHeader& subHdr = reader.subRecordHeader();
|
||||
switch (subHdr.typeId)
|
||||
{
|
||||
case ESM4::SUB_EDID:
|
||||
reader.getZString(mEditorId);
|
||||
break;
|
||||
case ESM4::SUB_DATA:
|
||||
mData = readData(mFormId, mEditorId, reader);
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Unknown ESM4 GMST (" + std::to_string(mFormId) + ") subrecord "
|
||||
+ ESM::printName(subHdr.typeId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#ifndef OPENMW_COMPONENTS_ESM4_LOADGMST_H
|
||||
#define OPENMW_COMPONENTS_ESM4_LOADGMST_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
#include "formid.hpp"
|
||||
|
||||
namespace ESM4
|
||||
{
|
||||
class Reader;
|
||||
|
||||
struct GameSetting
|
||||
{
|
||||
using Data = std::variant<float, std::int32_t, std::string>;
|
||||
|
||||
FormId mFormId; // from the header
|
||||
std::uint32_t mFlags; // from the header, see enum type RecordFlag for details
|
||||
std::string mEditorId;
|
||||
Data mData;
|
||||
|
||||
void load(Reader& reader);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // OPENMW_COMPONENTS_ESM4_LOADGMST_H
|
Loading…
Reference in New Issue