2022-02-27 07:53:44 -05:00
|
|
|
#include <STDInclude.hpp>
|
2022-06-22 11:36:06 -04:00
|
|
|
#include "IMenuList.hpp"
|
2017-02-25 13:41:54 -05:00
|
|
|
|
|
|
|
namespace Assets
|
|
|
|
{
|
2022-06-22 11:36:06 -04:00
|
|
|
void IMenuList::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
|
|
|
{
|
|
|
|
Utils::Memory::Allocator* allocator = builder->getAllocator();
|
|
|
|
|
|
|
|
// actually gets the whole list
|
|
|
|
auto menus = Components::Menus::LoadMenu(name);
|
|
|
|
if (menus.empty()) return;
|
|
|
|
|
|
|
|
// Allocate new menu list
|
2022-11-28 13:06:42 -05:00
|
|
|
auto* newList = allocator->allocate<Game::MenuList>();
|
2022-06-22 11:36:06 -04:00
|
|
|
if (!newList) return;
|
|
|
|
|
|
|
|
newList->menus = allocator->allocateArray<Game::menuDef_t*>(menus.size());
|
|
|
|
if (!newList->menus)
|
|
|
|
{
|
|
|
|
allocator->free(newList);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
newList->name = allocator->duplicateString(name);
|
|
|
|
newList->menuCount = menus.size();
|
|
|
|
|
|
|
|
// Copy new menus
|
|
|
|
for (unsigned int i = 0; i < menus.size(); ++i)
|
|
|
|
{
|
|
|
|
newList->menus[i] = menus[i].second;
|
|
|
|
}
|
|
|
|
|
|
|
|
header->menuList = newList;
|
|
|
|
}
|
2017-02-25 15:07:27 -05:00
|
|
|
void IMenuList::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
|
|
|
{
|
2022-11-28 13:06:42 -05:00
|
|
|
auto* asset = header.menuList;
|
2017-02-25 15:07:27 -05:00
|
|
|
|
2017-04-24 16:33:13 -04:00
|
|
|
for (int i = 0; i < asset->menuCount; ++i)
|
2017-02-25 15:07:27 -05:00
|
|
|
{
|
|
|
|
if (asset->menus[i])
|
|
|
|
{
|
|
|
|
builder->loadAsset(Game::XAssetType::ASSET_TYPE_MENU, asset->menus[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-25 13:41:54 -05:00
|
|
|
void IMenuList::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
|
|
|
{
|
|
|
|
AssertSize(Game::MenuList, 12);
|
|
|
|
|
|
|
|
Utils::Stream* buffer = builder->getBuffer();
|
|
|
|
Game::MenuList* asset = header.menuList;
|
2022-11-28 13:06:42 -05:00
|
|
|
auto* dest = buffer->dest<Game::MenuList>();
|
2017-02-25 13:41:54 -05:00
|
|
|
|
|
|
|
buffer->save(asset);
|
|
|
|
|
|
|
|
buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL);
|
|
|
|
|
|
|
|
if (asset->name)
|
|
|
|
{
|
|
|
|
buffer->saveString(builder->getAssetName(this->getType(), asset->name));
|
|
|
|
Utils::Stream::ClearPointer(&dest->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asset->menus)
|
|
|
|
{
|
|
|
|
buffer->align(Utils::Stream::ALIGN_4);
|
|
|
|
|
2022-11-28 13:06:42 -05:00
|
|
|
auto** destMenus = buffer->dest<Game::menuDef_t*>();
|
2017-02-25 13:41:54 -05:00
|
|
|
buffer->saveArray(asset->menus, asset->menuCount);
|
|
|
|
|
2017-04-24 16:33:13 -04:00
|
|
|
for (int i = 0; i < asset->menuCount; ++i)
|
2017-02-25 13:41:54 -05:00
|
|
|
{
|
|
|
|
destMenus[i] = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_MENU, asset->menus[i]).menu;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer->popBlock();
|
|
|
|
}
|
|
|
|
}
|