1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-30 18:25:16 +01:00

Close #12430: Refactor OBJ_STRING_ID to use strong enum (#12796)

This commit is contained in:
Łukasz Pękalski
2020-08-29 04:36:58 +02:00
committed by GitHub
parent 731a93dc39
commit bfdc1f6d2a
15 changed files with 46 additions and 46 deletions

View File

@@ -26,7 +26,7 @@ void BannerObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* st
_legacyType.banner.scenery_tab_id = OBJECT_ENTRY_INDEX_NULL;
stream->Seek(2, OpenRCT2::STREAM_SEEK_CURRENT);
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
GetStringTable().Read(context, stream, ObjectStringID::NAME);
rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>();
SetPrimarySceneryGroup(&sgEntry);

View File

@@ -21,7 +21,7 @@ void EntranceObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream*
_legacyType.scrolling_mode = stream->ReadValue<uint8_t>();
_legacyType.text_height = stream->ReadValue<uint8_t>();
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
GetStringTable().Read(context, stream, ObjectStringID::NAME);
GetImageTable().Read(context, stream);
}

View File

@@ -30,7 +30,7 @@ void FootpathItemObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStre
_legacyType.path_bit.scenery_tab_id = OBJECT_ENTRY_INDEX_NULL;
stream->Seek(2, OpenRCT2::STREAM_SEEK_CURRENT);
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
GetStringTable().Read(context, stream, ObjectStringID::NAME);
rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>();
SetPrimarySceneryGroup(&sgEntry);

View File

@@ -23,7 +23,7 @@ void FootpathObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream*
_legacyType.scrolling_mode = stream->ReadValue<uint8_t>();
stream->Seek(1, OpenRCT2::STREAM_SEEK_CURRENT);
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
GetStringTable().Read(context, stream, ObjectStringID::NAME);
GetImageTable().Read(context, stream);
// Validate properties

View File

@@ -35,7 +35,7 @@ void LargeSceneryObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStre
_legacyType.large_scenery.scrolling_mode = stream->ReadValue<uint8_t>();
stream->Seek(4, OpenRCT2::STREAM_SEEK_CURRENT);
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
GetStringTable().Read(context, stream, ObjectStringID::NAME);
rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>();
SetPrimarySceneryGroup(&sgEntry);

View File

@@ -51,9 +51,9 @@ std::string Object::GetOverrideString(uint8_t index) const
return String::ToStd(result);
}
std::string Object::GetString(uint8_t index) const
std::string Object::GetString(ObjectStringID index) const
{
auto sz = GetOverrideString(index);
auto sz = GetOverrideString(static_cast<uint8_t>(index));
if (sz.empty())
{
sz = GetStringTable().GetString(index);
@@ -61,7 +61,7 @@ std::string Object::GetString(uint8_t index) const
return sz;
}
std::string Object::GetString(int32_t language, uint8_t index) const
std::string Object::GetString(int32_t language, ObjectStringID index) const
{
return GetStringTable().GetString(language, index);
}
@@ -102,12 +102,12 @@ void Object::SetSourceGames(const std::vector<uint8_t>& sourceGames)
std::string Object::GetName() const
{
return GetString(OBJ_STRING_ID_NAME);
return GetString(ObjectStringID::NAME);
}
std::string Object::GetName(int32_t language) const
{
return GetString(language, OBJ_STRING_ID_NAME);
return GetString(language, ObjectStringID::NAME);
}
void rct_object_entry::SetName(const std::string_view& value)

View File

@@ -187,8 +187,8 @@ protected:
}
std::string GetOverrideString(uint8_t index) const;
std::string GetString(uint8_t index) const;
std::string GetString(int32_t language, uint8_t index) const;
std::string GetString(ObjectStringID index) const;
std::string GetString(int32_t language, ObjectStringID index) const;
public:
explicit Object(const rct_object_entry& entry);

View File

