1
0
Fork 0

Codechange: strongly type LeagueTableID and LeagueTableElementID

pull/13511/head
Rubidium 2025-01-31 21:37:32 +01:00 committed by rubidium42
parent 6aada55e96
commit 6c8915fdbc
5 changed files with 12 additions and 11 deletions

View File

@ -17,10 +17,10 @@
bool IsValidLink(Link link);
typedef Pool<LeagueTableElement, LeagueTableElementID, 64, 64000> LeagueTableElementPool;
using LeagueTableElementPool = Pool<LeagueTableElement, LeagueTableElementID, 64, LeagueTableElementID::End().base()>;
extern LeagueTableElementPool _league_table_element_pool;
typedef Pool<LeagueTable, LeagueTableID, 4, 255> LeagueTablePool;
using LeagueTablePool = Pool<LeagueTable, LeagueTableID, 4, LeagueTableID::End().base()>;
extern LeagueTablePool _league_table_pool;

View File

@ -298,9 +298,8 @@ private:
}
public:
ScriptLeagueWindow(WindowDesc &desc, LeagueTableID table) : Window(desc)
ScriptLeagueWindow(WindowDesc &desc, WindowNumber table) : Window(desc), table(table)
{
this->table = table;
this->BuildTable();
this->InitNested(table);
}

View File

@ -10,6 +10,8 @@
#ifndef LEAGUE_TYPE_H
#define LEAGUE_TYPE_H
#include "core/pool_type.hpp"
/** Types of the possible link targets. */
enum LinkType : uint8_t {
LT_NONE = 0, ///< No link
@ -29,12 +31,12 @@ struct Link {
Link(): Link(LT_NONE, 0) {}
};
typedef uint8_t LeagueTableID; ///< ID of a league table
using LeagueTableID = PoolID<uint8_t, struct LeagueTableIDTag, 255, 0xFF>; ///< ID of a league table
struct LeagueTable;
static const LeagueTableID INVALID_LEAGUE_TABLE = 0xFF; ///< Invalid/unknown index of LeagueTable
static constexpr LeagueTableID INVALID_LEAGUE_TABLE = LeagueTableID::Invalid(); ///< Invalid/unknown index of LeagueTable
typedef uint16_t LeagueTableElementID; ///< ID of a league table element
using LeagueTableElementID = PoolID<uint16_t, struct LeagueTableElementIDTag, 64000, 0xFFFF>; ///< ID of a league table
struct LeagueTableElement;
static const LeagueTableElementID INVALID_LEAGUE_TABLE_ELEMENT = 0xFFFF; ///< Invalid/unknown index of LeagueTableElement
static constexpr LeagueTableElementID INVALID_LEAGUE_TABLE_ELEMENT = LeagueTableElementID::Invalid(); ///< Invalid/unknown index of LeagueTableElement
#endif /* LEAGUE_TYPE_H */

View File

@ -41,7 +41,7 @@
if (!ScriptObject::Command<CMD_CREATE_LEAGUE_TABLE>::Do(&ScriptInstance::DoCommandReturnLeagueTableID, encoded_title, encoded_header, encoded_footer)) return LEAGUE_TABLE_INVALID;
/* In case of test-mode, we return LeagueTableID 0 */
return static_cast<LeagueTableID>(0);
return LeagueTableID::Begin();
}
/* static */ bool ScriptLeagueTable::IsValidLeagueTableElement(LeagueTableElementID element_id)
@ -74,7 +74,7 @@
if (!ScriptObject::Command<CMD_CREATE_LEAGUE_TABLE_ELEMENT>::Do(&ScriptInstance::DoCommandReturnLeagueTableElementID, table, rating, c, encoded_text, encoded_score, (::LinkType)link_type, (::LinkTargetID)link_target)) return LEAGUE_TABLE_ELEMENT_INVALID;
/* In case of test-mode, we return LeagueTableElementID 0 */
return static_cast<LeagueTableElementID>(0);
return LeagueTableElementID::Begin();
}
/* static */ bool ScriptLeagueTable::UpdateElementData(LeagueTableElementID element, ScriptCompany::CompanyID company, Text *text, LinkType link_type, SQInteger link_target)

View File

@ -663,7 +663,7 @@ static void AddDropDownLeagueTableOptions(DropDownList &list)
{
if (LeagueTable::GetNumItems() > 0) {
for (LeagueTable *lt : LeagueTable::Iterate()) {
list.push_back(MakeDropDownListStringItem(lt->title, lt->index));
list.push_back(MakeDropDownListStringItem(lt->title, lt->index.base()));
}
} else {
list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_COMPANY_LEAGUE_TABLE, LTMN_PERFORMANCE_LEAGUE));