mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-13 00:08:26 -05:00
feat: load t6 weapon camo from json
This commit is contained in:
@ -0,0 +1,46 @@
|
||||
#include "AssetLoaderWeaponCamo.h"
|
||||
|
||||
#include "Game/T6/WeaponCamo/JsonWeaponCamoLoader.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace T6;
|
||||
|
||||
void* AssetLoaderWeaponCamo::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||
{
|
||||
auto* weaponCamo = memory->Create<WeaponCamo>();
|
||||
memset(weaponCamo, 0, sizeof(WeaponCamo));
|
||||
weaponCamo->name = memory->Dup(assetName.c_str());
|
||||
|
||||
return weaponCamo;
|
||||
}
|
||||
|
||||
bool AssetLoaderWeaponCamo::CanLoadFromRaw() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetLoaderWeaponCamo::LoadFromRaw(
|
||||
const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||
{
|
||||
const auto fileName = std::format("camo/{}.json", assetName);
|
||||
const auto file = searchPath->Open(fileName);
|
||||
if (!file.IsOpen())
|
||||
return false;
|
||||
|
||||
auto* weaponCamo = static_cast<WeaponCamo*>(memory->Alloc(sizeof(WeaponCamo)));
|
||||
memset(weaponCamo, 0, sizeof(WeaponCamo));
|
||||
weaponCamo->name = memory->Dup(assetName.c_str());
|
||||
|
||||
std::vector<XAssetInfoGeneric*> dependencies;
|
||||
if (LoadWeaponCamoAsJson(*file.m_stream, *weaponCamo, memory, manager, dependencies))
|
||||
manager->AddAsset(ASSET_TYPE_WEAPON_CAMO, assetName, weaponCamo, std::move(dependencies));
|
||||
else
|
||||
std::cerr << "Failed to load weapon camo \"" << assetName << "\"\n";
|
||||
|
||||
return true;
|
||||
}
|
17
src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponCamo.h
Normal file
17
src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponCamo.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "AssetLoading/BasicAssetLoader.h"
|
||||
#include "AssetLoading/IAssetLoadingManager.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
class AssetLoaderWeaponCamo final : public BasicAssetLoader<ASSET_TYPE_WEAPON_CAMO, WeaponCamo>
|
||||
{
|
||||
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;
|
||||
};
|
||||
} // namespace T6
|
Reference in New Issue
Block a user