2022-03-21 21:54:48 -04:00
|
|
|
#include "SetExitList.h"
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "Utils/BitConverter.h"
|
|
|
|
#include "Utils/StringHelper.h"
|
|
|
|
#include "ZFile.h"
|
2023-05-07 19:58:50 -04:00
|
|
|
#include "ZRoom/ZNames.h"
|
2022-03-21 21:54:48 -04:00
|
|
|
#include "ZRoom/ZRoom.h"
|
|
|
|
|
|
|
|
SetExitList::SetExitList(ZFile* nParent) : ZRoomCommand(nParent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetExitList::DeclareReferences([[maybe_unused]] const std::string& prefix)
|
|
|
|
{
|
|
|
|
if (segmentOffset != 0)
|
|
|
|
{
|
|
|
|
std::string varName =
|
|
|
|
StringHelper::Sprintf("%sExitList_%06X", prefix.c_str(), segmentOffset);
|
|
|
|
parent->AddDeclarationPlaceholder(segmentOffset, varName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetExitList::ParseRawDataLate()
|
|
|
|
{
|
|
|
|
// Parse Entrances and Generate Declaration
|
2023-05-07 19:58:50 -04:00
|
|
|
uint32_t numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2;
|
2022-03-21 21:54:48 -04:00
|
|
|
uint32_t currentPtr = segmentOffset;
|
|
|
|
|
2023-05-07 19:58:50 -04:00
|
|
|
exits.reserve(numEntrances);
|
|
|
|
for (uint32_t i = 0; i < numEntrances; i++)
|
2022-03-21 21:54:48 -04:00
|
|
|
{
|
|
|
|
uint16_t exit = BitConverter::ToUInt16BE(parent->GetRawData(), currentPtr);
|
|
|
|
exits.push_back(exit);
|
|
|
|
|
|
|
|
currentPtr += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetExitList::DeclareReferencesLate([[maybe_unused]] const std::string& prefix)
|
|
|
|
{
|
|
|
|
if (!exits.empty())
|
|
|
|
{
|
|
|
|
std::string declaration;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < exits.size(); i++)
|
|
|
|
{
|
2023-05-07 19:58:50 -04:00
|
|
|
declaration +=
|
|
|
|
StringHelper::Sprintf(" %s,", ZNames::GetEntranceName(exits[i]).c_str());
|
2022-03-21 21:54:48 -04:00
|
|
|
if (i + 1 < exits.size())
|
|
|
|
declaration += "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string varName =
|
|
|
|
StringHelper::Sprintf("%sExitList_%06X", prefix.c_str(), segmentOffset);
|
|
|
|
parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4, exits.size() * 2,
|
|
|
|
"u16", varName, exits.size(), declaration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SetExitList::GetBodySourceCode() const
|
|
|
|
{
|
|
|
|
std::string listName;
|
2022-03-31 19:42:44 -04:00
|
|
|
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "u16", listName, parent->workerID);
|
2022-03-21 21:54:48 -04:00
|
|
|
return StringHelper::Sprintf("SCENE_CMD_EXIT_LIST(%s)", listName.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SetExitList::GetCommandCName() const
|
|
|
|
{
|
|
|
|
return "SCmdExitList";
|
|
|
|
}
|
|
|
|
|
|
|
|
RoomCommand SetExitList::GetRoomCommand() const
|
|
|
|
{
|
|
|
|
return RoomCommand::SetExitList;
|
|
|
|
}
|