1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-06 06:32:56 +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

@@ -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())