mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-24 09:16:39 +00:00
refactor: use asset_type_t for ZoneDefinition
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
#include "AssetList.h"
|
||||
|
||||
AssetListEntry::AssetListEntry()
|
||||
: m_is_reference(false)
|
||||
: m_type(0u),
|
||||
m_is_reference(false)
|
||||
{
|
||||
}
|
||||
|
||||
AssetListEntry::AssetListEntry(std::string type, std::string name, const bool isReference)
|
||||
: m_type(std::move(type)),
|
||||
AssetListEntry::AssetListEntry(const asset_type_t type, std::string name, const bool isReference)
|
||||
: m_type(type),
|
||||
m_name(std::move(name)),
|
||||
m_is_reference(isReference)
|
||||
{
|
||||
|
@@ -1,16 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class AssetListEntry
|
||||
{
|
||||
public:
|
||||
std::string m_type;
|
||||
asset_type_t m_type;
|
||||
std::string m_name;
|
||||
bool m_is_reference;
|
||||
|
||||
AssetListEntry();
|
||||
AssetListEntry(std::string type, std::string name, bool isReference);
|
||||
AssetListEntry(asset_type_t type, std::string name, bool isReference);
|
||||
};
|
||||
|
||||
class AssetList
|
||||
|
@@ -1,13 +1,18 @@
|
||||
#include "AssetListStream.h"
|
||||
|
||||
AssetListInputStream::AssetListInputStream(std::istream& stream)
|
||||
: m_stream(stream)
|
||||
#include <format>
|
||||
|
||||
AssetListInputStream::AssetListInputStream(std::istream& stream, const GameId game)
|
||||
: m_stream(stream),
|
||||
m_asset_name_resolver(IAssetNameResolver::GetResolverForGame(game))
|
||||
{
|
||||
}
|
||||
|
||||
bool AssetListInputStream::NextEntry(AssetListEntry& entry) const
|
||||
bool AssetListInputStream::NextEntry(AssetListEntry& entry, bool* failure) const
|
||||
{
|
||||
std::vector<std::string> row;
|
||||
if (failure)
|
||||
*failure = false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
@@ -17,7 +22,17 @@ bool AssetListInputStream::NextEntry(AssetListEntry& entry) const
|
||||
if (row.empty())
|
||||
continue;
|
||||
|
||||
entry.m_type = row[0];
|
||||
const auto& typeName = row[0];
|
||||
const auto maybeType = m_asset_name_resolver->GetAssetTypeByName(typeName);
|
||||
if (!maybeType)
|
||||
{
|
||||
std::cerr << std::format("Unknown asset type name \"{}\"\n", typeName);
|
||||
if (failure)
|
||||
*failure = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
entry.m_type = *maybeType;
|
||||
if (row.size() >= 3 && row[1].empty())
|
||||
{
|
||||
entry.m_name = row[2];
|
||||
@@ -33,14 +48,15 @@ bool AssetListInputStream::NextEntry(AssetListEntry& entry) const
|
||||
}
|
||||
}
|
||||
|
||||
AssetListOutputStream::AssetListOutputStream(std::ostream& stream)
|
||||
: m_stream(stream)
|
||||
AssetListOutputStream::AssetListOutputStream(std::ostream& stream, const GameId game)
|
||||
: m_stream(stream),
|
||||
m_asset_name_resolver(IAssetNameResolver::GetResolverForGame(game))
|
||||
{
|
||||
}
|
||||
|
||||
void AssetListOutputStream::WriteEntry(const AssetListEntry& entry)
|
||||
{
|
||||
m_stream.WriteColumn(entry.m_type);
|
||||
m_stream.WriteColumn(*m_asset_name_resolver->GetAssetTypeName(entry.m_type));
|
||||
m_stream.WriteColumn(entry.m_name);
|
||||
m_stream.NextRow();
|
||||
}
|
||||
|
@@ -1,25 +1,31 @@
|
||||
#pragma once
|
||||
#include "AssetList.h"
|
||||
#include "Csv/CsvStream.h"
|
||||
#include "Game/IGame.h"
|
||||
|
||||
#include <Zone/AssetNameResolver.h>
|
||||
#include <iostream>
|
||||
|
||||
class AssetListInputStream
|
||||
{
|
||||
CsvInputStream m_stream;
|
||||
|
||||
public:
|
||||
explicit AssetListInputStream(std::istream& stream);
|
||||
AssetListInputStream(std::istream& stream, GameId game);
|
||||
|
||||
bool NextEntry(AssetListEntry& entry) const;
|
||||
bool NextEntry(AssetListEntry& entry, bool* failure) const;
|
||||
|
||||
private:
|
||||
CsvInputStream m_stream;
|
||||
const IAssetNameResolver* m_asset_name_resolver;
|
||||
};
|
||||
|
||||
class AssetListOutputStream
|
||||
{
|
||||
CsvOutputStream m_stream;
|
||||
|
||||
public:
|
||||
explicit AssetListOutputStream(std::ostream& stream);
|
||||
AssetListOutputStream(std::ostream& stream, GameId game);
|
||||
|
||||
void WriteEntry(const AssetListEntry& entry);
|
||||
|
||||
private:
|
||||
CsvOutputStream m_stream;
|
||||
const IAssetNameResolver* m_asset_name_resolver;
|
||||
};
|
||||
|
Reference in New Issue
Block a user