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)
|
if (_FILTER_ALL)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
uint8_t source = item->Sources[0];
|
for (auto source: item->Sources)
|
||||||
uint8_t secondSource = item->Sources[1];
|
{
|
||||||
|
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)
|
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 };
|
char name[DAT_NAME_LENGTH + 1] = { 0 };
|
||||||
std::copy_n(entry.name, DAT_NAME_LENGTH, name);
|
std::copy_n(entry.name, DAT_NAME_LENGTH, name);
|
||||||
_identifier = String::Duplicate(name);
|
_identifier = String::Duplicate(name);
|
||||||
_secondSourceGame = OBJECT_SOURCE_CUSTOM;
|
|
||||||
|
|
||||||
if (IsOpenRCT2OfficialObject())
|
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;
|
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;
|
_sourceGames = sourceGames;
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Object::GetSecondSourceGame()
|
|
||||||
{
|
|
||||||
return _secondSourceGame;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Object::SetSecondSourceGame(const uint8_t sourceGame)
|
|
||||||
{
|
|
||||||
_secondSourceGame = sourceGame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Object::IsOpenRCT2OfficialObject()
|
bool Object::IsOpenRCT2OfficialObject()
|
||||||
|
|
|
@ -153,12 +153,12 @@ interface IReadObjectContext
|
||||||
class Object
|
class Object
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
<<<<<<< HEAD
|
||||||
char* _identifier;
|
char* _identifier;
|
||||||
rct_object_entry _objectEntry{};
|
rct_object_entry _objectEntry{};
|
||||||
StringTable _stringTable;
|
StringTable _stringTable;
|
||||||
ImageTable _imageTable;
|
ImageTable _imageTable;
|
||||||
uint8_t _sourceGame = OBJECT_SOURCE_CUSTOM;
|
std::vector<uint8_t> _sourceGames;
|
||||||
uint8_t _secondSourceGame = OBJECT_SOURCE_CUSTOM;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
StringTable& GetStringTable()
|
StringTable& GetStringTable()
|
||||||
|
@ -216,10 +216,8 @@ public:
|
||||||
virtual void SetRepositoryItem(ObjectRepositoryItem* /*item*/) const
|
virtual void SetRepositoryItem(ObjectRepositoryItem* /*item*/) const
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
uint8_t GetSourceGame();
|
std::vector<uint8_t> GetSourceGames();
|
||||||
void SetSourceGame(uint8_t sourceGame);
|
void SetSourceGames(std::vector<uint8_t> sourceGames);
|
||||||
uint8_t GetSecondSourceGame();
|
|
||||||
void SetSecondSourceGame(uint8_t sourceGame);
|
|
||||||
|
|
||||||
const ImageTable& GetImageTable() const
|
const ImageTable& GetImageTable() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -221,7 +221,7 @@ namespace ObjectFactory
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Object has errors");
|
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&)
|
catch (const std::exception&)
|
||||||
{
|
{
|
||||||
|
@ -254,7 +254,7 @@ namespace ObjectFactory
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result->SetSourceGame(object_entry_get_source_game_legacy(entry));
|
result->SetSourceGames({ object_entry_get_source_game_legacy(entry) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -420,19 +420,23 @@ namespace ObjectFactory
|
||||||
auto sourceGames = json_object_get(jRoot, "sourceGame");
|
auto sourceGames = json_object_get(jRoot, "sourceGame");
|
||||||
if (json_is_array(sourceGames))
|
if (json_is_array(sourceGames))
|
||||||
{
|
{
|
||||||
auto sourceGame = json_string_value(json_array_get(sourceGames, 0));
|
std::vector<uint8_t> sourceGameVector;
|
||||||
auto secondSourceGame = json_string_value(json_array_get(sourceGames, 1));
|
for (size_t j = 0; j < json_array_size(sourceGames); j++)
|
||||||
result->SetSourceGame(ParseSourceGame(sourceGame));
|
{
|
||||||
result->SetSecondSourceGame(ParseSourceGame(secondSourceGame));
|
sourceGameVector.push_back(
|
||||||
|
ParseSourceGame(json_string_value(json_array_get(sourceGames, j))));
|
||||||
|
}
|
||||||
|
result->SetSourceGames(sourceGameVector);
|
||||||
}
|
}
|
||||||
else if (json_is_string(sourceGames))
|
else if (json_is_string(sourceGames))
|
||||||
{
|
{
|
||||||
auto sourceGame = json_string_value(sourceGames);
|
auto sourceGame = json_string_value(sourceGames);
|
||||||
result->SetSourceGame(ParseSourceGame(sourceGame));
|
result->SetSourceGames({ ParseSourceGame(sourceGame) });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log_error("Object %s has an incorrect sourceGame parameter.", id);
|
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.ObjectEntry = *object->GetObjectEntry();
|
||||||
item.Path = path;
|
item.Path = path;
|
||||||
item.Name = object->GetName();
|
item.Name = object->GetName();
|
||||||
item.Sources[0] = object->GetSourceGame();
|
item.Sources = object->GetSourceGames();
|
||||||
item.Sources[1] = object->GetSecondSourceGame();
|
|
||||||
object->SetRepositoryItem(&item);
|
object->SetRepositoryItem(&item);
|
||||||
delete object;
|
delete object;
|
||||||
return std::make_tuple(true, item);
|
return std::make_tuple(true, item);
|
||||||
|
@ -127,7 +126,12 @@ protected:
|
||||||
stream->WriteValue(item.ObjectEntry);
|
stream->WriteValue(item.ObjectEntry);
|
||||||
stream->WriteString(item.Path);
|
stream->WriteString(item.Path);
|
||||||
stream->WriteString(item.Name);
|
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))
|
switch (object_entry_get_type(&item.ObjectEntry))
|
||||||
{
|
{
|
||||||
|
@ -160,10 +164,12 @@ protected:
|
||||||
item.ObjectEntry = stream->ReadValue<rct_object_entry>();
|
item.ObjectEntry = stream->ReadValue<rct_object_entry>();
|
||||||
item.Path = stream->ReadStdString();
|
item.Path = stream->ReadStdString();
|
||||||
item.Name = stream->ReadStdString();
|
item.Name = stream->ReadStdString();
|
||||||
auto sources = stream->ReadArray<uint8_t>(2);
|
auto sourceLength = stream->ReadValue<uint8_t>();
|
||||||
item.Sources[0] = sources[0];
|
for (size_t i = 0; i < sourceLength; i++)
|
||||||
item.Sources[1] = sources[1];
|
{
|
||||||
Memory::Free(sources);
|
auto value = stream->ReadValue<uint8_t>();
|
||||||
|
item.Sources.push_back(value);
|
||||||
|
}
|
||||||
|
|
||||||
switch (object_entry_get_type(&item.ObjectEntry))
|
switch (object_entry_get_type(&item.ObjectEntry))
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,7 +36,7 @@ struct ObjectRepositoryItem
|
||||||
rct_object_entry ObjectEntry;
|
rct_object_entry ObjectEntry;
|
||||||
std::string Path;
|
std::string Path;
|
||||||
std::string Name;
|
std::string Name;
|
||||||
uint8_t Sources[2];
|
std::vector<uint8_t> Sources;
|
||||||
Object* LoadedObject{};
|
Object* LoadedObject{};
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue