1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-16 11:33:03 +01:00

Write objects

This commit is contained in:
Ted John
2018-12-15 10:34:03 +00:00
parent 3f663feec7
commit 9ba375f23b
2 changed files with 34 additions and 0 deletions

View File

@@ -1,5 +1,8 @@
#include "ParkFile.h"
#include "Context.h"
#include "object/ObjectManager.h"
#include "object/ObjectRepository.h"
#include "OpenRCT2.h"
#include "Version.h"
#include "core/Crypt.h"
@@ -58,6 +61,7 @@ void ParkFile::Save(const std::string_view& path)
_header.Compression = COMPRESSION_NONE;
WriteAuthoringChunk();
WriteObjectsChunk();
WriteGeneralChunk();
// TODO avoid copying the buffer
@@ -152,6 +156,35 @@ void ParkFile::WriteAuthoringChunk()
EndChunk();
}
void ParkFile::WriteObjectsChunk()
{
BeginChunk(ParkFileChunkType::OBJECTS);
BeginArray();
// TODO do not hard code object count
auto& objManager = GetContext()->GetObjectManager();
for (size_t i = 0; i < OBJECT_ENTRY_COUNT; i++)
{
auto obj = objManager.GetLoadedObject(i);
if (obj != nullptr)
{
auto entry = obj->GetObjectEntry();
auto type = (uint16_t)(entry->flags & 0x0F);
type |= 0x8000; // Make as legacy object
WriteValue<uint16_t>(type);
WriteString(std::string_view(entry->name, 8));
WriteString("");
}
else
{
WriteValue<uint16_t>(0);
WriteString("");
WriteString("");
}
}
EndArray();
EndChunk();
}
void ParkFile::WriteGeneralChunk()
{
BeginChunk(ParkFileChunkType::GENERAL);

View File

@@ -59,6 +59,7 @@ namespace OpenRCT2
}
void WriteAuthoringChunk();
void WriteObjectsChunk();
void WriteGeneralChunk();
};
} // namespace OpenRCT2