mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 23:08:05 -05:00
ZoneLoading: Extract all obj dumping relevant parts to ObjWriting component
This commit is contained in:
39
src/ObjWriting/Dumping/AbstractAssetDumper.h
Normal file
39
src/ObjWriting/Dumping/AbstractAssetDumper.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "IAssetDumper.h"
|
||||
#include "Utils/FileAPI.h"
|
||||
#include "Utils/PathUtils.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
template<class T>
|
||||
class AbstractAssetDumper : public IAssetDumper<T>
|
||||
{
|
||||
protected:
|
||||
virtual std::string GetFileNameForAsset(Zone* zone, T* asset) = 0;
|
||||
virtual void DumpAsset(Zone* zone, T* asset, FileAPI::File* out) = 0;
|
||||
|
||||
public:
|
||||
void DumpPool(Zone* zone, AssetPool<T>* pool, const std::string& basePath) override
|
||||
{
|
||||
for(auto assetInfo : *pool)
|
||||
{
|
||||
std::string assetFilePath = utils::Path::Combine(basePath, GetFileNameForAsset(zone, assetInfo->m_asset));
|
||||
|
||||
FileAPI::DirectoryCreate(utils::Path::GetDirectory(assetFilePath));
|
||||
|
||||
auto file = FileAPI::Open(assetFilePath, FileAPI::Mode::MODE_WRITE);
|
||||
|
||||
if(file.IsOpen())
|
||||
{
|
||||
DumpAsset(zone, assetInfo->m_asset, &file);
|
||||
|
||||
file.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Failed to open file '%s' to dump asset '%s'\n", assetFilePath.c_str(), assetInfo->m_name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
13
src/ObjWriting/Dumping/IAssetDumper.h
Normal file
13
src/ObjWriting/Dumping/IAssetDumper.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Zone.h"
|
||||
#include "Pool/AssetPool.h"
|
||||
|
||||
template<class T>
|
||||
class IAssetDumper
|
||||
{
|
||||
public:
|
||||
virtual ~IAssetDumper() = default;
|
||||
|
||||
virtual void DumpPool(Zone* zone, AssetPool<T>* pool, const std::string& basePath) = 0;
|
||||
};
|
14
src/ObjWriting/Dumping/IZoneDumper.h
Normal file
14
src/ObjWriting/Dumping/IZoneDumper.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Zone.h"
|
||||
#include "Utils/FileAPI.h"
|
||||
|
||||
class IZoneDumper
|
||||
{
|
||||
public:
|
||||
virtual ~IZoneDumper() = default;
|
||||
|
||||
virtual bool CanHandleZone(Zone* zone) = 0;
|
||||
virtual bool DumpZone(Zone* zone, const std::string& basePath) = 0;
|
||||
virtual bool WriteZoneDefinition(Zone* zone, FileAPI::File* file, bool minimalistic) = 0;
|
||||
};
|
63
src/ObjWriting/Dumping/Localize/StringFileDumper.cpp
Normal file
63
src/ObjWriting/Dumping/Localize/StringFileDumper.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include "StringFileDumper.h"
|
||||
#include <regex>
|
||||
|
||||
StringFileDumper::StringFileDumper(Zone* zone, FileAPI::File* file)
|
||||
{
|
||||
m_zone = zone;
|
||||
m_file = file;
|
||||
|
||||
m_config_file = "";
|
||||
m_notes = "";
|
||||
m_language_caps = "ENGLISH";
|
||||
|
||||
m_wrote_header = false;
|
||||
}
|
||||
|
||||
void StringFileDumper::SetLanguageName(std::string language)
|
||||
{
|
||||
m_language_caps = std::move(language);
|
||||
for (auto& c : m_language_caps) c = toupper(c);
|
||||
}
|
||||
|
||||
void StringFileDumper::SetConfigFile(std::string configFile)
|
||||
{
|
||||
m_config_file = std::move(configFile);
|
||||
}
|
||||
|
||||
void StringFileDumper::SetNotes(std::string notes)
|
||||
{
|
||||
m_notes = std::move(notes);
|
||||
}
|
||||
|
||||
void StringFileDumper::WriteHeader()
|
||||
{
|
||||
m_file->Printf("// Dumped from fastfile \"%s\".\n", m_zone->m_name.c_str());
|
||||
m_file->Printf("// In their original format the strings might have been separated in multiple files.\n");
|
||||
m_file->Printf("VERSION \"1\"\n");
|
||||
m_file->Printf("CONFIG \"%s\"\n", m_config_file.c_str());
|
||||
m_file->Printf("FILENOTES \"%s\"\n", m_notes.c_str());
|
||||
|
||||
m_wrote_header = true;
|
||||
}
|
||||
|
||||
void StringFileDumper::WriteLocalizeEntry(const std::string& reference, const std::string& value)
|
||||
{
|
||||
if (!m_wrote_header)
|
||||
WriteHeader();
|
||||
|
||||
m_file->Printf("\n");
|
||||
m_file->Printf("REFERENCE %s\n", reference.c_str());
|
||||
|
||||
const std::string escapedValue = std::regex_replace(value, std::regex("\n"), "\\n");
|
||||
|
||||
const std::string valueSpacing = std::string(15 - m_language_caps.length(), ' ');
|
||||
m_file->Printf("LANG_%s%s\"%s\"\n", m_language_caps.c_str(), valueSpacing.c_str(), escapedValue.c_str());
|
||||
}
|
||||
|
||||
void StringFileDumper::Finalize()
|
||||
{
|
||||
if (!m_wrote_header)
|
||||
WriteHeader();
|
||||
|
||||
m_file->Printf("\nENDMARKER");
|
||||
}
|
29
src/ObjWriting/Dumping/Localize/StringFileDumper.h
Normal file
29
src/ObjWriting/Dumping/Localize/StringFileDumper.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Zone.h"
|
||||
#include "Utils/FileAPI.h"
|
||||
|
||||
class StringFileDumper
|
||||
{
|
||||
Zone* m_zone;
|
||||
FileAPI::File* m_file;
|
||||
|
||||
std::string m_config_file;
|
||||
std::string m_notes;
|
||||
std::string m_language_caps;
|
||||
|
||||
bool m_wrote_header;
|
||||
|
||||
void WriteHeader();
|
||||
|
||||
public:
|
||||
StringFileDumper(Zone* zone, FileAPI::File* file);
|
||||
|
||||
void SetConfigFile(std::string configFile);
|
||||
void SetNotes(std::string notes);
|
||||
void SetLanguageName(std::string language);
|
||||
|
||||
void WriteLocalizeEntry(const std::string& reference, const std::string& value);
|
||||
|
||||
void Finalize();
|
||||
};
|
Reference in New Issue
Block a user