Skip to content

Commit

Permalink
Rename GameplayPractice functions in more sane ways
Browse files Browse the repository at this point in the history
also allow more fine usage of SetSongPosition
  • Loading branch information
poco0317 committed Nov 1, 2019
1 parent c3bc281 commit a1c69b4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -948,12 +948,12 @@ local function duminput(event)
MESSAGEMAN:Broadcast("MouseRightClick")
elseif event.DeviceInput.button == "DeviceButton_backspace" and event.type == "InputEventType_FirstPress" then
if bookmarkPosition ~= nil then
SCREENMAN:GetTopScreen():SetPreviewNoteFieldMusicPosition(bookmarkPosition)
SCREENMAN:GetTopScreen():SetSongPosition(bookmarkPosition)
end
elseif event.button == "EffectUp" and event.type == "InputEventType_FirstPress" then
SCREENMAN:GetTopScreen():AddToPracticeRate(0.05)
SCREENMAN:GetTopScreen():AddToRate(0.05)
elseif event.button == "EffectDown" and event.type == "InputEventType_FirstPress" then
SCREENMAN:GetTopScreen():AddToPracticeRate(-0.05)
SCREENMAN:GetTopScreen():AddToRate(-0.05)
end
return false
end
Expand Down Expand Up @@ -1047,7 +1047,7 @@ pm[#pm + 1] =
end,
MouseLeftClickMessageCommand = function(self)
if isOver(self) then
SCREENMAN:GetTopScreen():SetPreviewNoteFieldMusicPosition(self:GetX() * musicratio)
SCREENMAN:GetTopScreen():SetSongPosition(self:GetX() * musicratio)
end
end,
MouseRightClickMessageCommand = function(self)
Expand All @@ -1056,7 +1056,7 @@ pm[#pm + 1] =
self:GetParent():GetChild("BookmarkPos"):queuecommand("Set")
else
if not (allowedCustomization) then
SCREENMAN:GetTopScreen():TogglePracticePause()
SCREENMAN:GetTopScreen():TogglePause()
end
end
end
Expand Down
43 changes: 29 additions & 14 deletions src/Etterna/Screen/Gameplay/ScreenGameplayPractice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ ScreenGameplayPractice::Update(float fDeltaTime)
}

void
ScreenGameplayPractice::SetupNoteDataFromRow(Steps* pSteps, int row)
ScreenGameplayPractice::SetupNoteDataFromRow(Steps* pSteps,
int minRow,
int maxRow)
{
NoteData originalNoteData;
pSteps->GetNoteData(originalNoteData);
Expand All @@ -128,6 +130,10 @@ ScreenGameplayPractice::SetupNoteDataFromRow(Steps* pSteps, int row)
pStyle->GetTransformedNoteDataForStyle(
m_vPlayerInfo.GetStepsAndTrailIndex(), originalNoteData, ndTransformed);

m_vPlayerInfo.GetPlayerState()->Update(0);

NoteDataUtil::RemoveAllButRange(ndTransformed, minRow, maxRow);

// load player
{
m_vPlayerInfo.m_NoteData = ndTransformed;
Expand Down Expand Up @@ -165,7 +171,7 @@ ScreenGameplayPractice::SetupNoteDataFromRow(Steps* pSteps, int row)
}

void
ScreenGameplayPractice::TogglePracticePause()
ScreenGameplayPractice::TogglePause()
{
// True if we were paused before now
bool oldPause = GAMESTATE->GetPaused();
Expand Down Expand Up @@ -202,13 +208,22 @@ ScreenGameplayPractice::TogglePracticePause()
}

void
ScreenGameplayPractice::SetPracticeSongPosition(float newPositionSeconds)
ScreenGameplayPractice::SetSongPosition(float newSongPositionSeconds,
float noteDelay)
{
SOUND->SetSoundPosition(m_pSoundMusic, newPositionSeconds);
SOUND->SetSoundPosition(m_pSoundMusic, newSongPositionSeconds - noteDelay);
UpdateSongPosition(0);

bool isPaused = GAMESTATE->GetPaused();
m_pSoundMusic->Pause(isPaused);

Steps* pSteps = GAMESTATE->m_pCurSteps;
TimingData* pTiming = pSteps->GetTimingData();
const float fSongBeat = GAMESTATE->m_Position.m_fSongBeat;
const float fNotesBeat =
pTiming->GetBeatFromElapsedTime(newSongPositionSeconds);
const int rowNow = BeatToNoteRow(fNotesBeat);
SetupNoteDataFromRow(pSteps, rowNow);
m_vPlayerInfo.m_pPlayer->RenderAllNotesIgnoreScores();

// curwifescore sent via judgment msgs is stored in player
Expand Down Expand Up @@ -243,7 +258,7 @@ ScreenGameplayPractice::SetPracticeSongPosition(float newPositionSeconds)
}

float
ScreenGameplayPractice::AddToPracticeRate(float amountAdded)
ScreenGameplayPractice::AddToRate(float amountAdded)
{
float rate = GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate;

Expand Down Expand Up @@ -295,31 +310,31 @@ ScreenGameplayPractice::AddToPracticeRate(float amountAdded)
class LunaScreenGameplayPractice : public Luna<ScreenGameplayPractice>
{
public:
static int SetPreviewNoteFieldMusicPosition(T* p, lua_State* L)
static int SetSongPosition(T* p, lua_State* L)
{
float given = FArg(1);
p->SetPracticeSongPosition(given);
p->SetSongPosition(given);
return 0;
}

static int AddToPracticeRate(T* p, lua_State* L)
static int AddToRate(T* p, lua_State* L)
{
float rate = FArg(1);
lua_pushnumber(L, p->AddToPracticeRate(rate));
lua_pushnumber(L, p->AddToRate(rate));
return 1;
}

static int TogglePracticePause(T* p, lua_State* L)
static int TogglePause(T* p, lua_State* L)
{
p->TogglePracticePause();
p->TogglePause();
return 0;
}

LunaScreenGameplayPractice()
{
ADD_METHOD(SetPreviewNoteFieldMusicPosition);
ADD_METHOD(AddToPracticeRate);
ADD_METHOD(TogglePracticePause);
ADD_METHOD(SetSongPosition);
ADD_METHOD(AddToRate);
ADD_METHOD(TogglePause);
}
};

Expand Down
15 changes: 8 additions & 7 deletions src/Etterna/Screen/Gameplay/ScreenGameplayPractice.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ class ScreenGameplayPractice : public ScreenGameplay

// Set the playback rate in the middle of gameplay
float SetRate(float newRate);
// Set the playback rate in the middle of gameplay, in practice mode only
float AddToPracticeRate(float amountAdded);
// Move the current position of the song in the middle of gameplay, in
// practice mode only
void SetPracticeSongPosition(float newPositionSeconds);
// Add to the playback rate in the middle of gameplay
float AddToRate(float amountAdded);
// Move the current position of the song in the middle of gameplay
void SetSongPosition(float newSongPositionSeconds, float noteDelay = 0.f);
// Toggle pause
void TogglePracticePause();
void TogglePause();

protected:
void SetupNoteDataFromRow(Steps* pSteps, int row) override;
void SetupNoteDataFromRow(Steps* pSteps,
int minRow = 0,
int maxrow = MAX_NOTE_ROW);
};

#endif

0 comments on commit a1c69b4

Please sign in to comment.