feat: load t6 weapon camo from json

This commit is contained in:
Jan
2024-03-24 14:48:54 +01:00
parent af37476e23
commit c881cd6fd3
5 changed files with 325 additions and 1 deletions

View File

@ -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;
}

View 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