mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-21 00:25:44 +00:00
chore: add writer for accuracy graphs
This commit is contained in:
parent
3201cefd5b
commit
5c0d1e4d99
17
src/ObjCommon/Weapon/GenericAccuracyGraph.h
Normal file
17
src/ObjCommon/Weapon/GenericAccuracyGraph.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class GenericAccuracyGraphKnot
|
||||
{
|
||||
public:
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
|
||||
class GenericAccuracyGraph
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
std::vector<GenericAccuracyGraphKnot> knots;
|
||||
};
|
57
src/ObjWriting/Weapon/AccuracyGraphWriter.cpp
Normal file
57
src/ObjWriting/Weapon/AccuracyGraphWriter.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include "AccuracyGraphWriter.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool ShouldDumpAccuracyGraph(std::unordered_set<std::string>& dumpedGraphs, const std::string& graphName)
|
||||
{
|
||||
if (graphName.empty())
|
||||
return false;
|
||||
|
||||
const auto existingEntry = dumpedGraphs.find(graphName);
|
||||
if (existingEntry == dumpedGraphs.end())
|
||||
{
|
||||
dumpedGraphs.emplace(graphName);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DumpAccuracyGraph(const AssetDumpingContext& context, const GenericAccuracyGraph& graph, const std::string& subFolder)
|
||||
{
|
||||
const auto file = context.OpenAssetFile(std::format("accuracy/{}/{}", subFolder, graph.name));
|
||||
if (!file)
|
||||
{
|
||||
std::cerr << "Failed to open file for accuracy graph: " << subFolder << "/" << graph.name << "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
*file << "WEAPONACCUFILE\n\n";
|
||||
*file << graph.knots.size() << "\n";
|
||||
|
||||
for (const auto& knot : graph.knots)
|
||||
*file << std::format("{:.4f} {:.4f}\n", knot.x, knot.y);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool AccuracyGraphWriter::ShouldDumpAiVsAiGraph(const std::string& graphName)
|
||||
{
|
||||
return ShouldDumpAccuracyGraph(m_dumped_ai_vs_ai_graphs, graphName);
|
||||
}
|
||||
|
||||
bool AccuracyGraphWriter::ShouldDumpAiVsPlayerGraph(const std::string& graphName)
|
||||
{
|
||||
return ShouldDumpAccuracyGraph(m_dumped_ai_vs_player_graphs, graphName);
|
||||
}
|
||||
|
||||
void AccuracyGraphWriter::DumpAiVsAiGraph(const AssetDumpingContext& context, const GenericAccuracyGraph& aiVsAiGraph)
|
||||
{
|
||||
DumpAccuracyGraph(context, aiVsAiGraph, "aivsai");
|
||||
}
|
||||
|
||||
void AccuracyGraphWriter::DumpAiVsPlayerGraph(const AssetDumpingContext& context, const GenericAccuracyGraph& aiVsPlayerGraph)
|
||||
{
|
||||
DumpAccuracyGraph(context, aiVsPlayerGraph, "aivsplayer");
|
||||
}
|
21
src/ObjWriting/Weapon/AccuracyGraphWriter.h
Normal file
21
src/ObjWriting/Weapon/AccuracyGraphWriter.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "Dumping/AssetDumpingContext.h"
|
||||
#include "Dumping/IZoneAssetDumperState.h"
|
||||
#include "Weapon/GenericAccuracyGraph.h"
|
||||
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
class AccuracyGraphWriter final : public IZoneAssetDumperState
|
||||
{
|
||||
public:
|
||||
bool ShouldDumpAiVsAiGraph(const std::string& graphName);
|
||||
bool ShouldDumpAiVsPlayerGraph(const std::string& graphName);
|
||||
|
||||
static void DumpAiVsAiGraph(const AssetDumpingContext& context, const GenericAccuracyGraph& aiVsAiGraph);
|
||||
static void DumpAiVsPlayerGraph(const AssetDumpingContext& context, const GenericAccuracyGraph& aiVsPlayerGraph);
|
||||
|
||||
private:
|
||||
std::unordered_set<std::string> m_dumped_ai_vs_ai_graphs;
|
||||
std::unordered_set<std::string> m_dumped_ai_vs_player_graphs;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user