mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
feat: add warning for dupe localize assets
This commit is contained in:
parent
3e18f74a1a
commit
09f7473db4
@ -1,9 +0,0 @@
|
||||
#include "LocalizeFile.h"
|
||||
|
||||
LocalizeFileEntry::LocalizeFileEntry() = default;
|
||||
|
||||
LocalizeFileEntry::LocalizeFileEntry(std::string key, std::string value)
|
||||
: m_key(std::move(key)),
|
||||
m_value(std::move(value))
|
||||
{
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
class LocalizeFileEntry
|
||||
{
|
||||
public:
|
||||
std::string m_key;
|
||||
std::string m_value;
|
||||
|
||||
LocalizeFileEntry();
|
||||
LocalizeFileEntry(std::string key, std::string value);
|
||||
};
|
@ -39,13 +39,13 @@ bool AssetLoaderLocalizeEntry::LoadFromRaw(
|
||||
LocalizeFileReader reader(*file.m_stream, assetName, zone->m_language);
|
||||
const auto localizeEntries = reader.ReadLocalizeFile();
|
||||
|
||||
for (const auto& entry : localizeEntries)
|
||||
for (const auto& [key, value] : localizeEntries)
|
||||
{
|
||||
auto* localizeEntry = memory->Create<LocalizeEntry>();
|
||||
localizeEntry->name = memory->Dup(entry.m_key.c_str());
|
||||
localizeEntry->value = memory->Dup(entry.m_value.c_str());
|
||||
localizeEntry->name = memory->Dup(key.c_str());
|
||||
localizeEntry->value = memory->Dup(value.c_str());
|
||||
|
||||
manager->AddAsset(ASSET_TYPE_LOCALIZE_ENTRY, entry.m_key, localizeEntry);
|
||||
manager->AddAsset(ASSET_TYPE_LOCALIZE_ENTRY, key, localizeEntry);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -39,13 +39,13 @@ bool AssetLoaderLocalizeEntry::LoadFromRaw(
|
||||
LocalizeFileReader reader(*file.m_stream, assetName, zone->m_language);
|
||||
const auto localizeEntries = reader.ReadLocalizeFile();
|
||||
|
||||
for (const auto& entry : localizeEntries)
|
||||
for (const auto& [key, value] : localizeEntries)
|
||||
{
|
||||
auto* localizeEntry = memory->Create<LocalizeEntry>();
|
||||
localizeEntry->name = memory->Dup(entry.m_key.c_str());
|
||||
localizeEntry->value = memory->Dup(entry.m_value.c_str());
|
||||
localizeEntry->name = memory->Dup(key.c_str());
|
||||
localizeEntry->value = memory->Dup(value.c_str());
|
||||
|
||||
manager->AddAsset(ASSET_TYPE_LOCALIZE_ENTRY, entry.m_key, localizeEntry);
|
||||
manager->AddAsset(ASSET_TYPE_LOCALIZE_ENTRY, key, localizeEntry);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -39,13 +39,13 @@ bool AssetLoaderLocalizeEntry::LoadFromRaw(
|
||||
LocalizeFileReader reader(*file.m_stream, assetName, zone->m_language);
|
||||
const auto localizeEntries = reader.ReadLocalizeFile();
|
||||
|
||||
for (const auto& entry : localizeEntries)
|
||||
for (const auto& [key, value] : localizeEntries)
|
||||
{
|
||||
auto* localizeEntry = memory->Create<LocalizeEntry>();
|
||||
localizeEntry->name = memory->Dup(entry.m_key.c_str());
|
||||
localizeEntry->value = memory->Dup(entry.m_value.c_str());
|
||||
localizeEntry->name = memory->Dup(key.c_str());
|
||||
localizeEntry->value = memory->Dup(value.c_str());
|
||||
|
||||
manager->AddAsset(ASSET_TYPE_LOCALIZE_ENTRY, entry.m_key, localizeEntry);
|
||||
manager->AddAsset(ASSET_TYPE_LOCALIZE_ENTRY, key, localizeEntry);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -39,13 +39,13 @@ bool AssetLoaderLocalizeEntry::LoadFromRaw(
|
||||
LocalizeFileReader reader(*file.m_stream, assetName, zone->m_language);
|
||||
const auto localizeEntries = reader.ReadLocalizeFile();
|
||||
|
||||
for (const auto& entry : localizeEntries)
|
||||
for (const auto& [key, value] : localizeEntries)
|
||||
{
|
||||
auto* localizeEntry = memory->Create<LocalizeEntry>();
|
||||
localizeEntry->name = memory->Dup(entry.m_key.c_str());
|
||||
localizeEntry->value = memory->Dup(entry.m_value.c_str());
|
||||
localizeEntry->name = memory->Dup(key.c_str());
|
||||
localizeEntry->value = memory->Dup(value.c_str());
|
||||
|
||||
manager->AddAsset(ASSET_TYPE_LOCALIZE_ENTRY, entry.m_key, localizeEntry);
|
||||
manager->AddAsset(ASSET_TYPE_LOCALIZE_ENTRY, key, localizeEntry);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -32,7 +32,7 @@ const std::vector<AbstractParser<SimpleParserValue, LocalizeFileParserState>::se
|
||||
return !m_state->m_end ? tests : noTests;
|
||||
}
|
||||
|
||||
std::vector<LocalizeFileEntry> LocalizeFileParser::GetParsedValues()
|
||||
std::map<std::string, std::string> LocalizeFileParser::GetParsedValues()
|
||||
{
|
||||
return std::move(m_state->m_entries);
|
||||
}
|
||||
|
@ -13,5 +13,5 @@ protected:
|
||||
|
||||
public:
|
||||
LocalizeFileParser(SimpleLexer* lexer, GameLanguage language);
|
||||
std::vector<LocalizeFileEntry> GetParsedValues();
|
||||
std::map<std::string, std::string> GetParsedValues();
|
||||
};
|
||||
|
@ -1,16 +1,15 @@
|
||||
#pragma once
|
||||
#include "Game/GameLanguage.h"
|
||||
#include "Localize/LocalizeFile.h"
|
||||
|
||||
#include <map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
class LocalizeFileParserState
|
||||
{
|
||||
public:
|
||||
bool m_end;
|
||||
|
||||
std::vector<LocalizeFileEntry> m_entries;
|
||||
std::map<std::string, std::string> m_entries;
|
||||
|
||||
GameLanguage m_language;
|
||||
std::string m_language_name_caps;
|
||||
|
@ -27,7 +27,7 @@ void LocalizeFileReader::SetupStreamProxies()
|
||||
m_stream = m_open_streams.back().get();
|
||||
}
|
||||
|
||||
std::vector<LocalizeFileEntry> LocalizeFileReader::ReadLocalizeFile()
|
||||
std::map<std::string, std::string> LocalizeFileReader::ReadLocalizeFile()
|
||||
{
|
||||
SimpleLexer::Config lexerConfig;
|
||||
lexerConfig.m_emit_new_line_tokens = true;
|
||||
@ -43,5 +43,5 @@ std::vector<LocalizeFileEntry> LocalizeFileReader::ReadLocalizeFile()
|
||||
return parser->GetParsedValues();
|
||||
|
||||
std::cout << "Parsing localization file failed!" << std::endl;
|
||||
return std::vector<LocalizeFileEntry>();
|
||||
return std::map<std::string, std::string>();
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/GameLanguage.h"
|
||||
#include "Localize/LocalizeFile.h"
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -21,5 +21,5 @@ class LocalizeFileReader
|
||||
public:
|
||||
LocalizeFileReader(std::istream& stream, std::string fileName, GameLanguage language);
|
||||
|
||||
std::vector<LocalizeFileEntry> ReadLocalizeFile();
|
||||
std::map<std::string, std::string> ReadLocalizeFile();
|
||||
};
|
||||
|
@ -31,5 +31,13 @@ void SequenceLocalizeFileLanguageValue::ProcessMatch(LocalizeFileParserState* st
|
||||
state->m_current_reference_languages.emplace(langName);
|
||||
|
||||
if (langName == state->m_language_name_caps)
|
||||
state->m_entries.emplace_back(state->m_current_reference, valueToken.StringValue());
|
||||
{
|
||||
const auto& currentReference = state->m_current_reference;
|
||||
if (const auto i = state->m_entries.find(currentReference); i != state->m_entries.end())
|
||||
{
|
||||
std::cout << "Localize: a value for reference \"" << currentReference << "\" was already defined\n";
|
||||
}
|
||||
|
||||
state->m_entries[currentReference] = valueToken.StringValue();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user