From d71d93752c61da83f9012c2202a8b8bc0d65b530 Mon Sep 17 00:00:00 2001 From: Barinade Date: Mon, 16 Sep 2019 20:21:10 -0500 Subject: [PATCH] Oversimplify & overcomplicate Practice Mode flags/options im not happy with this but oops --- .../Screen/Others/ScreenSelectMusic.cpp | 12 +---- src/Etterna/Singletons/GameState.cpp | 45 +++++++++++++++++++ src/Etterna/Singletons/GameState.h | 3 ++ 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/Etterna/Screen/Others/ScreenSelectMusic.cpp b/src/Etterna/Screen/Others/ScreenSelectMusic.cpp index 4d3c46e9cd..e0da4e0470 100644 --- a/src/Etterna/Screen/Others/ScreenSelectMusic.cpp +++ b/src/Etterna/Screen/Others/ScreenSelectMusic.cpp @@ -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(); } @@ -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 diff --git a/src/Etterna/Singletons/GameState.cpp b/src/Etterna/Singletons/GameState.cpp index bd24e793a7..7a458ed107 100644 --- a/src/Etterna/Singletons/GameState.cpp +++ b/src/Etterna/Singletons/GameState.cpp @@ -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" @@ -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" @@ -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" @@ -1871,8 +1908,14 @@ class LunaGameState : public Luna 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); @@ -1964,6 +2007,8 @@ class LunaGameState : public Luna ADD_METHOD(UpdateDiscordPresence); ADD_METHOD(IsPaused); ADD_METHOD(GetGameplayMode); + ADD_METHOD(IsPracticeMode); + ADD_METHOD(SetPracticeMode); } }; diff --git a/src/Etterna/Singletons/GameState.h b/src/Etterna/Singletons/GameState.h index 70bb044c5e..ea8dbc1844 100644 --- a/src/Etterna/Singletons/GameState.h +++ b/src/Etterna/Singletons/GameState.h @@ -317,6 +317,9 @@ class GameState // Current mode of Gameplay BroadcastOnChange 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;