1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-04 13:42:55 +01:00

Split identifier and legacyIdentifier on Object

This commit is contained in:
Ted John
2020-05-07 19:35:30 +01:00
parent 3417c10a61
commit 46d69126ea
17 changed files with 121 additions and 104 deletions

View File

@@ -480,10 +480,18 @@ declare global {
readonly index: number;
/**
* The unique name identifier of the object, e.g. "BURGB ".
* This may have trailing spaces if the name is shorter than 8 characters.
* The unique identifier of the object, e.g. "rct2.burgb".
* Only JSON objects will have an identifier.
*/
readonly identifier: string;
/**
* The original unique identifier of the object, e.g. "BURGB ".
* This may have trailing spaces if the name is shorter than 8 characters.
* Only .DAT objects or JSON objects based on .DAT objects will have legacy identifiers.
*/
readonly legacyIdentifier: string;
/**
* The name in the user's current language.
*/

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -125,12 +125,6 @@ void language_free_object_string(rct_string_id stringId)
localisationService.FreeObjectString(stringId);
}
rct_string_id language_get_object_override_string_id(const char* identifier, uint8_t index)
{
const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();
return localisationService.GetObjectOverrideStringId(identifier, index);
}
rct_string_id language_allocate_object_string(const std::string& target)
{
auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -105,7 +105,6 @@ std::string rct2_to_utf8(const std::string_view& src, RCT2LanguageId languageId)
std::string utf8_to_rct2(const std::string_view& src);
bool language_get_localised_scenario_strings(const utf8* scenarioFilename, rct_string_id* outStringIds);
void language_free_object_string(rct_string_id stringId);
rct_string_id language_get_object_override_string_id(const char* identifier, uint8_t index);
rct_string_id language_allocate_object_string(const std::string& target);
std::string language_convert_string_to_tokens(const std::string_view& s);
std::string language_convert_string(const std::string_view& s);

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -198,15 +198,14 @@ public:
}
}
rct_string_id GetObjectOverrideStringId(const char* objectIdentifier, uint8_t index) override
rct_string_id GetObjectOverrideStringId(const std::string_view& legacyIdentifier, uint8_t index) override
{
Guard::ArgumentNotNull(objectIdentifier);
Guard::Assert(index < ObjectOverrideMaxStringCount);
int32_t ooIndex = 0;
for (const ObjectOverride& objectOverride : _objectOverrides)
{
if (strncmp(objectOverride.name, objectIdentifier, 8) == 0)
if (std::string_view(objectOverride.name, 8) == legacyIdentifier)
{
if (objectOverride.strings[index].empty())
{

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -12,6 +12,7 @@
#include "../common.h"
#include <string>
#include <string_view>
interface ILanguagePack
{
@@ -23,7 +24,7 @@ interface ILanguagePack
virtual void RemoveString(rct_string_id stringId) abstract;
virtual void SetString(rct_string_id stringId, const std::string& str) abstract;
virtual const utf8* GetString(rct_string_id stringId) const abstract;
virtual rct_string_id GetObjectOverrideStringId(const char* objectIdentifier, uint8_t index) abstract;
virtual rct_string_id GetObjectOverrideStringId(const std::string_view& legacyIdentifier, uint8_t index) abstract;
virtual rct_string_id GetScenarioOverrideStringId(const utf8* scenarioFilename, uint8_t index) abstract;
};

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -122,13 +122,13 @@ std::tuple<rct_string_id, rct_string_id, rct_string_id> LocalisationService::Get
return std::make_tuple(result0, result1, result2);
}
rct_string_id LocalisationService::GetObjectOverrideStringId(const char* identifier, uint8_t index) const
rct_string_id LocalisationService::GetObjectOverrideStringId(const std::string_view& legacyIdentifier, uint8_t index) const
{
if (_languageCurrent == nullptr)
{
return STR_NONE;
}
return _languageCurrent->GetObjectOverrideStringId(identifier, index);
return _languageCurrent->GetObjectOverrideStringId(legacyIdentifier, index);
}
rct_string_id LocalisationService::AllocateObjectString(const std::string& target)

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -14,6 +14,7 @@
#include <memory>
#include <stack>
#include <string>
#include <string_view>
#include <tuple>
interface ILanguagePack;
@@ -56,7 +57,7 @@ namespace OpenRCT2::Localisation
const char* GetString(rct_string_id id) const;
std::tuple<rct_string_id, rct_string_id, rct_string_id> GetLocalisedScenarioStrings(
const std::string& scenarioFilename) const;
rct_string_id GetObjectOverrideStringId(const char* identifier, uint8_t index) const;
rct_string_id GetObjectOverrideStringId(const std::string_view& legacyIdentifier, uint8_t index) const;
std::string GetLanguagePath(uint32_t languageId) const;
void OpenLanguage(int32_t id, IObjectManager& objectManager);

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -41,7 +41,7 @@ void BannerObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
// 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 = GetIdentifier();
auto identifier = GetLegacyIdentifier();
auto& objectRepository = context->GetObjectRepository();
auto item = objectRepository.FindObject(identifier);

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -45,7 +45,7 @@ void FootpathItemObject::ReadLegacy(IReadObjectContext* context, IStream* stream
// Add path bits 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 = GetIdentifier();
auto identifier = GetLegacyIdentifier();
auto& objectRepository = context->GetObjectRepository();
auto item = objectRepository.FindObject(identifier);

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -9,28 +9,22 @@
#include "Object.h"
#include "../Context.h"
#include "../core/Memory.hpp"
#include "../core/String.hpp"
#include "../localisation/Language.h"
#include "../localisation/LocalisationService.h"
#include "../localisation/StringIds.h"
#include "../world/Scenery.h"
#include "ObjectLimits.h"
#include <algorithm>
#include <cstring>
#include <stdexcept>
Object::Object(const rct_object_entry& entry)
{
_objectEntry = entry;
char name[DAT_NAME_LENGTH + 1] = { 0 };
std::copy_n(entry.name, DAT_NAME_LENGTH, name);
_identifier = String::Duplicate(name);
}
Object::~Object()
{
Memory::Free(_identifier);
}
void* Object::GetLegacyData()
@@ -45,8 +39,9 @@ void Object::ReadLegacy(IReadObjectContext* context, IStream* stream)
std::string Object::GetOverrideString(uint8_t index) const
{
const char* identifier = GetIdentifier();
rct_string_id stringId = language_get_object_override_string_id(identifier, index);
auto legacyIdentifier = GetLegacyIdentifier();
const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();
auto stringId = localisationService.GetObjectOverrideStringId(legacyIdentifier, index);
const utf8* result = nullptr;
if (stringId != STR_NONE)
@@ -115,6 +110,12 @@ std::string Object::GetName(int32_t language) const
return GetString(language, OBJ_STRING_ID_NAME);
}
void rct_object_entry::SetName(const std::string_view& value)
{
std::memset(name, ' ', sizeof(name));
std::memcpy(name, value.data(), std::min(sizeof(name), value.size()));
}
std::optional<uint8_t> rct_object_entry::GetSceneryType() const
{
switch (GetType())

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -13,6 +13,7 @@
#include "ImageTable.h"
#include "StringTable.h"
#include <algorithm>
#include <optional>
#include <string_view>
#include <vector>
@@ -96,19 +97,7 @@ struct rct_object_entry
return std::string_view(name, std::size(name));
}
void SetName(const char* value)
{
auto src = value;
for (size_t i = 0; i < sizeof(name); i++)
{
auto dc = ' ';
if (*src != '\0')
{
dc = *src++;
}
name[i] = dc;
}
}
void SetName(const std::string_view& value);
uint8_t GetType() const
{
@@ -155,6 +144,7 @@ interface IReadObjectContext
{
virtual ~IReadObjectContext() = default;
virtual std::string_view GetObjectIdentifier() abstract;
virtual IObjectRepository& GetObjectRepository() abstract;
virtual bool ShouldLoadImages() abstract;
virtual std::vector<uint8_t> GetData(const std::string_view& path) abstract;
@@ -171,7 +161,7 @@ interface IReadObjectContext
class Object
{
private:
char* _identifier;
std::string _identifier;
rct_object_entry _objectEntry{};
StringTable _stringTable;
ImageTable _imageTable;
@@ -198,7 +188,16 @@ protected:
public:
explicit Object(const rct_object_entry& entry);
virtual ~Object();
virtual ~Object() = default;
std::string_view GetIdentifier() const
{
return _identifier;
}
void SetIdentifier(const std::string_view& identifier)
{
_identifier = identifier;
}
void MarkAsJsonObject()
{
@@ -211,9 +210,9 @@ public:
};
// Legacy data structures
const char* GetIdentifier() const
std::string_view GetLegacyIdentifier() const
{
return _identifier;
return _objectEntry.GetName();
}
const rct_object_entry* GetObjectEntry() const
{

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -87,7 +87,7 @@ private:
IObjectRepository& _objectRepository;
const IFileDataRetriever* _fileDataRetriever;
std::string _objectName;
std::string _identifier;
bool _loadImages;
std::string _basePath;
bool _wasWarning = false;
@@ -104,15 +104,20 @@ public:
}
ReadObjectContext(
IObjectRepository& objectRepository, const std::string& objectName, bool loadImages,
IObjectRepository& objectRepository, const std::string& identifier, bool loadImages,
const IFileDataRetriever* fileDataRetriever)
: _objectRepository(objectRepository)
, _fileDataRetriever(fileDataRetriever)
, _objectName(objectName)
, _identifier(identifier)
, _loadImages(loadImages)
{
}
std::string_view GetObjectIdentifier() override
{
return _identifier;
}
IObjectRepository& GetObjectRepository() override
{
return _objectRepository;
@@ -138,7 +143,7 @@ public:
if (!String::IsNullOrEmpty(text))
{
Console::Error::WriteLine("[%s] Warning (%d): %s", _objectName.c_str(), code, text);
Console::Error::WriteLine("[%s] Warning (%d): %s", _identifier.c_str(), code, text);
}
}
@@ -148,7 +153,7 @@ public:
if (!String::IsNullOrEmpty(text))
{
Console::Error::WriteLine("[%s] Error (%d): %s", _objectName.c_str(), code, text);
Console::Error::WriteLine("[%s] Error (%d): %s", _identifier.c_str(), code, text);
}
}
};
@@ -429,6 +434,7 @@ namespace ObjectFactory
std::memcpy(entry.name, originalName.c_str(), minLength);
result = CreateObject(entry);
result->SetIdentifier(id);
result->MarkAsJsonObject();
auto readContext = ReadObjectContext(objectRepository, id, !gOpenRCT2NoGraphics, fileRetriever);
result->ReadJson(&readContext, jRoot);

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -252,12 +252,10 @@ public:
return _items.data();
}
const ObjectRepositoryItem* FindObject(const utf8* name) const override
const ObjectRepositoryItem* FindObject(const std::string_view& legacyIdentifier) const override
{
rct_object_entry entry = {};
utf8 entryName[9] = { ' ' };
String::Set(entryName, sizeof(entryName), name);
std::copy_n(entryName, 8, entry.name);
entry.SetName(legacyIdentifier);
auto kvp = _itemMap.find(entry);
if (kvp != _itemMap.end())

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -67,7 +67,7 @@ interface IObjectRepository
virtual void Construct(int32_t language) abstract;
virtual size_t GetNumObjects() const abstract;
virtual const ObjectRepositoryItem* GetObjects() const abstract;
virtual const ObjectRepositoryItem* FindObject(const utf8* name) const abstract;
virtual const ObjectRepositoryItem* FindObject(const std::string_view& legacyIdentifier) const abstract;
virtual const ObjectRepositoryItem* FindObject(const rct_object_entry* objectEntry) const abstract;
virtual Object* LoadObject(const ObjectRepositoryItem* ori) abstract;

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -156,14 +156,14 @@ std::vector<uint8_t> SmallSceneryObject::ReadFrameOffsets(IStream* stream)
// clang-format off
void SmallSceneryObject::PerformFixes()
{
std::string identifier = GetIdentifier();
auto identifier = GetLegacyIdentifier();
static const rct_object_entry scgWalls = Object::GetScgWallsHeader();
// ToonTowner's base blocks. Make them allow supports on top and put them in the Walls and Roofs group.
if (String::Equals(identifier, "XXBBCL01") ||
String::Equals(identifier, "XXBBMD01") ||
String::Equals(identifier, "XXBBBR01") ||
String::Equals(identifier, "ARBASE2 "))
if (identifier == "XXBBCL01" ||
identifier == "XXBBMD01" ||
identifier == "XXBBBR01" ||
identifier == "ARBASE2 ")
{
SetPrimarySceneryGroup(&scgWalls);
@@ -171,48 +171,48 @@ void SmallSceneryObject::PerformFixes()
}
// ToonTowner's regular roofs. Put them in the Walls and Roofs group.
if (String::Equals(identifier, "TTRFTL02") ||
String::Equals(identifier, "TTRFTL03") ||
String::Equals(identifier, "TTRFTL04") ||
String::Equals(identifier, "TTRFTL07") ||
String::Equals(identifier, "TTRFTL08"))
if (identifier == "TTRFTL02" ||
identifier == "TTRFTL03" ||
identifier == "TTRFTL04" ||
identifier == "TTRFTL07" ||
identifier == "TTRFTL08")
{
SetPrimarySceneryGroup(&scgWalls);
}
// ToonTowner's Pirate roofs. Make them show up in the Pirate Theming.
if (String::Equals(identifier, "TTPIRF02") ||
String::Equals(identifier, "TTPIRF03") ||
String::Equals(identifier, "TTPIRF04") ||
String::Equals(identifier, "TTPIRF05") ||
String::Equals(identifier, "TTPIRF07") ||
String::Equals(identifier, "TTPIRF08") ||
String::Equals(identifier, "TTPRF09 ") ||
String::Equals(identifier, "TTPRF10 ") ||
String::Equals(identifier, "TTPRF11 "))
if (identifier == "TTPIRF02" ||
identifier == "TTPIRF03" ||
identifier == "TTPIRF04" ||
identifier == "TTPIRF05" ||
identifier == "TTPIRF07" ||
identifier == "TTPIRF08" ||
identifier == "TTPRF09 " ||
identifier == "TTPRF10 " ||
identifier == "TTPRF11 ")
{
static const rct_object_entry scgPirat = GetScgPiratHeader();
SetPrimarySceneryGroup(&scgPirat);
}
// ToonTowner's wooden roofs. Make them show up in the Mine Theming.
if (String::Equals(identifier, "TTRFWD01") ||
String::Equals(identifier, "TTRFWD02") ||
String::Equals(identifier, "TTRFWD03") ||
String::Equals(identifier, "TTRFWD04") ||
String::Equals(identifier, "TTRFWD05") ||
String::Equals(identifier, "TTRFWD06") ||
String::Equals(identifier, "TTRFWD07") ||
String::Equals(identifier, "TTRFWD08"))
if (identifier == "TTRFWD01" ||
identifier == "TTRFWD02" ||
identifier == "TTRFWD03" ||
identifier == "TTRFWD04" ||
identifier == "TTRFWD05" ||
identifier == "TTRFWD06" ||
identifier == "TTRFWD07" ||
identifier == "TTRFWD08")
{
static const rct_object_entry scgMine = GetScgMineHeader();
SetPrimarySceneryGroup(&scgMine);
}
// ToonTowner's glass roofs. Make them show up in the Abstract Theming.
if (String::Equals(identifier, "TTRFGL01") ||
String::Equals(identifier, "TTRFGL02") ||
String::Equals(identifier, "TTRFGL03"))
if (identifier == "TTRFGL01" ||
identifier == "TTRFGL02" ||
identifier == "TTRFGL03")
{
static const rct_object_entry scgAbstr = GetScgAbstrHeader();
SetPrimarySceneryGroup(&scgAbstr);

View File

@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@@ -43,8 +43,8 @@ void WallObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
}
// Autofix this object (will be turned into an official object later).
auto identifier = GetIdentifier();
if (String::Equals(identifier, "XXWLBR03"))
auto identifier = GetLegacyIdentifier();
if (identifier == "XXWLBR03")
{
_legacyType.wall.flags2 &= ~WALL_SCENERY_2_DOOR_SOUND_MASK;
_legacyType.wall.flags2 |= (1u << WALL_SCENERY_2_DOOR_SOUND_SHIFT) & WALL_SCENERY_2_DOOR_SOUND_MASK;

View File

@@ -41,6 +41,7 @@ namespace OpenRCT2::Scripting
dukglue_register_property(ctx, &ScObject::type_get, nullptr, "type");
dukglue_register_property(ctx, &ScObject::index_get, nullptr, "index");
dukglue_register_property(ctx, &ScObject::identifier_get, nullptr, "identifier");
dukglue_register_property(ctx, &ScObject::legacyIdentifier_get, nullptr, "legacyIdentifier");
dukglue_register_property(ctx, &ScObject::name_get, nullptr, "name");
}
@@ -83,7 +84,17 @@ namespace OpenRCT2::Scripting
auto obj = GetObject();
if (obj != nullptr)
{
return obj->GetIdentifier();
return std::string(obj->GetIdentifier());
}
return {};
}
std::string legacyIdentifier_get() const
{
auto obj = GetObject();
if (obj != nullptr)
{
return std::string(obj->GetLegacyIdentifier());
}
return {};
}