Close #12427: Refactor OBJECT_TYPE to use strong enum

This commit is contained in:
Łukasz Pękalski 2020-11-10 09:00:15 +01:00
parent dc93cacbee
commit 7648feeba2
11 changed files with 31 additions and 31 deletions

View File

@ -188,7 +188,7 @@ static bool window_editor_bottom_toolbar_check_object_selection()
if (w != nullptr)
{
// Click tab with missing object
window_event_mouse_up_call(w, WC_EDITOR_OBJECT_SELECTION__WIDX_TAB_1 + missingObjectType);
window_event_mouse_up_call(w, WC_EDITOR_OBJECT_SELECTION__WIDX_TAB_1 + EnumValue(missingObjectType));
}
return false;
}

View File

@ -212,7 +212,7 @@ static constexpr const int32_t window_editor_object_selection_animation_divisor[
static void window_editor_object_set_page(rct_window* w, int32_t page);
static void window_editor_object_selection_set_pressed_tab(rct_window* w);
static int32_t get_object_from_object_selection(uint8_t object_type, int32_t y);
static int32_t get_object_from_object_selection(ObjectType object_type, int32_t y);
static void window_editor_object_selection_manage_tracks();
static void editor_load_selected_objects();
static bool filter_selected(uint8_t objectFlags);
@ -295,7 +295,7 @@ static void visible_list_refresh(rct_window* w)
{
uint8_t selectionFlags = _objectSelectionFlags[i];
const ObjectRepositoryItem* item = &items[i];
uint8_t objectType = item->ObjectEntry.GetType();
ObjectType objectType = item->ObjectEntry.GetType();
if (objectType == get_selected_object_type(w) && !(selectionFlags & OBJECT_SELECTION_FLAG_6) && filter_source(item)
&& filter_string(item) && filter_chunks(item) && filter_selected(selectionFlags))
{
@ -999,8 +999,8 @@ static void window_editor_object_selection_paint(rct_window* w, rct_drawpixelinf
{
auto screenPos = w->windowPos + ScreenCoordsXY{ 3, w->height - 13 };
int32_t numSelected = _numSelectedObjectsForType[get_selected_object_type(w)];
int32_t totalSelectable = object_entry_group_counts[get_selected_object_type(w)];
int32_t numSelected = _numSelectedObjectsForType[EnumValue(get_selected_object_type(w))];
int32_t totalSelectable = object_entry_group_counts[EnumValue(get_selected_object_type(w))];
if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)
totalSelectable = 4;
@ -1256,7 +1256,7 @@ static void window_editor_object_selection_set_pressed_tab(rct_window* w)
*
* rct2: 0x006AA703
*/
static int32_t get_object_from_object_selection(uint8_t object_type, int32_t y)
static int32_t get_object_from_object_selection(ObjectType object_type, int32_t y)
{
int32_t listItemIndex = y / SCROLLABLE_ROW_HEIGHT;
if (listItemIndex < 0 || static_cast<size_t>(listItemIndex) >= _listItems.size())
@ -1502,7 +1502,7 @@ static bool filter_chunks(const ObjectRepositoryItem* item)
case ObjectType::Music:
case ObjectType::Count:
case ObjectType::None:
//This function works only with ObjectType::Ride.
// This function works only with ObjectType::Ride.
break;
}
return true;
@ -1522,8 +1522,8 @@ static void filter_update_counts()
const ObjectRepositoryItem* item = &items[i];
if (filter_source(item) && filter_string(item) && filter_chunks(item) && filter_selected(selectionFlags[i]))
{
uint8_t objectType = item->ObjectEntry.GetType();
_filter_object_counts[objectType]++;
ObjectType objectType = item->ObjectEntry.GetType();
_filter_object_counts[EnumValue(objectType)]++;
}
}
}

View File

@ -11,8 +11,7 @@
#define _EDITOR_H_
#include "common.h"
#include <src/openrct2/object/Object.h>
#include "object/Object.h"
namespace Editor
{

View File

@ -42,7 +42,7 @@ enum class ObjectType : uint8_t
Music,
Count,
None=255
None = 255
};
enum OBJECT_SELECTION_FLAGS

View File

@ -474,7 +474,7 @@ private:
case ObjectType::Music:
case ObjectType::Count:
case ObjectType::None:
//This switch handles only ObjectType for sceneries.
// This switch handles only ObjectType for sceneries.
break;
}
}

View File

@ -181,7 +181,7 @@ protected:
case ObjectType::Music:
case ObjectType::Count:
case ObjectType::None:
//Switch processes only ObjectType::Ride and ObjectType::SceneryGroup
// Switch processes only ObjectType::Ride and ObjectType::SceneryGroup
break;
}
}
@ -247,7 +247,7 @@ protected:
case ObjectType::Music:
case ObjectType::Count:
case ObjectType::None:
//Switch processes only ObjectType::Ride and ObjectType::SceneryGroup
// Switch processes only ObjectType::Ride and ObjectType::SceneryGroup
break;
}
return item;

