From 2a64ec7aff99c003c0dd8bad8fad2a665122ccd6 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Tue, 3 Jul 2018 13:46:45 +0200 Subject: [PATCH] Use sourceGame parameter in JSON files instead of originalId --- .../windows/EditorObjectSelection.cpp | 9 +++------ src/openrct2-ui/windows/ObjectLoadError.cpp | 3 ++- src/openrct2/object/BannerObject.cpp | 8 ++++---- src/openrct2/object/FootpathItemObject.cpp | 2 +- src/openrct2/object/Object.cpp | 9 ++++++--- src/openrct2/object/Object.h | 4 +++- src/openrct2/object/ObjectFactory.cpp | 16 ++++++++++++++++ src/openrct2/object/ObjectList.cpp | 2 +- src/openrct2/object/ObjectList.h | 2 +- src/openrct2/object/ObjectManager.cpp | 8 ++++---- src/openrct2/object/ObjectManager.h | 2 +- src/openrct2/object/ObjectRepository.cpp | 10 +++++++--- src/openrct2/object/ObjectRepository.h | 2 +- 13 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 0501046c3b..6c84790ced 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -951,7 +951,6 @@ static void window_editor_object_selection_paint(rct_window* w, rct_drawpixelinf { int32_t i, x, y, width; rct_widget* widget; - rct_object_entry* highlightedEntry; rct_string_id stringId; window_draw_widgets(w, dpi); @@ -1043,8 +1042,6 @@ static void window_editor_object_selection_paint(rct_window* w, rct_drawpixelinf list_item* listItem = &_listItems[w->selected_list_item]; - highlightedEntry = w->object_entry; - // Draw preview widget = &w->widgets[WIDX_PREVIEW]; { @@ -1093,7 +1090,7 @@ static void window_editor_object_selection_paint(rct_window* w, rct_drawpixelinf y += 12; // Draw object source - stringId = object_manager_get_source_game_string(highlightedEntry); + stringId = object_manager_get_source_game_string(listItem->repositoryItem->Sources[0]); gfx_draw_string_right(dpi, stringId, nullptr, COLOUR_WHITE, w->x + w->width - 5, y); y += 12; @@ -1434,8 +1431,8 @@ static bool filter_source(const ObjectRepositoryItem * item) if (_FILTER_ALL) return true; - uint8_t source = object_entry_get_source_game(&item->ObjectEntry); - uint8_t secondSource = item->Source; + uint8_t source = item->Sources[0]; + uint8_t secondSource = item->Sources[1]; return sources_match(source) || (secondSource != OBJECT_SOURCE_CUSTOM && sources_match(secondSource)); } diff --git a/src/openrct2-ui/windows/ObjectLoadError.cpp b/src/openrct2-ui/windows/ObjectLoadError.cpp index 0ae0d1050f..8db291f93d 100644 --- a/src/openrct2-ui/windows/ObjectLoadError.cpp +++ b/src/openrct2-ui/windows/ObjectLoadError.cpp @@ -329,7 +329,8 @@ static void window_object_load_error_scrollpaint(rct_window* w, rct_drawpixelinf gfx_draw_string(dpi, strndup(_invalid_entries[i].name, 8), COLOUR_DARK_GREEN, NAME_COL_LEFT - 3, y); // ... source game ... - rct_string_id sourceStringId = object_manager_get_source_game_string(&_invalid_entries[i]); + rct_string_id sourceStringId = object_manager_get_source_game_string( + object_entry_get_source_game_legacy(&_invalid_entries[i])); gfx_draw_string_left(dpi, sourceStringId, nullptr, COLOUR_DARK_GREEN, SOURCE_COL_LEFT - 3, y); // ... and type diff --git a/src/openrct2/object/BannerObject.cpp b/src/openrct2/object/BannerObject.cpp index aed6426385..5db9948819 100644 --- a/src/openrct2/object/BannerObject.cpp +++ b/src/openrct2/object/BannerObject.cpp @@ -47,10 +47,10 @@ void BannerObject::ReadLegacy(IReadObjectContext* context, IStream* stream) auto item = objectRepository.FindObject(identifier); if (item != nullptr) { - auto objectEntry = &item->ObjectEntry; - if (object_entry_get_source_game(objectEntry) == OBJECT_SOURCE_WACKY_WORLDS - || object_entry_get_source_game(objectEntry) == OBJECT_SOURCE_TIME_TWISTER - || object_entry_get_source_game(objectEntry) == OBJECT_SOURCE_CUSTOM) + auto sourceGame = item->Sources[0]; + if (sourceGame == OBJECT_SOURCE_WACKY_WORLDS + || sourceGame == OBJECT_SOURCE_TIME_TWISTER + || sourceGame == OBJECT_SOURCE_CUSTOM) { auto scgPathX = Object::GetScgPathXHeader(); SetPrimarySceneryGroup(&scgPathX); diff --git a/src/openrct2/object/FootpathItemObject.cpp b/src/openrct2/object/FootpathItemObject.cpp index 63b1d6c46a..8274735fa4 100644 --- a/src/openrct2/object/FootpathItemObject.cpp +++ b/src/openrct2/object/FootpathItemObject.cpp @@ -51,7 +51,7 @@ void FootpathItemObject::ReadLegacy(IReadObjectContext* context, IStream* stream auto item = objectRepository.FindObject(identifier); if (item != nullptr) { - auto sourceGame = object_entry_get_source_game(&item->ObjectEntry); + auto sourceGame = item->Sources[0]; if (sourceGame == OBJECT_SOURCE_WACKY_WORLDS || sourceGame == OBJECT_SOURCE_TIME_TWISTER || sourceGame == OBJECT_SOURCE_CUSTOM) { diff --git a/src/openrct2/object/Object.cpp b/src/openrct2/object/Object.cpp index d4573044f1..401c6b139c 100644 --- a/src/openrct2/object/Object.cpp +++ b/src/openrct2/object/Object.cpp @@ -84,11 +84,14 @@ rct_object_entry Object::CreateHeader(const char name[DAT_NAME_LENGTH + 1], uint return header; } +uint8_t Object::GetSourceGame() +{ + return _sourceGame; +} + void Object::SetSourceGame(const uint8_t sourceGame) { - // FIXME: Temporary disabled because it breaks exporting to vanilla. - /*_objectEntry.flags &= 0x0F; - _objectEntry.flags |= (sourceGame << 4);*/ + _sourceGame = sourceGame; } uint8_t Object::GetSecondSourceGame() diff --git a/src/openrct2/object/Object.h b/src/openrct2/object/Object.h index 2f7eb38ed3..31a2be48d7 100644 --- a/src/openrct2/object/Object.h +++ b/src/openrct2/object/Object.h @@ -157,6 +157,7 @@ private: rct_object_entry _objectEntry{}; StringTable _stringTable; ImageTable _imageTable; + uint8_t _sourceGame = OBJECT_SOURCE_CUSTOM; uint8_t _secondSourceGame = OBJECT_SOURCE_CUSTOM; protected: @@ -177,7 +178,6 @@ protected: std::string GetString(uint8_t index) const; std::string GetString(int32_t language, uint8_t index) const; - void SetSourceGame(const uint8_t sourceGame); bool IsOpenRCT2OfficialObject(); public: @@ -216,6 +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); diff --git a/src/openrct2/object/ObjectFactory.cpp b/src/openrct2/object/ObjectFactory.cpp index b51bf2b120..997432a246 100644 --- a/src/openrct2/object/ObjectFactory.cpp +++ b/src/openrct2/object/ObjectFactory.cpp @@ -221,6 +221,7 @@ namespace ObjectFactory { throw std::runtime_error("Object has errors"); } + result->SetSourceGame(object_entry_get_source_game_legacy(&entry)); } catch (const std::exception&) { @@ -251,6 +252,10 @@ namespace ObjectFactory delete result; result = nullptr; } + else + { + result->SetSourceGame(object_entry_get_source_game_legacy(entry)); + } } return result; } @@ -415,9 +420,20 @@ 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)); } + else if (json_is_string(sourceGames)) + { + auto sourceGame = json_string_value(sourceGames); + result->SetSourceGame(ParseSourceGame(sourceGame)); + } + else + { + log_error("Object %s has an incorrect sourceGame parameter.", id); + } } } return result; diff --git a/src/openrct2/object/ObjectList.cpp b/src/openrct2/object/ObjectList.cpp index 2247a484e9..be7fb19b35 100644 --- a/src/openrct2/object/ObjectList.cpp +++ b/src/openrct2/object/ObjectList.cpp @@ -71,7 +71,7 @@ uint8_t object_entry_get_type(const rct_object_entry* objectEntry) return (objectEntry->flags & 0x0F); } -uint8_t object_entry_get_source_game(const rct_object_entry* objectEntry) +uint8_t object_entry_get_source_game_legacy(const rct_object_entry* objectEntry) { return (objectEntry->flags & 0xF0) >> 4; } diff --git a/src/openrct2/object/ObjectList.h b/src/openrct2/object/ObjectList.h index 7d6102b274..d214ae22fb 100644 --- a/src/openrct2/object/ObjectList.h +++ b/src/openrct2/object/ObjectList.h @@ -21,4 +21,4 @@ void get_type_entry_index(size_t index, uint8_t* outObjectType, uint8_t* outEntr const rct_object_entry* get_loaded_object_entry(size_t index); void* get_loaded_object_chunk(size_t index); uint8_t object_entry_get_type(const rct_object_entry* objectEntry); -uint8_t object_entry_get_source_game(const rct_object_entry* objectEntry); +uint8_t object_entry_get_source_game_legacy(const rct_object_entry* objectEntry); diff --git a/src/openrct2/object/ObjectManager.cpp b/src/openrct2/object/ObjectManager.cpp index 42685b096e..ba6c9c835d 100644 --- a/src/openrct2/object/ObjectManager.cpp +++ b/src/openrct2/object/ObjectManager.cpp @@ -218,9 +218,9 @@ public: // loaded RCT1 and RCT2 save files. } - static rct_string_id GetObjectSourceGameString(const rct_object_entry* entry) + static rct_string_id GetObjectSourceGameString(const uint8_t sourceGame) { - switch (object_entry_get_source_game(entry)) + switch (sourceGame) { case OBJECT_SOURCE_RCT1: return STR_SCENARIO_CATEGORY_RCT1; @@ -675,7 +675,7 @@ void object_manager_unload_all_objects() } } -rct_string_id object_manager_get_source_game_string(const rct_object_entry* entry) +rct_string_id object_manager_get_source_game_string(const uint8_t sourceGame) { - return ObjectManager::GetObjectSourceGameString(entry); + return ObjectManager::GetObjectSourceGameString(sourceGame); } diff --git a/src/openrct2/object/ObjectManager.h b/src/openrct2/object/ObjectManager.h index 5496bdbad1..fd6dcbca5e 100644 --- a/src/openrct2/object/ObjectManager.h +++ b/src/openrct2/object/ObjectManager.h @@ -49,4 +49,4 @@ uint8_t object_manager_get_loaded_object_entry_index(const void* loadedObject); void* object_manager_load_object(const rct_object_entry* entry); void object_manager_unload_objects(const rct_object_entry* entries, size_t count); void object_manager_unload_all_objects(); -rct_string_id object_manager_get_source_game_string(const rct_object_entry* entry); +rct_string_id object_manager_get_source_game_string(const uint8_t sourceGame); diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index 39cd2cee86..8b8f160389 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -112,7 +112,8 @@ public: item.ObjectEntry = *object->GetObjectEntry(); item.Path = path; item.Name = object->GetName(); - item.Source = object->GetSecondSourceGame(); + item.Sources[0] = object->GetSourceGame(); + item.Sources[1] = object->GetSecondSourceGame(); object->SetRepositoryItem(&item); delete object; return std::make_tuple(true, item); @@ -126,7 +127,7 @@ protected: stream->WriteValue(item.ObjectEntry); stream->WriteString(item.Path); stream->WriteString(item.Name); - stream->WriteValue(item.Source); + stream->WriteArray(item.Sources, 2); switch (object_entry_get_type(&item.ObjectEntry)) { @@ -159,7 +160,10 @@ protected: item.ObjectEntry = stream->ReadValue(); item.Path = stream->ReadStdString(); item.Name = stream->ReadStdString(); - item.Source = stream->ReadValue(); + auto sources = stream->ReadArray(2); + item.Sources[0] = sources[0]; + item.Sources[1] = sources[1]; + Memory::Free(sources); switch (object_entry_get_type(&item.ObjectEntry)) { diff --git a/src/openrct2/object/ObjectRepository.h b/src/openrct2/object/ObjectRepository.h index 6255d08625..037cdbd564 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 Source; + uint8_t Sources[2]; Object* LoadedObject{}; struct {