1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-10 09:32:29 +01:00

Refactor TRACK_REPO_ITEM_FLAGS to strong enum and FlagHolder

This commit is contained in:
Gymnasiast
2025-03-25 23:47:28 +01:00
parent ad547d2d6c
commit e6762f1e08

View File

@@ -16,6 +16,7 @@
#include "../core/File.h" #include "../core/File.h"
#include "../core/FileIndex.hpp" #include "../core/FileIndex.hpp"
#include "../core/FileStream.h" #include "../core/FileStream.h"
#include "../core/FlagHolder.hpp"
#include "../core/Path.hpp" #include "../core/Path.hpp"
#include "../core/String.hpp" #include "../core/String.hpp"
#include "../localisation/LocalisationService.h" #include "../localisation/LocalisationService.h"
@@ -28,18 +29,19 @@
using namespace OpenRCT2; using namespace OpenRCT2;
enum TrackRepoItemFlag : uint8_t
{
readOnly,
};
using TrackRepoItemFlags = FlagHolder<uint32_t, TrackRepoItemFlag>;
struct TrackRepositoryItem struct TrackRepositoryItem
{ {
std::string Name; std::string Name;
std::string Path; std::string Path;
ride_type_t RideType = kRideTypeNull; ride_type_t RideType = kRideTypeNull;
std::string ObjectEntry; std::string ObjectEntry;
uint32_t Flags = 0; TrackRepoItemFlags flags{};
};
enum TRACK_REPO_ITEM_FLAGS
{
TRIF_READ_ONLY = (1 << 0),
}; };
std::string GetNameFromTrackPath(const std::string& path) std::string GetNameFromTrackPath(const std::string& path)
@@ -75,15 +77,14 @@ public:
auto td = TrackDesignImport(path.c_str()); auto td = TrackDesignImport(path.c_str());
if (td != nullptr) if (td != nullptr)
{ {
TrackRepositoryItem item; TrackRepositoryItem item{};
item.Name = GetNameFromTrackPath(path); item.Name = GetNameFromTrackPath(path);
item.Path = path; item.Path = path;
item.RideType = td->trackAndVehicle.rtdIndex; item.RideType = td->trackAndVehicle.rtdIndex;
item.ObjectEntry = std::string(td->trackAndVehicle.vehicleObject.Entry.name, 8); item.ObjectEntry = std::string(td->trackAndVehicle.vehicleObject.Entry.name, 8);
item.Flags = 0;
if (IsTrackReadOnly(path)) if (IsTrackReadOnly(path))
{ {
item.Flags |= TRIF_READ_ONLY; item.flags.set(TrackRepoItemFlag::readOnly);
} }
return item; return item;
} }
@@ -98,7 +99,7 @@ protected:
ds << item.Path; ds << item.Path;
ds << item.RideType; ds << item.RideType;
ds << item.ObjectEntry; ds << item.ObjectEntry;
ds << item.Flags; ds << item.flags.holder;
} }
private: private:
@@ -219,7 +220,7 @@ public:
if (index != SIZE_MAX) if (index != SIZE_MAX)
{ {
const TrackRepositoryItem* item = &_items[index]; const TrackRepositoryItem* item = &_items[index];
if (!(item->Flags & TRIF_READ_ONLY)) if (!item->flags.has(TrackRepoItemFlag::readOnly))
{ {
if (File::Delete(path)) if (File::Delete(path))
{ {
@@ -238,7 +239,7 @@ public:
if (index != SIZE_MAX) if (index != SIZE_MAX)
{ {
TrackRepositoryItem* item = &_items[index]; TrackRepositoryItem* item = &_items[index];
if (!(item->Flags & TRIF_READ_ONLY)) if (!item->flags.has(TrackRepoItemFlag::readOnly))
{ {
std::string directory = Path::GetDirectory(path); std::string directory = Path::GetDirectory(path);
std::string newPath = Path::Combine(directory, newName + Path::GetExtension(path)); std::string newPath = Path::Combine(directory, newName + Path::GetExtension(path));