mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 19:13:07 +01:00
Use ScenarioTextObject for indexing scenarios
This commit is contained in:
@@ -32,7 +32,7 @@ void ScenarioTextObject::ReadJson(IReadObjectContext* context, json_t& root)
|
||||
|
||||
std::string ScenarioTextObject::GetScenarioName()
|
||||
{
|
||||
return GetStringTable().GetString(ObjectStringID::SCENARIO_NAME);
|
||||
return GetStringTable().GetString(ObjectStringID::NAME); // SCENARIO_NAME
|
||||
}
|
||||
|
||||
std::string ScenarioTextObject::GetParkName()
|
||||
|
||||
@@ -88,6 +88,10 @@ ObjectStringID StringTable::ParseStringId(const std::string& s)
|
||||
return ObjectStringID::NAME;
|
||||
if (s == "description")
|
||||
return ObjectStringID::DESCRIPTION;
|
||||
if (s == "park_name")
|
||||
return ObjectStringID::PARK_NAME;
|
||||
if (s == "details")
|
||||
return ObjectStringID::SCENARIO_DETAILS;
|
||||
if (s == "capacity")
|
||||
return ObjectStringID::CAPACITY;
|
||||
if (s == "vehicleName")
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "../object/ObjectList.h"
|
||||
#include "../object/ObjectManager.h"
|
||||
#include "../object/ObjectRepository.h"
|
||||
#include "../object/ScenarioTextObject.h"
|
||||
#include "../park/Legacy.h"
|
||||
#include "../peep/PeepAnimationData.h"
|
||||
#include "../peep/RideUseSystem.h"
|
||||
@@ -244,7 +245,7 @@ namespace OpenRCT2::RCT1
|
||||
dst->ObjectiveArg3 = GetBuildTheBestRideId();
|
||||
}
|
||||
|
||||
auto name = RCT2StringToUTF8(_s4.ScenarioName, RCT2LanguageId::EnglishUK);
|
||||
std::string name = RCT2StringToUTF8(_s4.ScenarioName, RCT2LanguageId::EnglishUK);
|
||||
std::string details;
|
||||
|
||||
// TryGetById won't set this property if the scenario is not recognised,
|
||||
@@ -256,16 +257,20 @@ namespace OpenRCT2::RCT1
|
||||
|
||||
String::Set(dst->InternalName, sizeof(dst->InternalName), desc.title);
|
||||
|
||||
StringId localisedStringIds[3];
|
||||
if (LanguageGetLocalisedScenarioStrings(desc.title, localisedStringIds))
|
||||
if (desc.textObjectId != nullptr)
|
||||
{
|
||||
if (localisedStringIds[0] != STR_NONE)
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
|
||||
// Unload loaded scenario text object, if any.
|
||||
if (auto* obj = objManager.GetLoadedObject(ObjectType::ScenarioText, 0); obj != nullptr)
|
||||
objManager.UnloadObjects({ obj->GetDescriptor() });
|
||||
|
||||
// Load the one specified
|
||||
if (auto* obj = objManager.LoadObject(desc.textObjectId); obj != nullptr)
|
||||
{
|
||||
name = String::ToStd(LanguageGetString(localisedStringIds[0]));
|
||||
}
|
||||
if (localisedStringIds[2] != STR_NONE)
|
||||
{
|
||||
details = String::ToStd(LanguageGetString(localisedStringIds[2]));
|
||||
auto* textObject = reinterpret_cast<ScenarioTextObject*>(obj);
|
||||
name = textObject->GetScenarioName();
|
||||
details = textObject->GetScenarioDetails();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2324,24 +2329,25 @@ namespace OpenRCT2::RCT1
|
||||
int32_t scNumber = _s4.ScenarioSlotIndex;
|
||||
if (scNumber != -1)
|
||||
{
|
||||
SourceDescriptor sourceDesc;
|
||||
if (ScenarioSources::TryGetById(scNumber, &sourceDesc))
|
||||
SourceDescriptor desc;
|
||||
if (ScenarioSources::TryGetById(scNumber, &desc) && desc.textObjectId != nullptr)
|
||||
{
|
||||
StringId localisedStringIds[3];
|
||||
if (LanguageGetLocalisedScenarioStrings(sourceDesc.title, localisedStringIds))
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
|
||||
// Ensure only one thread talks to the object manager at a time
|
||||
std::lock_guard lock(mtx);
|
||||
|
||||
// Unload loaded scenario text object, if any.
|
||||
if (auto* obj = objManager.GetLoadedObject(ObjectType::ScenarioText, 0); obj != nullptr)
|
||||
objManager.UnloadObjects({ obj->GetDescriptor() });
|
||||
|
||||
// Load the one specified
|
||||
if (auto* obj = objManager.LoadObject(desc.textObjectId); obj != nullptr)
|
||||
{
|
||||
if (localisedStringIds[0] != STR_NONE)
|
||||
{
|
||||
name = String::ToStd(LanguageGetString(localisedStringIds[0]));
|
||||
}
|
||||
if (localisedStringIds[1] != STR_NONE)
|
||||
{
|
||||
parkName = String::ToStd(LanguageGetString(localisedStringIds[1]));
|
||||
}
|
||||
if (localisedStringIds[2] != STR_NONE)
|
||||
{
|
||||
details = String::ToStd(LanguageGetString(localisedStringIds[2]));
|
||||
}
|
||||
auto* textObject = reinterpret_cast<ScenarioTextObject*>(obj);
|
||||
name = textObject->GetScenarioName();
|
||||
parkName = textObject->GetParkName();
|
||||
details = textObject->GetScenarioDetails();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include "../object/ObjectList.h"
|
||||
#include "../object/ObjectManager.h"
|
||||
#include "../object/ObjectRepository.h"
|
||||
#include "../object/ScenarioTextObject.h"
|
||||
#include "../object/WallSceneryEntry.h"
|
||||
#include "../park/Legacy.h"
|
||||
#include "../peep/RideUseSystem.h"
|
||||
@@ -263,11 +264,6 @@ namespace OpenRCT2::RCT2
|
||||
String::Set(dst->Name, sizeof(dst->Name), normalisedName.c_str());
|
||||
}
|
||||
|
||||
// dst->name will be translated later so keep the untranslated name here
|
||||
String::Set(dst->InternalName, sizeof(dst->InternalName), dst->Name);
|
||||
|
||||
String::Set(dst->Details, sizeof(dst->Details), _s6.Info.Details);
|
||||
|
||||
// Look up and store information regarding the origins of this scenario.
|
||||
SourceDescriptor desc;
|
||||
if (ScenarioSources::TryGetByName(dst->Name, &desc))
|
||||
@@ -291,17 +287,27 @@ namespace OpenRCT2::RCT2
|
||||
}
|
||||
}
|
||||
|
||||
// Localise the park name and description
|
||||
StringId localisedStringIds[3];
|
||||
if (LanguageGetLocalisedScenarioStrings(dst->Name, localisedStringIds))
|
||||
// dst->name will be translated later so keep the untranslated name here
|
||||
String::Set(dst->InternalName, sizeof(dst->InternalName), dst->Name);
|
||||
String::Set(dst->Details, sizeof(dst->Details), _s6.Info.Details);
|
||||
|
||||
if (desc.textObjectId != nullptr)
|
||||
{
|
||||
if (localisedStringIds[0] != STR_NONE)
|
||||
auto& objManager = GetContext()->GetObjectManager();
|
||||
|
||||
// Unload loaded scenario text object, if any.
|
||||
if (auto* obj = objManager.GetLoadedObject(ObjectType::ScenarioText, 0); obj != nullptr)
|
||||
objManager.UnloadObjects({ obj->GetDescriptor() });
|
||||
|
||||
// Load the one specified
|
||||
if (auto* obj = objManager.LoadObject(desc.textObjectId); obj != nullptr)
|
||||
{
|
||||
String::Set(dst->Name, sizeof(dst->Name), LanguageGetString(localisedStringIds[0]));
|
||||
}
|
||||
if (localisedStringIds[2] != STR_NONE)
|
||||
{
|
||||
String::Set(dst->Details, sizeof(dst->Details), LanguageGetString(localisedStringIds[2]));
|
||||
auto* textObject = reinterpret_cast<ScenarioTextObject*>(obj);
|
||||
auto name = textObject->GetScenarioName();
|
||||
auto details = textObject->GetScenarioDetails();
|
||||
|
||||
String::Set(dst->Name, sizeof(dst->Name), name.c_str());
|
||||
String::Set(dst->Details, sizeof(dst->Details), details.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user