mirror of https://github.com/OpenRCT2/OpenRCT2.git
Use vector for source games
This commit is contained in:
parent
2a64ec7aff
commit
b257619418
|
@ -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)
|
||||
|
|
|
@ -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<uint8_t> Object::GetSourceGames()
|
||||
{
|
||||
return _sourceGame;
|
||||
return _sourceGames;
|
||||
}
|
||||
|
||||
void Object::SetSourceGame(const uint8_t sourceGame)
|
||||
void Object::SetSourceGames(std::vector<uint8_t> sourceGames)
|
||||
{
|
||||
_sourceGame = sourceGame;
|
||||
}
|
||||
|
||||
uint8_t Object::GetSecondSourceGame()
|
||||
{
|
||||
return _secondSourceGame;
|
||||
}
|
||||
|
||||
void Object::SetSecondSourceGame(const uint8_t sourceGame)
|
||||
{
|
||||
_secondSourceGame = sourceGame;
|
||||
_sourceGames = sourceGames;
|
||||
}
|
||||
|
||||
bool Object::IsOpenRCT2OfficialObject()
|
||||
|
|
|
@ -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<uint8_t> _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<uint8_t> GetSourceGames();
|
||||
void SetSourceGames(std::vector<uint8_t> sourceGames);
|
||||
|
||||
const ImageTable& GetImageTable() const
|
||||
{
|
||||
|
|
|
@ -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<uint8_t> 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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<rct_object_entry>();
|
||||
item.Path = stream->ReadStdString();
|
||||
item.Name = stream->ReadStdString();
|
||||
auto sources = stream->ReadArray<uint8_t>(2);
|
||||
item.Sources[0] = sources[0];
|
||||
item.Sources[1] = sources[1];
|
||||
Memory::Free(sources);
|
||||
auto sourceLength = stream->ReadValue<uint8_t>();
|
||||
for (size_t i = 0; i < sourceLength; i++)
|
||||
{
|
||||
auto value = stream->ReadValue<uint8_t>();
|
||||
item.Sources.push_back(value);
|
||||
}
|
||||
|
||||
switch (object_entry_get_type(&item.ObjectEntry))
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@ struct ObjectRepositoryItem
|
|||
rct_object_entry ObjectEntry;
|
||||
std::string Path;
|
||||
std::string Name;
|
||||
uint8_t Sources[2];
|
||||
std::vector<uint8_t> Sources;
|
||||
Object* LoadedObject{};
|
||||
struct
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue