Skip to content

Commit ac19b96

Browse files
committed
Simplify Gameplay Type identification using an enum
dont use a bunch of bools haha
1 parent 055ef81 commit ac19b96

File tree

7 files changed

+37
-14
lines changed

7 files changed

+37
-14
lines changed

Themes/_fallback/Scripts/02 Branches.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ function GameOverOrContinue()
3333
end
3434

3535
function ToGameplay()
36-
if GAMESTATE:IsPracticeMode() then
36+
local mode = GAMESTATE:GetGameplayMode()
37+
if mode == "GameplayMode_Practice" then
3738
return "ScreenGameplayPractice"
38-
elseif GAMESTATE:IsReplayMode() then
39+
elseif mode == "GameplayMode_Replay" then
3940
return "ScreenGameplayReplay"
4041
else
4142
return "ScreenGameplay"

src/Etterna/Models/Misc/GameConstantsAndTypes.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ static const char* HealthStateNames[] = {
9595
XToString(HealthState);
9696
LuaXType(HealthState);
9797

98+
static const char* GameplayModeNames[] = {
99+
"Normal",
100+
"Practice",
101+
"Replay",
102+
};
103+
XToString(GameplayMode);
104+
LuaXType(GameplayMode);
105+
98106
static const char* SortOrderNames[] = {
99107
"Preferred", "Group", "Title", "BPM", "Popularity",
100108
"TopGrades", "Artist", "Genre", "ModeMenu", "Recent",

src/Etterna/Models/Misc/GameConstantsAndTypes.h

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ const int MIN_METER = 1;
1818
*/
1919
const int MAX_METER = 35;
2020

21+
enum GameplayMode
22+
{
23+
GameplayMode_Normal,
24+
GameplayMode_Practice,
25+
GameplayMode_Replay,
26+
NUM_GameplayMode,
27+
GameplayMode_Invalid
28+
};
29+
2130
enum Skillset
2231
{
2332
Skill_Overall,

src/Etterna/Singletons/GameState.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ GameState::GameState()
9292
, m_pCurSteps(Message_CurrentStepsP1Changed)
9393
, m_bGameplayLeadIn(Message_GameplayLeadInChanged)
9494
, m_sEditLocalProfileID(Message_EditLocalProfileIDChanged)
95+
, m_gameplayMode(Message_GameplayModeChanged)
9596
{
9697
g_pImpl = new GameStateImpl;
9798

@@ -103,6 +104,8 @@ GameState::GameState()
103104

104105
m_iStageSeed = m_iGameSeed = 0;
105106

107+
m_gameplayMode.Set(GameplayMode_Normal);
108+
106109
m_PlayMode.Set(
107110
PlayMode_Invalid); // used by IsPlayerEnabled before the first screen
108111
m_bSideIsJoined =
@@ -1862,8 +1865,12 @@ class LunaGameState : public Luna<GameState>
18621865
GamePreferences::m_AutoPlay.Set(p->m_pPlayerState->m_PlayerController);
18631866
return 0;
18641867
}
1865-
DEFINE_METHOD(IsPracticeMode, IsPracticeMode())
1866-
DEFINE_METHOD(IsReplayMode, IsReplayMode())
1868+
static int GetGameplayMode(T* p, lua_State* L)
1869+
{
1870+
GameplayMode mode = p->GetGameplayMode();
1871+
LuaHelpers::Push(L, mode);
1872+
return 1;
1873+
}
18671874

18681875
DEFINE_METHOD(GetEtternaVersion, GetEtternaVersion())
18691876
LunaGameState()
@@ -1956,8 +1963,7 @@ class LunaGameState : public Luna<GameState>
19561963
ADD_METHOD(UpdateDiscordMenu);
19571964
ADD_METHOD(UpdateDiscordPresence);
19581965
ADD_METHOD(IsPaused);
1959-
ADD_METHOD(IsPracticeMode);
1960-
ADD_METHOD(IsReplayMode);
1966+
ADD_METHOD(GetGameplayMode);
19611967
}
19621968
};
19631969

src/Etterna/Singletons/GameState.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,9 @@ class GameState
314314
Profile* GetEditLocalProfile();
315315
bool m_bIsChartPreviewActive;
316316

317-
// is the game in a practice state
318-
bool m_practice = false;
319-
// is the game in a replay state
320-
bool m_replay = false;
321-
bool IsPracticeMode() { return m_practice; }
322-
bool IsReplayMode() { return m_replay; }
317+
// Current mode of Gameplay
318+
BroadcastOnChange<GameplayMode> m_gameplayMode;
319+
GameplayMode GetGameplayMode() { return m_gameplayMode; }
323320

324321
// Discord Rich Presence
325322
void discordInit();

src/Etterna/Singletons/MessageManager.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "Etterna/Globals/global.h"
1+
#include "Etterna/Globals/global.h"
22
#include "Etterna/Models/Misc/EnumHelper.h"
33
#include "Etterna/Models/Misc/Foreach.h"
44
#include "LuaManager.h"
@@ -25,6 +25,7 @@ static const char* MessageIDNames[] = {
2525
"CurrentTrailP1Changed",
2626
"CurrentTrailP2Changed",
2727
"GameplayLeadInChanged",
28+
"GameplayModeChanged",
2829
"EditStepsTypeChanged",
2930
"EditCourseDifficultyChanged",
3031
"EditSourceStepsChanged",

src/Etterna/Singletons/MessageManager.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ifndef MessageManager_H
1+
#ifndef MessageManager_H
22
#define MessageManager_H
33

44
#include "LuaManager.h"
@@ -20,6 +20,7 @@ enum MessageID
2020
Message_CurrentTrailP1Changed,
2121
Message_CurrentTrailP2Changed,
2222
Message_GameplayLeadInChanged,
23+
Message_GameplayModeChanged,
2324
Message_EditStepsTypeChanged,
2425
Message_EditCourseDifficultyChanged,
2526
Message_EditSourceStepsChanged,

0 commit comments

Comments
 (0)