diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 6c84790ced..2cda11bd12 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -1431,10 +1431,13 @@ static bool filter_source(const ObjectRepositoryItem * item) if (_FILTER_ALL) return true; - uint8_t source = item->Sources[0]; - uint8_t secondSource = item->Sources[1]; + for (auto source: item->Sources) + { + if (sources_match(source)) + return true; + } - return sources_match(source) || (secondSource != OBJECT_SOURCE_CUSTOM && sources_match(secondSource)); + return false; } static bool filter_chunks(const ObjectRepositoryItem* item) diff --git a/src/openrct2/object/Object.cpp b/src/openrct2/object/Object.cpp index 401c6b139c..287f3a31d5 100644 --- a/src/openrct2/object/Object.cpp +++ b/src/openrct2/object/Object.cpp @@ -24,11 +24,10 @@ Object::Object(const rct_object_entry& entry) char name[DAT_NAME_LENGTH + 1] = { 0 }; std::copy_n(entry.name, DAT_NAME_LENGTH, name); _identifier = String::Duplicate(name); - _secondSourceGame = OBJECT_SOURCE_CUSTOM; if (IsOpenRCT2OfficialObject()) { - SetSourceGame(OBJECT_SOURCE_OPENRCT2_OFFICIAL); + SetSourceGames({ OBJECT_SOURCE_OPENRCT2_OFFICIAL }); } } @@ -84,24 +83,14 @@ rct_object_entry Object::CreateHeader(const char name[DAT_NAME_LENGTH + 1], uint return header; } -uint8_t Object::GetSourceGame() +std::vector Object::GetSourceGames() { - return _sourceGame; + return _sourceGames; } -void Object::SetSourceGame(const uint8_t sourceGame) +void Object::SetSourceGames(std::vector sourceGames) { - _sourceGame = sourceGame; -} - -uint8_t Object::GetSecondSourceGame() -{ - return _secondSourceGame; -} - -void Object::SetSecondSourceGame(const uint8_t sourceGame) -{ - _secondSourceGame = sourceGame; + _sourceGames = sourceGames; } bool Object::IsOpenRCT2OfficialObject() diff --git a/src/openrct2/object/Object.h b/src/openrct2/object/Object.h index 31a2be48d7..13a57481aa 100644 --- a/src/openrct2/object/Object.h +++ b/src/openrct2/object/Object.h @@ -153,12 +153,12 @@ interface IReadObjectContext class Object { private: +<<<<<<< HEAD char* _identifier; rct_object_entry _objectEntry{}; StringTable _stringTable; ImageTable _imageTable; - uint8_t _sourceGame = OBJECT_SOURCE_CUSTOM; - uint8_t _secondSourceGame = OBJECT_SOURCE_CUSTOM; + std::vector _sourceGames; protected: StringTable& GetStringTable() @@ -216,10 +216,8 @@ public: virtual void SetRepositoryItem(ObjectRepositoryItem* /*item*/) const { } - uint8_t GetSourceGame(); - void SetSourceGame(uint8_t sourceGame); - uint8_t GetSecondSourceGame(); - void SetSecondSourceGame(uint8_t sourceGame); + std::vector GetSourceGames(); + void SetSourceGames(std::vector sourceGames); const ImageTable& GetImageTable() const { diff --git a/src/openrct2/object/ObjectFactory.cpp b/src/openrct2/object/ObjectFactory.cpp index 997432a246..9b4a3f2808 100644 --- a/src/openrct2/object/ObjectFactory.cpp +++ b/src/openrct2/object/ObjectFactory.cpp @@ -221,7 +221,7 @@ namespace ObjectFactory { throw std::runtime_error("Object has errors"); } - result->SetSourceGame(object_entry_get_source_game_legacy(&entry)); + result->SetSourceGames({ object_entry_get_source_game_legacy(&entry) }); } catch (const std::exception&) { @@ -254,7 +254,7 @@ namespace ObjectFactory } else { - result->SetSourceGame(object_entry_get_source_game_legacy(entry)); + result->SetSourceGames({ object_entry_get_source_game_legacy(entry) }); } } return result; @@ -420,19 +420,23 @@ namespace ObjectFactory auto sourceGames = json_object_get(jRoot, "sourceGame"); if (json_is_array(sourceGames)) { - auto sourceGame = json_string_value(json_array_get(sourceGames, 0)); - auto secondSourceGame = json_string_value(json_array_get(sourceGames, 1)); - result->SetSourceGame(ParseSourceGame(sourceGame)); - result->SetSecondSourceGame(ParseSourceGame(secondSourceGame)); + std::vector sourceGameVector; + for (size_t j = 0; j < json_array_size(sourceGames); j++) + { + sourceGameVector.push_back( + ParseSourceGame(json_string_value(json_array_get(sourceGames, j)))); + } + result->SetSourceGames(sourceGameVector); } else if (json_is_string(sourceGames)) { auto sourceGame = json_string_value(sourceGames); - result->SetSourceGame(ParseSourceGame(sourceGame)); + result->SetSourceGames({ ParseSourceGame(sourceGame) }); } else { log_error("Object %s has an incorrect sourceGame parameter.", id); + result->SetSourceGames({ OBJECT_SOURCE_CUSTOM }); } } } diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index 8b8f160389..94df82e747 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -112,8 +112,7 @@ public: item.ObjectEntry = *object->GetObjectEntry(); item.Path = path; item.Name = object->GetName(); - item.Sources[0] = object->GetSourceGame(); - item.Sources[1] = object->GetSecondSourceGame(); + item.Sources = object->GetSourceGames(); object->SetRepositoryItem(&item); delete object; return std::make_tuple(true, item); @@ -127,7 +126,12 @@ protected: stream->WriteValue(item.ObjectEntry); stream->WriteString(item.Path); stream->WriteString(item.Name); - stream->WriteArray(item.Sources, 2); + uint8_t sourceLength = (uint8_t)item.Sources.size(); + stream->WriteValue(sourceLength); + for (auto source : item.Sources) + { + stream->WriteValue(source); + } switch (object_entry_get_type(&item.ObjectEntry)) { @@ -160,10 +164,12 @@ protected: item.ObjectEntry = stream->ReadValue(); item.Path = stream->ReadStdString(); item.Name = stream->ReadStdString(); - auto sources = stream->ReadArray(2); - item.Sources[0] = sources[0]; - item.Sources[1] = sources[1]; - Memory::Free(sources); + auto sourceLength = stream->ReadValue(); + for (size_t i = 0; i < sourceLength; i++) + { + auto value = stream->ReadValue(); + item.Sources.push_back(value); + } switch (object_entry_get_type(&item.ObjectEntry)) { diff --git a/src/openrct2/object/ObjectRepository.h b/src/openrct2/object/ObjectRepository.h index 037cdbd564..5317c43da6 100644 --- a/src/openrct2/object/ObjectRepository.h +++ b/src/openrct2/object/ObjectRepository.h @@ -36,7 +36,7 @@ struct ObjectRepositoryItem rct_object_entry ObjectEntry; std::string Path; std::string Name; - uint8_t Sources[2]; + std::vector Sources; Object* LoadedObject{}; struct {