Skip to content

Commit 895556c

Browse files
committed
Refactor DataModule type flags - use an enum
1 parent 5773dd5 commit 895556c

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

System/DataModule.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace RTE {
1111
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1212

1313
void DataModule::Clear() {
14-
m_IsUserdata = false;
14+
m_ModuleType = DataModuleType::Unofficial;
1515
m_FileName.clear();
1616
m_FriendlyName.clear();
1717
m_Author.clear();
@@ -56,7 +56,7 @@ namespace RTE {
5656
size_t lastPeriodPosition = m_SupportedGameVersion.find_last_of(".");
5757
std::string supportedMajorGameVersion = m_SupportedGameVersion.substr(0, lastPeriodPosition);
5858
std::string supportedMinorGameVersion = lastPeriodPosition == std::string::npos ? ".0" : m_SupportedGameVersion.substr(lastPeriodPosition, m_SupportedGameVersion.length());
59-
if (m_ModuleID >= g_ModuleMan.GetOfficialModuleCount() && !m_IsUserdata && (supportedMajorGameVersion != c_MajorGameVersion || supportedMinorGameVersion > c_MinorGameVersion)) {
59+
if (m_ModuleType == DataModuleType::Unofficial && (supportedMajorGameVersion != c_MajorGameVersion || supportedMinorGameVersion > c_MinorGameVersion)) {
6060
RTEAssert(!m_SupportedGameVersion.empty(), m_FileName + " does not specify a supported Cortex Command version, so it is not compatible with this version of Cortex Command (" + c_MajorGameVersion + c_MinorGameVersion + ").\nPlease contact the mod author or ask for help in the CCCP discord server.");
6161
RTEAssert(supportedMinorGameVersion <= c_MinorGameVersion, m_FileName + " supports Cortex Command version " + m_SupportedGameVersion + ", which is ahead of this version of Cortex Command (" + c_MajorGameVersion + c_MinorGameVersion + ").\nPlease update your game to the newest version to use this mod.");
6262
RTEAbort(m_FileName + " supports Cortex Command version " + m_SupportedGameVersion + ", so it is not compatible with this version of Cortex Command (" + c_MajorGameVersion + c_MinorGameVersion + ").\nPlease contact the mod author or ask for help in the CCCP discord server.");
@@ -78,7 +78,7 @@ namespace RTE {
7878
std::string moduleNameWithPackageExtension = System::GetUserdataDirectory() + moduleName + (moduleName.ends_with(System::GetModulePackageExtension()) ? "" : System::GetModulePackageExtension());
7979
if (Writer writer(moduleNameWithPackageExtension + "/Index.ini", false, true); writer.WriterOK()) {
8080
DataModule newModule;
81-
newModule.m_IsUserdata = true;
81+
newModule.m_ModuleType = DataModuleType::Userdata;
8282
newModule.m_FriendlyName = friendlyName;
8383
newModule.m_IgnoreMissingItems = ignoreMissingItems;
8484
newModule.m_ScanFolderContents = scanFolderContents;
@@ -201,7 +201,7 @@ namespace RTE {
201201

202202
writer.NewPropertyWithValue("ModuleName", m_FriendlyName);
203203

204-
if (!m_IsUserdata) {
204+
if (!IsUserdata()) {
205205
writer.NewPropertyWithValue("Author", m_Author);
206206
writer.NewPropertyWithValue("Description", m_Description);
207207
writer.NewPropertyWithValue("IsFaction", m_IsFaction);

System/DataModule.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ namespace RTE {
2222
SerializableClassNameGetter;
2323
SerializableOverrideMethods;
2424

25+
/// <summary>
26+
/// Enumeration for the different types of DataModules.
27+
/// </summary>
28+
enum class DataModuleType {
29+
Unofficial, // Mods and any other modules not shipped with the game.
30+
Official,
31+
Userdata // Userdata written by the game (e.g saved games or editor scenes) that should be ignored anywhere where that is relevant.
32+
};
33+
2534
/// <summary>
2635
/// Struct that holds data about the custom BuyMenu/ObjectPicker theme of this DataModule.
2736
/// Themes are used when a DataModule is considered a faction and is selected to be played as in an Activity.
@@ -102,15 +111,16 @@ namespace RTE {
102111

103112
#pragma region Module Information Getters
104113
/// <summary>
105-
/// Gets whether this DataModule is a userdata module.
114+
/// Gets whether this DataModule is an official module.
106115
/// </summary>
107-
/// <returns>Whether this DataModule is used for userdata written by the game.</returns>
108-
bool IsUserdata() const { return m_IsUserdata; }
116+
/// <returns>Whether this DataModule is an official module.</returns>
117+
bool IsOfficial() const { return m_ModuleType == DataModuleType::Official; }
109118

110119
/// <summary>
111-
/// Sets this DataModule as a userdata module.
120+
/// Gets whether this DataModule is a userdata module.
112121
/// </summary>
113-
void SetAsUserdata() { m_IsUserdata = true; }
122+
/// <returns>Whether this DataModule is used for userdata written by the game.</returns>
123+
bool IsUserdata() const { return m_ModuleType == DataModuleType::Userdata; }
114124

115125
/// <summary>
116126
/// Gets the file name of this DataModule, e.g. "MyMod.rte".
@@ -309,7 +319,7 @@ namespace RTE {
309319
std::string m_FileReadFrom; //!< Where the instance was read from.
310320
};
311321

312-
bool m_IsUserdata; //!< Whether this DataModule contains userdata written by the game (e.g saved games or editor scenes), meaning it is not an official nor a 3rd party module and is ignored anywhere where that is relevant.
322+
DataModuleType m_ModuleType; //!< The type of this DataModule. See DataModuleType enumeration.
313323
bool m_ScanFolderContents; //!< Indicates whether module loader should scan for any .ini's inside module folder instead of loading files defined in IncludeFile only.
314324
bool m_IgnoreMissingItems; //!< Indicates whether module loader should ignore missing items in this module.
315325

0 commit comments

Comments
 (0)