mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-11 07:18:11 -05:00
Add basic parsing for menu lists with only loadMenus instructions
This commit is contained in:
17
src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuDef.h
Normal file
17
src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuDef.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "AssetLoading/BasicAssetLoader.h"
|
||||
#include "AssetLoading/IAssetLoadingManager.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
namespace IW4
|
||||
{
|
||||
class AssetLoaderMenuDef final : public BasicAssetLoader<ASSET_TYPE_MENU, menuDef_t>
|
||||
{
|
||||
public:
|
||||
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
|
||||
_NODISCARD bool CanLoadFromRaw() const override;
|
||||
bool LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
|
||||
};
|
||||
}
|
46
src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuList.cpp
Normal file
46
src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuList.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "AssetLoaderMenuList.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Parsing/Menu/MenuFileReader.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
void* AssetLoaderMenuList::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||
{
|
||||
auto* menuList = memory->Create<MenuList>();
|
||||
memset(menuList, 0, sizeof(MenuList));
|
||||
menuList->name = memory->Dup(assetName.c_str());
|
||||
return menuList;
|
||||
}
|
||||
|
||||
bool AssetLoaderMenuList::CanLoadFromRaw() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetLoaderMenuList::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||
{
|
||||
const auto file = searchPath->Open(assetName);
|
||||
if (!file.IsOpen())
|
||||
return false;
|
||||
|
||||
MenuFileReader reader(*file.m_stream, assetName, [searchPath](const std::string& filename) -> std::unique_ptr<std::istream>
|
||||
{
|
||||
auto foundFileToInclude = searchPath->Open(filename);
|
||||
if (!foundFileToInclude.IsOpen() || !foundFileToInclude.m_stream)
|
||||
return nullptr;
|
||||
|
||||
return std::move(foundFileToInclude.m_stream);
|
||||
});
|
||||
|
||||
if(!reader.ReadMenuFile(MenuFeatureLevel::IW4))
|
||||
{
|
||||
std::cout << "Could not read menu list \"" << assetName << "\"\n";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
17
src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuList.h
Normal file
17
src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMenuList.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "AssetLoading/BasicAssetLoader.h"
|
||||
#include "AssetLoading/IAssetLoadingManager.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
namespace IW4
|
||||
{
|
||||
class AssetLoaderMenuList final : public BasicAssetLoader<ASSET_TYPE_MENULIST, MenuList>
|
||||
{
|
||||
public:
|
||||
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
|
||||
_NODISCARD bool CanLoadFromRaw() const override;
|
||||
bool LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
|
||||
};
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
#include "ObjContainer/IPak/IPak.h"
|
||||
#include "ObjLoading.h"
|
||||
#include "AssetLoaders/AssetLoaderLocalizeEntry.h"
|
||||
#include "AssetLoaders/AssetLoaderMenuList.h"
|
||||
#include "AssetLoaders/AssetLoaderRawFile.h"
|
||||
#include "AssetLoading/AssetLoadingManager.h"
|
||||
#include "Image/Dx9TextureLoader.h"
|
||||
@ -43,7 +44,7 @@ ObjLoader::ObjLoader()
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_GFXWORLD, GfxWorld))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_LIGHT_DEF, GfxLightDef))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_FONT, Font_s))
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_MENULIST, MenuList))
|
||||
REGISTER_ASSET_LOADER(AssetLoaderMenuList)
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_MENU, menuDef_t))
|
||||
REGISTER_ASSET_LOADER(AssetLoaderLocalizeEntry)
|
||||
REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_WEAPON, WeaponCompleteDef))
|
||||
|
Reference in New Issue
Block a user