mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #20271 from duncanspumpkin/objDescriptor
Rework Object Identifier callers
This commit is contained in:
commit
b291c87d51
|
@ -4138,17 +4138,6 @@ STR_SCNR :Fort Anachronism
|
|||
STR_PARK :Fort Anachronism
|
||||
STR_DTLS :
|
||||
|
||||
###########
|
||||
# Scenery #
|
||||
###########
|
||||
|
||||
## Start OpenRCT2 Official
|
||||
|
||||
[TTPIRF05]
|
||||
STR_NAME :Roof
|
||||
|
||||
## End OpenRCT2 Official
|
||||
|
||||
###############################################################################
|
||||
## RCT2 Scenarios
|
||||
###############################################################################
|
||||
|
|
|
@ -28,21 +28,11 @@
|
|||
|
||||
// Don't try to load more than language files that exceed 64 MiB
|
||||
constexpr uint64_t MAX_LANGUAGE_SIZE = 64 * 1024 * 1024;
|
||||
constexpr uint64_t MAX_OBJECT_OVERRIDES = 4096;
|
||||
constexpr uint64_t MAX_SCENARIO_OVERRIDES = 4096;
|
||||
|
||||
constexpr StringId ObjectOverrideBase = 0x6000;
|
||||
constexpr int32_t ObjectOverrideMaxStringCount = 3;
|
||||
|
||||
constexpr StringId ScenarioOverrideBase = 0x7000;
|
||||
constexpr int32_t ScenarioOverrideMaxStringCount = 3;
|
||||
|
||||
struct ObjectOverride
|
||||
{
|
||||
char name[8] = { 0 };
|
||||
std::string strings[ObjectOverrideMaxStringCount];
|
||||
};
|
||||
|
||||
struct ScenarioOverride
|
||||
{
|
||||
std::string filename;
|
||||
|
@ -54,14 +44,12 @@ class LanguagePack final : public ILanguagePack
|
|||
private:
|
||||
uint16_t const _id;
|
||||
std::vector<std::string> _strings;
|
||||
std::vector<ObjectOverride> _objectOverrides;
|
||||
std::vector<ScenarioOverride> _scenarioOverrides;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Parsing work data
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
std::string _currentGroup;
|
||||
ObjectOverride* _currentObjectOverride = nullptr;
|
||||
ScenarioOverride* _currentScenarioOverride = nullptr;
|
||||
|
||||
public:
|
||||
|
@ -112,7 +100,6 @@ public:
|
|||
|
||||
// Clean up the parsing work data
|
||||
_currentGroup.clear();
|
||||
_currentObjectOverride = nullptr;
|
||||
_currentScenarioOverride = nullptr;
|
||||
}
|
||||
|
||||
|
@ -159,21 +146,6 @@ public:
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (stringId >= ObjectOverrideBase)
|
||||
{
|
||||
int32_t offset = stringId - ObjectOverrideBase;
|
||||
int32_t ooIndex = offset / ObjectOverrideMaxStringCount;
|
||||
int32_t ooStringIndex = offset % ObjectOverrideMaxStringCount;
|
||||
|
||||
if (_objectOverrides.size() > static_cast<size_t>(ooIndex)
|
||||
&& !_objectOverrides[ooIndex].strings[ooStringIndex].empty())
|
||||
{
|
||||
return _objectOverrides[ooIndex].strings[ooStringIndex].c_str();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if ((_strings.size() > static_cast<size_t>(stringId)) && !_strings[stringId].empty())
|
||||
{
|
||||
return _strings[stringId].c_str();
|
||||
|
@ -182,27 +154,6 @@ public:
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
StringId GetObjectOverrideStringId(std::string_view legacyIdentifier, uint8_t index) override
|
||||
{
|
||||
Guard::Assert(index < ObjectOverrideMaxStringCount);
|
||||
|
||||
int32_t ooIndex = 0;
|
||||
for (const ObjectOverride& objectOverride : _objectOverrides)
|
||||
{
|
||||
if (std::string_view(objectOverride.name, 8) == legacyIdentifier)
|
||||
{
|
||||
if (objectOverride.strings[index].empty())
|
||||
{
|
||||
return STR_NONE;
|
||||
}
|
||||
return ObjectOverrideBase + (ooIndex * ObjectOverrideMaxStringCount) + index;
|
||||
}
|
||||
ooIndex++;
|
||||
}
|
||||
|
||||
return STR_NONE;
|
||||
}
|
||||
|
||||
StringId GetScenarioOverrideStringId(const utf8* scenarioFilename, uint8_t index) override
|
||||
{
|
||||
Guard::ArgumentNotNull(scenarioFilename);
|
||||
|
@ -226,18 +177,6 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
ObjectOverride* GetObjectOverride(const std::string& objectIdentifier)
|
||||
{
|
||||
for (auto& oo : _objectOverrides)
|
||||
{
|
||||
if (strncmp(oo.name, objectIdentifier.c_str(), 8) == 0)
|
||||
{
|
||||
return &oo;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ScenarioOverride* GetScenarioOverride(const std::string& scenarioIdentifier)
|
||||
{
|
||||
for (auto& so : _scenarioOverrides)
|
||||
|
@ -355,14 +294,13 @@ private:
|
|||
|
||||
void ParseGroupObject(IStringReader* reader)
|
||||
{
|
||||
auto sb = StringBuilder();
|
||||
// THIS IS NO LONGER USED SO WE ARE JUST SKIPPING OVER
|
||||
codepoint_t codepoint;
|
||||
|
||||
// Should have already deduced that the next codepoint is a [
|
||||
reader->Skip();
|
||||
|
||||
// Read string up to ] or line end
|
||||
bool closedCorrectly = false;
|
||||
while (reader->TryPeek(&codepoint))
|
||||
{
|
||||
if (IsNewLine(codepoint))
|
||||
|
@ -371,36 +309,10 @@ private:
|
|||
reader->Skip();
|
||||
if (codepoint == ']')
|
||||
{
|
||||
closedCorrectly = true;
|
||||
break;
|
||||
}
|
||||
sb.Append(codepoint);
|
||||
}
|
||||
|
||||
if (closedCorrectly)
|
||||
{
|
||||
while (sb.GetLength() < 8)
|
||||
{
|
||||
sb.Append(' ');
|
||||
}
|
||||
if (sb.GetLength() == 8)
|
||||
{
|
||||
_currentGroup = sb.GetStdString();
|
||||
_currentObjectOverride = GetObjectOverride(_currentGroup);
|
||||
_currentScenarioOverride = nullptr;
|
||||
if (_currentObjectOverride == nullptr)
|
||||
{
|
||||
if (_objectOverrides.size() == MAX_OBJECT_OVERRIDES)
|
||||
{
|
||||
LOG_WARNING("Maximum number of localised object strings exceeded.");
|
||||
}
|
||||
|
||||
_objectOverrides.emplace_back();
|
||||
_currentObjectOverride = &_objectOverrides[_objectOverrides.size() - 1];
|
||||
std::copy_n(_currentGroup.c_str(), 8, _currentObjectOverride->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
_currentGroup.clear();
|
||||
}
|
||||
|
||||
void ParseGroupScenario(IStringReader* reader)
|
||||
|
@ -430,7 +342,6 @@ private:
|
|||
if (closedCorrectly)
|
||||
{
|
||||
_currentGroup = sb.GetStdString();
|
||||
_currentObjectOverride = nullptr;
|
||||
_currentScenarioOverride = GetScenarioOverride(_currentGroup);
|
||||
if (_currentScenarioOverride == nullptr)
|
||||
{
|
||||
|
@ -557,11 +468,7 @@ private:
|
|||
}
|
||||
else
|
||||
{
|
||||
if (_currentObjectOverride != nullptr)
|
||||
{
|
||||
_currentObjectOverride->strings[stringId] = s;
|
||||
}
|
||||
else
|
||||
if (_currentScenarioOverride != nullptr)
|
||||
{
|
||||
_currentScenarioOverride->strings[stringId] = std::move(s);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ struct ILanguagePack
|
|||
virtual void RemoveString(StringId stringId) abstract;
|
||||
virtual void SetString(StringId stringId, const std::string& str) abstract;
|
||||
virtual const utf8* GetString(StringId stringId) const abstract;
|
||||
virtual StringId GetObjectOverrideStringId(std::string_view legacyIdentifier, uint8_t index) abstract;
|
||||
virtual StringId GetScenarioOverrideStringId(const utf8* scenarioFilename, uint8_t index) abstract;
|
||||
};
|
||||
|
||||
|
|
|
@ -153,15 +153,6 @@ std::tuple<StringId, StringId, StringId> LocalisationService::GetLocalisedScenar
|
|||
return std::make_tuple(result0, result1, result2);
|
||||
}
|
||||
|
||||
StringId LocalisationService::GetObjectOverrideStringId(std::string_view legacyIdentifier, uint8_t index) const
|
||||
{
|
||||
if (_loadedLanguages.empty())
|
||||
{
|
||||
return STR_NONE;
|
||||
}
|
||||
return _loadedLanguages[0]->GetObjectOverrideStringId(legacyIdentifier, index);
|
||||
}
|
||||
|
||||
StringId LocalisationService::AllocateObjectString(const std::string& target)
|
||||
{
|
||||
if (_availableObjectStringIds.empty())
|
||||
|
|
|
@ -59,7 +59,6 @@ namespace OpenRCT2::Localisation
|
|||
|
||||
const char* GetString(StringId id) const;
|
||||
std::tuple<StringId, StringId, StringId> GetLocalisedScenarioStrings(const std::string& scenarioFilename) const;
|
||||
StringId GetObjectOverrideStringId(std::string_view legacyIdentifier, uint8_t index) const;
|
||||
std::string GetLanguagePath(uint32_t languageId) const;
|
||||
|
||||
void OpenLanguage(int32_t id);
|
||||
|
|
|
@ -41,10 +41,9 @@ void BannerObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* st
|
|||
|
||||
// Add banners to 'Signs and items for footpaths' group, rather than lumping them in the Miscellaneous tab.
|
||||
// Since this is already done the other way round for original items, avoid adding those to prevent duplicates.
|
||||
auto identifier = GetLegacyIdentifier();
|
||||
|
||||
auto& objectRepository = context->GetObjectRepository();
|
||||
auto item = objectRepository.FindObjectLegacy(identifier);
|
||||
auto item = objectRepository.FindObject(GetDescriptor());
|
||||
if (item != nullptr)
|
||||
{
|
||||
auto sourceGame = item->GetFirstSourceGame();
|
||||
|
|
|
@ -156,28 +156,9 @@ void Object::PopulateTablesFromJson(IReadObjectContext* context, json_t& root)
|
|||
_usesFallbackImages = _imageTable.ReadJson(context, root);
|
||||
}
|
||||
|
||||
std::string Object::GetOverrideString(uint8_t index) const
|
||||
{
|
||||
auto legacyIdentifier = GetLegacyIdentifier();
|
||||
const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();
|
||||
auto stringId = localisationService.GetObjectOverrideStringId(legacyIdentifier, index);
|
||||
|
||||
const utf8* result = nullptr;
|
||||
if (stringId != STR_NONE)
|
||||
{
|
||||
result = LanguageGetString(stringId);
|
||||
}
|
||||
return String::ToStd(result);
|
||||
}
|
||||
|
||||
std::string Object::GetString(ObjectStringID index) const
|
||||
{
|
||||
auto sz = GetOverrideString(static_cast<uint8_t>(index));
|
||||
if (sz.empty())
|
||||
{
|
||||
sz = GetStringTable().GetString(index);
|
||||
}
|
||||
return sz;
|
||||
return GetStringTable().GetString(index);
|
||||
}
|
||||
|
||||
std::string Object::GetString(int32_t language, ObjectStringID index) const
|
||||
|
|
|
@ -223,7 +223,6 @@ protected:
|
|||
*/
|
||||
void PopulateTablesFromJson(IReadObjectContext* context, json_t& root);
|
||||
|
||||
std::string GetOverrideString(uint8_t index) const;
|
||||
std::string GetString(ObjectStringID index) const;
|
||||
std::string GetString(int32_t language, ObjectStringID index) const;
|
||||
|
||||
|
@ -268,7 +267,7 @@ public:
|
|||
return _usesFallbackImages;
|
||||
}
|
||||
|
||||
// Legacy data structures
|
||||
// DONOT USE THIS CAN LEAD TO OBJECT COLLISIONS
|
||||
std::string_view GetLegacyIdentifier() const
|
||||
{
|
||||
return _descriptor.GetName();
|
||||
|
|
|
@ -45,10 +45,9 @@ void PathAdditionObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStre
|
|||
|
||||
// Add path additions to 'Signs and items for footpaths' group, rather than lumping them in the Miscellaneous tab.
|
||||
// Since this is already done the other way round for original items, avoid adding those to prevent duplicates.
|
||||
auto identifier = GetLegacyIdentifier();
|
||||
|
||||
auto& objectRepository = context->GetObjectRepository();
|
||||
auto item = objectRepository.FindObjectLegacy(identifier);
|
||||
auto item = objectRepository.FindObject(GetDescriptor());
|
||||
if (item != nullptr)
|
||||
{
|
||||
auto sourceGame = item->GetFirstSourceGame();
|
||||
|
|
|
@ -47,12 +47,9 @@ TEST_F(LanguagePackTest, language_pack_simple)
|
|||
ASSERT_STREQ(lang->GetString(2), "Spiral Roller Coaster");
|
||||
ASSERT_EQ(lang->GetScenarioOverrideStringId("Arid Heights", 0), 0x7000);
|
||||
ASSERT_STREQ(lang->GetString(0x7000), "Arid Heights scenario string");
|
||||
ASSERT_EQ(lang->GetObjectOverrideStringId("CONDORRD", 0), 0x6000);
|
||||
ASSERT_STREQ(lang->GetString(0x6000), "my test ride");
|
||||
// Test some negatives too
|
||||
ASSERT_EQ(lang->GetString(1000), nullptr);
|
||||
ASSERT_EQ(lang->GetScenarioOverrideStringId("No such park", 0), STR_NONE);
|
||||
ASSERT_EQ(lang->GetObjectOverrideStringId(" ", 0), STR_NONE);
|
||||
}
|
||||
|
||||
TEST_F(LanguagePackTest, language_pack_multibyte)
|
||||
|
@ -65,8 +62,6 @@ TEST_F(LanguagePackTest, language_pack_multibyte)
|
|||
ASSERT_EQ(lang->GetScenarioOverrideStringId("Forest Frontiers", 2), 0x7002);
|
||||
ASSERT_STREQ(lang->GetString(0x7000), "Forest Frontiers");
|
||||
ASSERT_STREQ(lang->GetString(0x7002), u8"在隱藏於森林深處的清空範圍中, 建造一個很受歡迎的樂園");
|
||||
ASSERT_EQ(lang->GetObjectOverrideStringId("CONDORRD", 0), 0x6000);
|
||||
ASSERT_STREQ(lang->GetString(0x6000), u8"神鷹暢遊");
|
||||
}
|
||||
|
||||
const utf8* LanguagePackTest::LanguageEnGB = "# STR_XXXX part is read and XXXX becomes the string id number.\n"
|
||||
|
|
Loading…
Reference in New Issue