2024-01-05 10:15:41 -06:00
|
|
|
#include "2s2h/resource/importer/TextMMFactory.h"
|
|
|
|
|
#include "2s2h/resource/type/TextMM.h"
|
|
|
|
|
#include "spdlog/spdlog.h"
|
|
|
|
|
|
2024-03-26 21:26:31 -04:00
|
|
|
namespace SOH {
|
2024-05-03 15:57:40 -04:00
|
|
|
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryTextMMV0::ReadResource(std::shared_ptr<Ship::File> file) {
|
2024-03-26 21:26:31 -04:00
|
|
|
if (!FileHasValidFormatAndReader(file)) {
|
2024-01-05 10:15:41 -06:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 21:26:31 -04:00
|
|
|
auto text = std::make_shared<TextMM>(file->InitData);
|
2024-05-03 15:57:40 -04:00
|
|
|
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
|
2024-01-05 10:15:41 -06:00
|
|
|
|
2024-03-26 21:26:31 -04:00
|
|
|
const uint32_t msgCount = reader->ReadUInt32();
|
2024-01-05 10:15:41 -06:00
|
|
|
text->messages.reserve(msgCount);
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < msgCount; i++) {
|
|
|
|
|
MessageEntryMM entry;
|
|
|
|
|
entry.id = reader->ReadUInt16();
|
|
|
|
|
entry.textboxType = reader->ReadUByte();
|
|
|
|
|
entry.textboxYPos = reader->ReadUByte();
|
2024-05-22 09:52:56 -04:00
|
|
|
// BENTODO: the new ZAPD reads and exports this as an int16 for JP but nothing currently uses that and the game
|
|
|
|
|
// expects an int8. Use this for now.
|
2024-04-30 21:44:38 -04:00
|
|
|
entry.icon = (int8_t)reader->ReadUInt16();
|
2024-01-05 10:15:41 -06:00
|
|
|
entry.nextMessageID = reader->ReadUInt16();
|
|
|
|
|
entry.firstItemCost = reader->ReadUInt16();
|
|
|
|
|
entry.secondItemCost = reader->ReadUInt16();
|
|
|
|
|
entry.msg = reader->ReadString();
|
|
|
|
|
|
|
|
|
|
text->messages.push_back(entry);
|
|
|
|
|
}
|
2024-03-26 21:26:31 -04:00
|
|
|
|
|
|
|
|
return text;
|
2024-01-05 10:15:41 -06:00
|
|
|
}
|
2024-03-26 21:26:31 -04:00
|
|
|
|
2024-05-03 15:57:40 -04:00
|
|
|
std::shared_ptr<Ship::IResource> ResourceFactoryXMLTextMMV0::ReadResource(std::shared_ptr<Ship::File> file) {
|
2024-03-26 21:26:31 -04:00
|
|
|
if (!FileHasValidFormatAndReader(file)) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto text = std::make_shared<TextMM>(file->InitData);
|
|
|
|
|
auto reader = std::get<std::shared_ptr<tinyxml2::XMLDocument>>(file->Reader)->FirstChildElement();
|
2024-01-05 10:15:41 -06:00
|
|
|
|
|
|
|
|
auto child = reader->FirstChildElement();
|
|
|
|
|
|
|
|
|
|
while (child != nullptr) {
|
|
|
|
|
std::string childName = child->Name();
|
|
|
|
|
|
|
|
|
|
if (childName == "TextEntry") {
|
|
|
|
|
MessageEntryMM entry;
|
|
|
|
|
entry.id = child->IntAttribute("ID");
|
|
|
|
|
entry.textboxType = child->IntAttribute("TextboxType");
|
|
|
|
|
entry.textboxYPos = child->IntAttribute("TextboxYPos");
|
|
|
|
|
|
2024-03-26 21:26:31 -04:00
|
|
|
// BENTODO: MM Unique Fields
|
2024-01-05 10:15:41 -06:00
|
|
|
|
|
|
|
|
entry.msg = child->Attribute("Message");
|
|
|
|
|
entry.msg += "\x2";
|
|
|
|
|
|
2024-03-26 21:26:31 -04:00
|
|
|
text->messages.push_back(entry);
|
2024-01-05 10:15:41 -06:00
|
|
|
int bp = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
child = child->NextSiblingElement();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 21:26:31 -04:00
|
|
|
return text;
|
|
|
|
|
}
|
2024-05-22 09:52:56 -04:00
|
|
|
} // namespace SOH
|