mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-08-30 21:53:15 +00:00
refactor: restructure light def dumper
This commit is contained in:
11
src/ObjCommon/LightDef/LightDefCommon.cpp
Normal file
11
src/ObjCommon/LightDef/LightDefCommon.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "LightDefCommon.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
namespace light_def
|
||||
{
|
||||
std::string GetFileNameForAsset(const std::string& assetName)
|
||||
{
|
||||
return std::format("lights/{}", assetName);
|
||||
}
|
||||
} // namespace light_def
|
8
src/ObjCommon/LightDef/LightDefCommon.h
Normal file
8
src/ObjCommon/LightDef/LightDefCommon.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace light_def
|
||||
{
|
||||
std::string GetFileNameForAsset(const std::string& assetName);
|
||||
}
|
@@ -1,12 +1,15 @@
|
||||
#include "LoaderLightDefIW4.h"
|
||||
#include "LightDefLoaderIW4.h"
|
||||
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "LightDef/LightDefCommon.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace IW4;
|
||||
using namespace ::light_def;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -23,7 +26,7 @@ namespace
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto filename = GetAssetFilename(assetName);
|
||||
const auto filename = GetFileNameForAsset(assetName);
|
||||
const auto file = m_search_path.Open(filename);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
@@ -61,11 +64,6 @@ namespace
|
||||
}
|
||||
|
||||
private:
|
||||
std::string GetAssetFilename(const std::string& assetName)
|
||||
{
|
||||
return std::format("lights/{}", assetName);
|
||||
}
|
||||
|
||||
MemoryManager& m_memory;
|
||||
ISearchPath& m_search_path;
|
||||
};
|
@@ -5,7 +5,7 @@
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Game/IW4/XModel/LoaderXModelIW4.h"
|
||||
#include "Leaderboard/LoaderLeaderboardIW4.h"
|
||||
#include "LightDef/LoaderLightDefIW4.h"
|
||||
#include "LightDef/LightDefLoaderIW4.h"
|
||||
#include "Localize/LoaderLocalizeIW4.h"
|
||||
#include "Material/LoaderMaterialIW4.h"
|
||||
#include "Menu/LoaderMenuListIW4.h"
|
||||
|
@@ -1,36 +0,0 @@
|
||||
#include "AssetDumperGfxLightDef.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
std::string AssetDumperGfxLightDef::GetAssetFilename(const std::string& assetName)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
|
||||
ss << "lights/" << assetName;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool AssetDumperGfxLightDef::ShouldDump(XAssetInfo<GfxLightDef>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetDumperGfxLightDef::DumpAsset(AssetDumpingContext& context, XAssetInfo<GfxLightDef>* asset)
|
||||
{
|
||||
const auto* lightDef = asset->Asset();
|
||||
const auto assetFile = context.OpenAssetFile(GetAssetFilename(asset->m_name));
|
||||
|
||||
if (!assetFile || lightDef->attenuation.image == nullptr || lightDef->attenuation.image->name == nullptr)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
|
||||
const auto* imageName = lightDef->attenuation.image->name;
|
||||
if (imageName[0] == ',')
|
||||
imageName = &imageName[1];
|
||||
|
||||
stream << lightDef->attenuation.samplerState << imageName << static_cast<char>(lightDef->lmapLookupStart);
|
||||
}
|
33
src/ObjWriting/Game/IW4/LightDef/LightDefDumperIW4.cpp
Normal file
33
src/ObjWriting/Game/IW4/LightDef/LightDefDumperIW4.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "LightDefDumperIW4.h"
|
||||
|
||||
#include "LightDef/LightDefCommon.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using namespace IW4;
|
||||
using namespace ::light_def;
|
||||
|
||||
namespace IW4::light_def
|
||||
{
|
||||
bool Dumper::ShouldDump(XAssetInfo<GfxLightDef>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<GfxLightDef>* asset)
|
||||
{
|
||||
const auto* lightDef = asset->Asset();
|
||||
const auto assetFile = context.OpenAssetFile(GetFileNameForAsset(asset->m_name));
|
||||
|
||||
if (!assetFile || lightDef->attenuation.image == nullptr || lightDef->attenuation.image->name == nullptr)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
|
||||
const auto* imageName = lightDef->attenuation.image->name;
|
||||
if (imageName[0] == ',')
|
||||
imageName = &imageName[1];
|
||||
|
||||
stream << lightDef->attenuation.samplerState << imageName << static_cast<char>(lightDef->lmapLookupStart);
|
||||
}
|
||||
} // namespace IW4::light_def
|
@@ -3,12 +3,10 @@
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
|
||||
namespace IW4
|
||||
namespace IW4::light_def
|
||||
{
|
||||
class AssetDumperGfxLightDef final : public AbstractAssetDumper<GfxLightDef>
|
||||
class Dumper final : public AbstractAssetDumper<GfxLightDef>
|
||||
{
|
||||
static std::string GetAssetFilename(const std::string& assetName);
|
||||
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<GfxLightDef>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<GfxLightDef>* asset) override;
|
@@ -4,7 +4,7 @@
|
||||
#include "Game/IW4/XModel/XModelDumperIW4.h"
|
||||
#include "Image/AssetDumperGfxImage.h"
|
||||
#include "Leaderboard/LeaderboardJsonDumperIW4.h"
|
||||
#include "LightDef/AssetDumperGfxLightDef.h"
|
||||
#include "LightDef/LightDefDumperIW4.h"
|
||||
#include "Localize/AssetDumperLocalizeEntry.h"
|
||||
#include "Maps/AssetDumperAddonMapEnts.h"
|
||||
#include "Material/DumperMaterialIW4.h"
|
||||
@@ -57,7 +57,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
|
||||
// DUMP_ASSET_POOL(AssetDumperMapEnts, m_map_ents, ASSET_TYPE_MAP_ENTS)
|
||||
// DUMP_ASSET_POOL(AssetDumperFxWorld, m_fx_world, ASSET_TYPE_FXWORLD)
|
||||
// DUMP_ASSET_POOL(AssetDumperGfxWorld, m_gfx_world, ASSET_TYPE_GFXWORLD)
|
||||
DUMP_ASSET_POOL(AssetDumperGfxLightDef, m_gfx_light_def, ASSET_TYPE_LIGHT_DEF)
|
||||
DUMP_ASSET_POOL(light_def::Dumper, m_gfx_light_def, ASSET_TYPE_LIGHT_DEF)
|
||||
// DUMP_ASSET_POOL(AssetDumperFont_s, m_font, ASSET_TYPE_FONT)
|
||||
DUMP_ASSET_POOL(AssetDumperMenuList, m_menu_list, ASSET_TYPE_MENULIST)
|
||||
DUMP_ASSET_POOL(AssetDumperMenuDef, m_menu_def, ASSET_TYPE_MENU)
|
||||
|
Reference in New Issue
Block a user