Fix #10439: [GS] Validate story page button colour, flags, cursor and vehicle type (#11892)

Adds GSStoryPage::IsValidStoryPageButtonColour, GSStoryPage::IsValidStoryPageButtonFlags and GSStoryPage::IsValidStoryPageButtonCursor to the API.

Add missing enforced preconditions to validate parameters passed to MakePushButtonReference, MakeTileButtonReference and MakeVehicleButtonReference.
This commit is contained in:
SamuXarick
2024-01-27 23:29:10 +00:00
committed by GitHub
parent 76f0f9e386
commit 0c4e509b60
4 changed files with 71 additions and 5 deletions

View File

@@ -146,7 +146,7 @@ public:
* Colour codes usable for story page button elements.
* Place a colour value in the lowest 8 bits of the \c reference parameter to the button.
*/
enum StoryPageButtonColour {
enum StoryPageButtonColour : byte {
SPBC_DARK_BLUE = ::COLOUR_DARK_BLUE,
SPBC_PALE_GREEN = ::COLOUR_PALE_GREEN,
SPBC_PINK = ::COLOUR_PINK,
@@ -320,11 +320,34 @@ public:
*/
static bool RemoveElement(StoryPageElementID story_page_element_id);
/**
* Check whether this is a valid story page button colour.
* @param colour The StoryPageButtonColour to check.
* @return True if and only if this story page button colour is valid.
*/
static bool IsValidStoryPageButtonColour(StoryPageButtonColour colour);
/**
* Check whether this is a valid story page button flag.
* @param colour The StoryPageButtonFlags to check.
* @return True if and only if this story page button flag is valid.
*/
static bool IsValidStoryPageButtonFlags(StoryPageButtonFlags flags);
/**
* Check whether this is a valid story page button cursor.
* @param colour The StoryPageButtonCursor to check.
* @return True if and only if this story page button cursor is valid.
*/
static bool IsValidStoryPageButtonCursor(StoryPageButtonCursor cursor);
/**
* Create a reference value for SPET_BUTTON_PUSH element parameters.
* @param colour The colour for the face of the button.
* @param flags The formatting and layout flags for the button.
* @return A reference value usable with the #NewElement and #UpdateElement functions.
* @pre IsValidStoryPageButtonColour(colour).
* @pre IsValidStoryPageButtonFlags(flags).
*/
static StoryPageButtonFormatting MakePushButtonReference(StoryPageButtonColour colour, StoryPageButtonFlags flags);
@@ -334,6 +357,9 @@ public:
* @param flags The formatting and layout flags for the button.
* @param cursor The mouse cursor to use when the player clicks the button and the game is ready for the player to select a tile.
* @return A reference value usable with the #NewElement and #UpdateElement functions.
* @pre IsValidStoryPageButtonColour(colour).
* @pre IsValidStoryPageButtonFlags(flags).
* @pre IsValidStoryPageButtonCursor(cursor).
*/
static StoryPageButtonFormatting MakeTileButtonReference(StoryPageButtonColour colour, StoryPageButtonFlags flags, StoryPageButtonCursor cursor);
@@ -344,6 +370,10 @@ public:
* @param cursor The mouse cursor to use when the player clicks the button and the game is ready for the player to select a vehicle.
* @param vehtype The type of vehicle that will be selectable, or \c VT_INVALID to allow all types.
* @return A reference value usable with the #NewElement and #UpdateElement functions.
* @pre IsValidStoryPageButtonColour(colour).
* @pre IsValidStoryPageButtonFlags(flags).
* @pre IsValidStoryPageButtonCursor(cursor).
* @pre vehtype == ScriptVehicle::VT_INVALID || vehtype == ScriptVehicle::VT_RAIL || vehtype == ScriptVehicle::VT_ROAD || vehtype == ScriptVehicle::VT_WATER || vehtype == ScriptVehicle::VT_AIR.
*/
static StoryPageButtonFormatting MakeVehicleButtonReference(StoryPageButtonColour colour, StoryPageButtonFlags flags, StoryPageButtonCursor cursor, ScriptVehicle::VehicleType vehtype);
};