@@ -459,17 +459,17 @@ namespace ObjectJsonHelpers
return result;
}
static uint8_t ParseStringId(const std::string& s)
static ObjectStringID ParseStringId(const std::string& s)
{
if (s == "name")
return OBJ_STRING_ID_NAME;
return ObjectStringID::NAME;
if (s == "description")
return OBJ_STRING_ID_DESCRIPTION;
return ObjectStringID::DESCRIPTION;
if (s == "capacity")
return OBJ_STRING_ID_CAPACITY;
return ObjectStringID::CAPACITY;
if (s == "vehicleName")
return OBJ_STRING_ID_VEHICLE_NAME;
return OBJ_STRING_ID_UNKNOWN;
return ObjectStringID::VEHICLE_NAME;
return ObjectStringID::UNKNOWN;
}
void LoadStrings(const json_t* root, StringTable& stringTable)
@@ -480,7 +480,7 @@ namespace ObjectJsonHelpers
json_object_foreach(jsonStrings, key, jlanguages)
{
auto stringId = ParseStringId(key);
if (stringId != OBJ_STRING_ID_UNKNOWN)
if (stringId != ObjectStringID::UNKNOWN)
{
const char* locale;
json_t* jstring;

View File

@@ -86,9 +86,9 @@ void RideObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
_legacyType.shop_item[0] = stream->ReadValue<uint8_t>();
_legacyType.shop_item[1] = stream->ReadValue<uint8_t>();
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
GetStringTable().Read(context, stream, OBJ_STRING_ID_DESCRIPTION);
GetStringTable().Read(context, stream, OBJ_STRING_ID_CAPACITY);
GetStringTable().Read(context, stream, ObjectStringID::NAME);
GetStringTable().Read(context, stream, ObjectStringID::DESCRIPTION);
GetStringTable().Read(context, stream, ObjectStringID::CAPACITY);
// Read preset colours, by default there are 32
_presetColours.count = stream->ReadValue<uint8_t>();
@@ -393,12 +393,12 @@ void RideObject::DrawPreview(rct_drawpixelinfo* dpi, [[maybe_unused]] int32_t wi
std::string RideObject::GetDescription() const
{
return GetString(OBJ_STRING_ID_DESCRIPTION);
return GetString(ObjectStringID::DESCRIPTION);
}
std::string RideObject::GetCapacity() const
{
return GetString(OBJ_STRING_ID_CAPACITY);
return GetString(ObjectStringID::CAPACITY);
}
void RideObject::SetRepositoryItem(ObjectRepositoryItem* item) const

View File

@@ -36,7 +36,7 @@ void SceneryGroupObject::ReadLegacy(IReadObjectContext* context, IStream* stream
stream->Seek(1, STREAM_SEEK_CURRENT); // pad_109;
_legacyType.entertainer_costumes = stream->ReadValue<uint32_t>();
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
GetStringTable().Read(context, stream, ObjectStringID::NAME);
_items = ReadItems(stream);
GetImageTable().Read(context, stream);
}

View File

@@ -37,7 +37,7 @@ void SmallSceneryObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStre
_legacyType.small_scenery.num_frames = stream->ReadValue<uint16_t>();
_legacyType.small_scenery.scenery_tab_id = OBJECT_ENTRY_INDEX_NULL;
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
GetStringTable().Read(context, stream, ObjectStringID::NAME);
rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>();
SetPrimarySceneryGroup(&sgEntry);

View File

@@ -47,7 +47,7 @@ static bool StringIsBlank(const utf8* str)
return true;
}
void StringTable::Read(IReadObjectContext* context, OpenRCT2::IStream* stream, uint8_t id)
void StringTable::Read(IReadObjectContext* context, OpenRCT2::IStream* stream, ObjectStringID id)
{
try
{
@@ -78,7 +78,7 @@ void StringTable::Read(IReadObjectContext* context, OpenRCT2::IStream* stream, u
Sort();
}
std::string StringTable::GetString(uint8_t id) const
std::string StringTable::GetString(ObjectStringID id) const
{
for (auto& string : _strings)
{
@@ -90,7 +90,7 @@ std::string StringTable::GetString(uint8_t id) const
return std::string();
}
std::string StringTable::GetString(uint8_t language, uint8_t id) const
std::string StringTable::GetString(uint8_t language, ObjectStringID id) const
{
for (auto& string : _strings)
{
@@ -102,7 +102,7 @@ std::string StringTable::GetString(uint8_t language, uint8_t id) const
return std::string();
}
void StringTable::SetString(uint8_t id, uint8_t language, const std::string& text)
void StringTable::SetString(ObjectStringID id, uint8_t language, const std::string& text)
{
StringTableEntry entry;
entry.Id = id;

View File

@@ -21,21 +21,21 @@ namespace OpenRCT2
struct IStream;
}
enum OBJ_STRING_ID : uint8_t
enum class ObjectStringID : uint8_t
{
OBJ_STRING_ID_UNKNOWN = 255,
OBJ_STRING_ID_NAME = 0,
OBJ_STRING_ID_DESCRIPTION,
OBJ_STRING_ID_SCENARIO_NAME = 0,
OBJ_STRING_ID_PARK_NAME = 1,
OBJ_STRING_ID_SCENARIO_DETAILS = 2,
OBJ_STRING_ID_CAPACITY = 2,
OBJ_STRING_ID_VEHICLE_NAME = 3,
UNKNOWN = 255,
NAME = 0,
DESCRIPTION,
SCENARIO_NAME = 0,
PARK_NAME = 1,
SCENARIO_DETAILS = 2,
CAPACITY = 2,
VEHICLE_NAME = 3,
};
struct StringTableEntry
{
uint8_t Id = OBJ_STRING_ID_UNKNOWN;
ObjectStringID Id = ObjectStringID::UNKNOWN;
uint8_t LanguageId = LANGUAGE_UNDEFINED;
std::string Text;
};
@@ -50,9 +50,9 @@ public:
StringTable(const StringTable&) = delete;
StringTable& operator=(const StringTable&) = delete;
void Read(IReadObjectContext* context, OpenRCT2::IStream* stream, uint8_t id);
void Read(IReadObjectContext* context, OpenRCT2::IStream* stream, ObjectStringID id);
void Sort();
std::string GetString(uint8_t id) const;
std::string GetString(uint8_t language, uint8_t id) const;
void SetString(uint8_t id, uint8_t language, const std::string& text);
std::string GetString(ObjectStringID id) const;
std::string GetString(uint8_t language, ObjectStringID id) const;
void SetString(ObjectStringID id, uint8_t language, const std::string& text);
};

View File

@@ -29,7 +29,7 @@ void WallObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stre
stream->Seek(1, OpenRCT2::STREAM_SEEK_CURRENT);
_legacyType.wall.scrolling_mode = stream->ReadValue<uint8_t>();
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
GetStringTable().Read(context, stream, ObjectStringID::NAME);
rct_object_entry sgEntry = stream->ReadValue<rct_object_entry>();
SetPrimarySceneryGroup(&sgEntry);

View File

@@ -25,7 +25,7 @@ void WaterObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* str
stream->Seek(14, OpenRCT2::STREAM_SEEK_CURRENT);
_legacyType.flags = stream->ReadValue<uint16_t>();
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
GetStringTable().Read(context, stream, ObjectStringID::NAME);
GetImageTable().Read(context, stream);
}