View File

@ -560,7 +560,7 @@ private:
case ObjectType::Music:
case ObjectType::Count:
case ObjectType::None:
//This switch processes only ObjectTypes valid for scenery
// This switch processes only ObjectTypes valid for scenery
break;
}
}
@ -2999,7 +2999,7 @@ private:
case ObjectType::Music:
case ObjectType::Count:
case ObjectType::None:
//This switch processes only ObjectType for for Entries
// This switch processes only ObjectType for for Entries
break;
}
return nullptr;

View File

@ -785,7 +785,7 @@ static void track_design_mirror_scenery(TrackDesign* td6)
case ObjectType::Music:
case ObjectType::Count:
case ObjectType::None:
//This switch processes only ObjectType for Scenery items.
// This switch processes only ObjectType for Scenery items.
break;
}
}
@ -900,7 +900,8 @@ static bool TrackDesignPlaceSceneryElementGetEntry(
}
entry_index = 0;
for (PathSurfaceEntry* path = get_path_surface_entry(0); entry_index < object_entry_group_counts[ObjectType::Paths];
for (PathSurfaceEntry* path = get_path_surface_entry(0);
entry_index < object_entry_group_counts[EnumValue(ObjectType::Paths)];
path = get_path_surface_entry(entry_index), entry_index++)
{
if (path == nullptr)
@ -987,7 +988,7 @@ static bool TrackDesignPlaceSceneryElementGetPlaceZ(const TrackDesignSceneryElem
_trackDesignPlaceSceneryZ = z;
}
uint8_t entry_type;
ObjectType entry_type;
ObjectEntryIndex entry_index;
TrackDesignPlaceSceneryElementGetEntry(entry_type, entry_index, scenery);
@ -1904,7 +1905,7 @@ static bool track_design_place_preview(TrackDesign* td6, money32* cost, Ride** o
*outRide = nullptr;
*flags = 0;
uint8_t entry_type;
ObjectType entry_type;
ObjectEntryIndex entry_index;
if (!find_object_in_entry_group(&td6->vehicle_object, &entry_type, &entry_index))
{

View File

@ -90,11 +90,11 @@ namespace OpenRCT2::Scripting
switch (type)
{
case ObjectType::Ride:
return GetObjectAsDukValue(ctx, std::make_shared<ScRideObject>(EnumValue(type), index));
return GetObjectAsDukValue(ctx, std::make_shared<ScRideObject>(type, index));
case ObjectType::SmallScenery:
return GetObjectAsDukValue(ctx, std::make_shared<ScSmallSceneryObject>(EnumValue(type), index));
return GetObjectAsDukValue(ctx, std::make_shared<ScSmallSceneryObject>(type, index));
default:
return GetObjectAsDukValue(ctx, std::make_shared<ScObject>(EnumValue(type), index));
return GetObjectAsDukValue(ctx, std::make_shared<ScObject>(type, index));
}
}
@ -128,7 +128,7 @@ namespace OpenRCT2::Scripting
auto type = ScObject::StringToObjectType(typez);
if (type)
{
auto count = object_entry_group_counts[*type];
auto count = object_entry_group_counts[EnumValue(*type)];
for (int32_t i = 0; i < count; i++)
{
auto obj = objManager.GetLoadedObject(*type, i);

View File

@ -26,11 +26,11 @@ namespace OpenRCT2::Scripting
class ScObject
{
protected:
uint8_t _type{};
ObjectType _type{};
int32_t _index{};
public:
ScObject(uint8_t type, int32_t index)
ScObject(ObjectType type, int32_t index)
: _type(type)
, _index(index)
{
@ -71,7 +71,7 @@ namespace OpenRCT2::Scripting
private:
std::string type_get() const
{
return std::string(ObjectTypeToString(_type));
return std::string(ObjectTypeToString(EnumValue(_type)));
}
int32_t index_get() const
@ -641,7 +641,7 @@ namespace OpenRCT2::Scripting
class ScRideObject : public ScObject
{
public:
ScRideObject(uint8_t type, int32_t index)
ScRideObject(ObjectType type, int32_t index)
: ScObject(type, index)
{
}
@ -922,7 +922,7 @@ namespace OpenRCT2::Scripting
class ScSmallSceneryObject : public ScObject
{
public:
ScSmallSceneryObject(uint8_t type, int32_t index)
ScSmallSceneryObject(ObjectType type, int32_t index)
: ScObject(type, index)
{
}

View File

@ -199,7 +199,7 @@ namespace OpenRCT2::Scripting
auto rideObject = GetContext()->GetObjectManager().GetLoadedObject(ObjectType::Ride, ride->subtype);
if (rideObject != nullptr)
{
return std::make_shared<ScRideObject>(EnumValue(ObjectType::Ride), ride->subtype);
return std::make_shared<ScRideObject>(ObjectType::Ride, ride->subtype);
}
}
return nullptr;