Files
Shipwright/soh/soh/resource/importer/TextFactory.cpp
T
briaguya e0d502b696 resource refactory (#3926)
* animation

* playeranimation

* stop putting things in the LUS namespace from SoH

* get all the factories out of the namespace

* LUS::

* start on scene command stuff

* i think that's the rest of scene

* reduce copypasta

* collision header

* skeleton

* skeletonlimb

* fix

* path

* cutscene

* text

* audio sample

* sound font

* audiosequence

* background

* Revert "stop putting things in the LUS namespace from SoH"

This reverts commit 0ead6056e6.

* namespace shanans

* wrap all factories in namespace soh

* it's trying to link now

* lus

* scene command override etc

* fix audio loading

* slightly less logspam

* get past the cutscene problem

* in game!

* exporter cleanup

* more exporter cleanup

* clang formatted lus

* msvc

* itny lus change

* variant

* formatty

* fix of some sort i guess?

* use latest lus main

* fix name to enum/factory mapping

* otrexporter
2024-02-15 21:06:52 -06:00

59 lines
1.8 KiB
C++

#include "soh/resource/importer/TextFactory.h"
#include "soh/resource/type/Text.h"
#include "spdlog/spdlog.h"
namespace SOH {
std::shared_ptr<LUS::IResource> ResourceFactoryBinaryTextV0::ReadResource(std::shared_ptr<LUS::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto text = std::make_shared<Text>(file->InitData);
auto reader = std::get<std::shared_ptr<LUS::BinaryReader>>(file->Reader);
uint32_t msgCount = reader->ReadUInt32();
text->messages.reserve(msgCount);
for (uint32_t i = 0; i < msgCount; i++) {
MessageEntry entry;
entry.id = reader->ReadUInt16();
entry.textboxType = reader->ReadUByte();
entry.textboxYPos = reader->ReadUByte();
entry.msg = reader->ReadString();
text->messages.push_back(entry);
}
return text;
}
std::shared_ptr<LUS::IResource> ResourceFactoryXMLTextV0::ReadResource(std::shared_ptr<LUS::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto txt = std::make_shared<Text>(file->InitData);
auto child = std::get<std::shared_ptr<tinyxml2::XMLDocument>>(file->Reader)->FirstChildElement()->FirstChildElement();
while (child != nullptr) {
std::string childName = child->Name();
if (childName == "TextEntry") {
MessageEntry entry;
entry.id = child->IntAttribute("ID");
entry.textboxType = child->IntAttribute("TextboxType");
entry.textboxYPos = child->IntAttribute("TextboxYPos");
entry.msg = child->Attribute("Message");
entry.msg += "\x2";
txt->messages.push_back(entry);
int bp = 0;
}
child = child->NextSiblingElement();
}
return txt;
}
} // namespace SOH