1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-06 00:55:50 +00:00
OpenMW/components/esm4/loadgmst.cpp
jvoisin a58dc6fd30 Use the logging system instead of std::cout in components/esm4
- Remove debug-related includes
- Add some trivial missing includes
- Remove useless {}
- Move the known-but-skipped-records are the end of the switch-cases
- Always throw on unknown records
2023-06-01 13:31:48 +02:00

76 lines
2.2 KiB
C++

#include "loadgmst.hpp"
#include <cstdint>
#include <stdexcept>
#include <string>
#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 (" + formId.toString() + ") data type: editor id is empty");
const char type = editorId[0];
switch (type)
{
case 'b':
{
std::uint32_t value = 0;
reader.get(value);
return value != 0;
}
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 (" + formId.toString() + ") data type: " + std::string(editorId));
}
}
}
void GameSetting::load(Reader& reader)
{
mFormId = reader.hdr().record.getFormId();
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 (" + mFormId.toString() + ") subrecord " + ESM::printName(subHdr.typeId));
}
}
}
}