Skip to content

Commit

Permalink
Oversimplify & overcomplicate Practice Mode flags/options
Browse files Browse the repository at this point in the history
im not happy with this but oops
  • Loading branch information
poco0317 committed Sep 17, 2019
1 parent 66792d3 commit d71d937
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/Etterna/Screen/Others/ScreenSelectMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ ScreenSelectMusic::Init()
m_soundLocked.Load(THEME->GetPathS(m_sName, "locked"));

m_pPreviewNoteField = nullptr;
GAMESTATE->m_gameplayMode.Set(GameplayMode_Normal);

this->SortByDrawOrder();
}
Expand Down Expand Up @@ -507,15 +506,8 @@ ScreenSelectMusic::Input(const InputEventPlus& input)
return true;
} else if (bHoldingCtrl && c == 'O' && m_MusicWheel.IsSettled() &&
input.type == IET_FIRST_PRESS) {
bool opposite =
!GAMESTATE->m_pPlayerState->m_PlayerOptions.GetPreferred()
.m_bPractice;
GAMESTATE->m_pPlayerState->m_PlayerOptions.GetPreferred()
.m_bPractice = opposite;
GAMESTATE->m_pPlayerState->m_PlayerOptions.GetCurrent()
.m_bPractice = opposite;
GAMESTATE->m_pPlayerState->m_PlayerOptions.GetSong().m_bPractice =
opposite;
bool opposite = !GAMESTATE->IsPracticeMode();
GAMESTATE->TogglePracticeMode(opposite);
if (opposite)
SCREENMAN->SystemMessage("Practice Mode On");
else
Expand Down
45 changes: 45 additions & 0 deletions src/Etterna/Singletons/GameState.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "Etterna/Globals/global.h"
#include "Etterna/Actor/Base/Actor.h"
#include "Etterna/Models/Misc/AdjustSync.h"
#include "Etterna/Models/Misc/Character.h"
#include "Etterna/Models/Misc/CommonMetrics.h"
#include "CryptManager.h"
#include "discord_rpc.h"
#include "DownloadManager.h"
#include "Etterna/Models/Misc/Foreach.h"
#include "Etterna/Models/Misc/Game.h"
#include "Etterna/Models/Misc/GameCommand.h"
Expand All @@ -18,6 +20,7 @@
#include "Etterna/Models/Misc/PlayerState.h"
#include "ProfileManager.h"
#include "ScreenManager.h"
#include "Etterna/Screen/Others/Screen.h"
#include "Etterna/Models/Songs/Song.h"
#include "Etterna/Models/Songs/SongUtil.h"
#include "StatsManager.h"
Expand Down Expand Up @@ -1373,6 +1376,40 @@ GameState::updateDiscordPresenceMenu(const RString& largeImageText)
Discord_UpdatePresence(&discordPresence);
}

void
GameState::TogglePracticeModeSafe(bool set)
{
auto screenname = SCREENMAN->GetTopScreen()->GetName();
bool gameplayscreen =
screenname.find("ScreenGameplay") != std::string::npos;

// This isnt really "safe" but should at least make it harder to break
if (m_gameplayMode != GameplayMode_Replay && !gameplayscreen) {
TogglePracticeMode(set);
}
}

void
GameState::TogglePracticeMode(bool set)
{
m_pPlayerState->m_PlayerOptions.GetCurrent().m_bPractice = set;
m_pPlayerState->m_PlayerOptions.GetPreferred().m_bPractice = set;
m_pPlayerState->m_PlayerOptions.GetSong().m_bPractice = set;
m_gameplayMode.Set(set ? GameplayMode_Practice : GameplayMode_Normal);
}

bool
GameState::IsPracticeMode()
{
GameplayMode mode = GetGameplayMode();
bool ispractice =
mode == GameplayMode_Practice &&
m_pPlayerState->m_PlayerOptions.GetCurrent().m_bPractice &&
m_pPlayerState->m_PlayerOptions.GetPreferred().m_bPractice &&
m_pPlayerState->m_PlayerOptions.GetSong().m_bPractice;
return ispractice;
}

// lua start
#include "Etterna/Models/Misc/Game.h"
#include "Etterna/Models/Lua/LuaBinding.h"
Expand Down Expand Up @@ -1871,8 +1908,14 @@ class LunaGameState : public Luna<GameState>
LuaHelpers::Push(L, mode);
return 1;
}
static int SetPracticeMode(T* p, lua_State* L)
{
p->TogglePracticeModeSafe(BArg(1));
return 0;
}

DEFINE_METHOD(GetEtternaVersion, GetEtternaVersion())
DEFINE_METHOD(IsPracticeMode, IsPracticeMode())
LunaGameState()
{
ADD_METHOD(SetAutoplay);
Expand Down Expand Up @@ -1964,6 +2007,8 @@ class LunaGameState : public Luna<GameState>
ADD_METHOD(UpdateDiscordPresence);
ADD_METHOD(IsPaused);
ADD_METHOD(GetGameplayMode);
ADD_METHOD(IsPracticeMode);
ADD_METHOD(SetPracticeMode);
}
};

Expand Down
3 changes: 3 additions & 0 deletions src/Etterna/Singletons/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ class GameState
// Current mode of Gameplay
BroadcastOnChange<GameplayMode> m_gameplayMode;
GameplayMode GetGameplayMode() { return m_gameplayMode; }
void TogglePracticeModeSafe(bool set);
void TogglePracticeMode(bool set);
bool IsPracticeMode();

// A "persistent" way to know if we restarted gameplay (hack)
bool m_bRestartedGameplay;
Expand Down

0 comments on commit d71d937

Please sign in to comment.