forked from Laupetin/OpenAssetTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Laupetin#77 from Laupetin/refactor/localize-remove…
…-duplication Remove duplicated code in localize asset loading
- Loading branch information
Showing
18 changed files
with
149 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "CommonLocalizeEntry.h" | ||
|
||
CommonLocalizeEntry::CommonLocalizeEntry() = default; | ||
|
||
CommonLocalizeEntry::CommonLocalizeEntry(std::string key, std::string value) | ||
: m_key(std::move(key)), | ||
m_value(std::move(value)) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
#include <string> | ||
|
||
class CommonLocalizeEntry | ||
{ | ||
public: | ||
std::string m_key; | ||
std::string m_value; | ||
|
||
CommonLocalizeEntry(); | ||
CommonLocalizeEntry(std::string key, std::string value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderLocalizeEntry.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/ObjLoading/Game/IW5/AssetLoaders/AssetLoaderLocalizeEntry.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "LocalizeCommonAssetLoader.h" | ||
|
||
#include "Localize/LocalizeCommon.h" | ||
#include "Localize/LocalizeReadingZoneState.h" | ||
#include "Localize/Parsing/LocalizeFileReader.h" | ||
|
||
#include <sstream> | ||
|
||
LocalizeCommonAssetLoader::LocalizeCommonAssetLoader(std::function<void(const CommonLocalizeEntry&)> entryCallback) | ||
: m_entry_callback(std::move(entryCallback)) | ||
{ | ||
} | ||
|
||
std::string LocalizeCommonAssetLoader::GetFileName(const std::string& assetName, Zone* zone) const | ||
{ | ||
std::ostringstream ss; | ||
ss << LocalizeCommon::GetNameOfLanguage(zone->m_language) << "/localizedstrings/" << assetName << ".str"; | ||
return ss.str(); | ||
} | ||
|
||
bool LocalizeCommonAssetLoader::LoadLocalizeAsset(const std::string& assetName, ISearchPath* searchPath, IAssetLoadingManager* manager, Zone* zone) const | ||
{ | ||
std::string fileName = GetFileName(assetName, zone); | ||
|
||
const auto file = searchPath->Open(fileName); | ||
if (!file.IsOpen()) | ||
return false; | ||
|
||
auto* zoneState = manager->GetAssetLoadingContext()->GetZoneAssetLoaderState<LocalizeReadingZoneState>(); | ||
LocalizeFileReader reader(*file.m_stream, assetName, zone->m_language, zoneState); | ||
|
||
std::vector<CommonLocalizeEntry> localizeEntries; | ||
if (!reader.ReadLocalizeFile(localizeEntries)) | ||
return false; | ||
|
||
for (const auto& entry : localizeEntries) | ||
{ | ||
m_entry_callback(entry); | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include "AssetLoading/IAssetLoadingManager.h" | ||
#include "Localize/CommonLocalizeEntry.h" | ||
#include "SearchPath/ISearchPath.h" | ||
#include "Zone/Zone.h" | ||
|
||
#include <functional> | ||
#include <string> | ||
|
||
class LocalizeCommonAssetLoader | ||
{ | ||
public: | ||
explicit LocalizeCommonAssetLoader(std::function<void(const CommonLocalizeEntry&)> entryCallback); | ||
|
||
bool LoadLocalizeAsset(const std::string& assetName, ISearchPath* searchPath, IAssetLoadingManager* manager, Zone* zone) const; | ||
|
||
private: | ||
std::string GetFileName(const std::string& assetName, Zone* zone) const; | ||
|
||
std::function<void(const CommonLocalizeEntry&)> m_entry_callback; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
#include "LocalizeFileParserState.h" | ||
|
||
#include "Localize/LocalizeCommon.h" | ||
#include "Utils/StringUtils.h" | ||
|
||
LocalizeFileParserState::LocalizeFileParserState(const GameLanguage language, LocalizeReadingZoneState* zoneState) | ||
: m_end(false), | ||
m_language(language), | ||
m_zone_state(zoneState) | ||
{ | ||
m_language_name_caps = LocalizeCommon::GetNameOfLanguage(m_language); | ||
for (auto& c : m_language_name_caps) | ||
c = static_cast<char>(toupper(c)); | ||
utils::MakeStringUpperCase(m_language_name_caps); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.