mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-19 03:07:58 -05:00
Make sure to only dump menu files once
This commit is contained in:
@ -3,13 +3,17 @@
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
#include <memory>
|
||||
#include <typeindex>
|
||||
|
||||
#include "IZoneAssetDumperState.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Obj/Gdt/GdtStream.h"
|
||||
#include "Zone/Zone.h"
|
||||
|
||||
class AssetDumpingContext
|
||||
{
|
||||
std::unordered_map<std::type_index, std::unique_ptr<IZoneAssetDumperState>> m_zone_asset_dumper_states;
|
||||
|
||||
public:
|
||||
Zone* m_zone;
|
||||
std::string m_base_path;
|
||||
@ -18,4 +22,21 @@ public:
|
||||
AssetDumpingContext();
|
||||
|
||||
_NODISCARD std::unique_ptr<std::ostream> OpenAssetFile(const std::string& fileName) const;
|
||||
|
||||
template<typename T>
|
||||
T* GetZoneAssetDumperState()
|
||||
{
|
||||
static_assert(std::is_base_of_v<IZoneAssetDumperState, T>, "T must inherit IZoneAssetDumperState");
|
||||
// T must also have a public default constructor
|
||||
|
||||
const auto foundEntry = m_zone_asset_dumper_states.find(typeid(T));
|
||||
if (foundEntry != m_zone_asset_dumper_states.end())
|
||||
return dynamic_cast<T*>(foundEntry->second.get());
|
||||
|
||||
auto newState = std::make_unique<T>();
|
||||
newState->SetZone(m_zone);
|
||||
auto* newStatePtr = newState.get();
|
||||
m_zone_asset_dumper_states.emplace(std::make_pair<std::type_index, std::unique_ptr<IZoneAssetDumperState>>(typeid(T), std::move(newState)));
|
||||
return newStatePtr;
|
||||
}
|
||||
};
|
||||
|
20
src/ObjWriting/Dumping/IZoneAssetDumperState.h
Normal file
20
src/ObjWriting/Dumping/IZoneAssetDumperState.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "Zone/Zone.h"
|
||||
|
||||
class IZoneAssetDumperState
|
||||
{
|
||||
protected:
|
||||
IZoneAssetDumperState() = default;
|
||||
|
||||
public:
|
||||
virtual ~IZoneAssetDumperState() = default;
|
||||
IZoneAssetDumperState(const IZoneAssetDumperState& other) = default;
|
||||
IZoneAssetDumperState(IZoneAssetDumperState&& other) noexcept = default;
|
||||
IZoneAssetDumperState& operator=(const IZoneAssetDumperState& other) = default;
|
||||
IZoneAssetDumperState& operator=(IZoneAssetDumperState&& other) noexcept = default;
|
||||
|
||||
virtual void SetZone(Zone* zone)
|
||||
{
|
||||
// Do nothing by default
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user