diff --git a/Themes/default/BGAnimations/ScreenGameplay decorations/default.lua b/Themes/default/BGAnimations/ScreenGameplay decorations/default.lua index a8664db8b2..e7b9331a3b 100644 --- a/Themes/default/BGAnimations/ScreenGameplay decorations/default.lua +++ b/Themes/default/BGAnimations/ScreenGameplay decorations/default.lua @@ -91,45 +91,38 @@ local function CreateSegments(Player) end; for i=2,#bpms do - local data = split("=",bpms[i]); - bpmFrame[#bpmFrame+1] = CreateLine(data[1], 0, + bpmFrame[#bpmFrame+1] = CreateLine(bpms[i][1], 0, "#00808077", "#00808077", "#00808077", "#FF634777", "#FF000077"); end; for i=1,#delays do - local data = split("=",delays[i]); - delayFrame[#delayFrame+1] = CreateLine(data[1], data[2], + delayFrame[#delayFrame+1] = CreateLine(delays[i][1], delays[i][2], "#FFFF0077", "#FFFF0077", "#FFFF0077", "#00FF0077", "#FF000077"); end; for i=1,#stops do - local data = split("=",stops[i]); - stopFrame[#stopFrame+1] = CreateLine(data[1], data[2], + stopFrame[#stopFrame+1] = CreateLine(stops[i][1], stops[i][2], "#FFFFFF77", "#FFFFFF77", "#FFFFFF77", "#FFA50077", "#FF000077"); end; for i=1,#scrolls do - local data = split("=",scrolls[i]); - scrollFrame[#scrollFrame+1] = CreateLine(data[1], 0, + scrollFrame[#scrollFrame+1] = CreateLine(scrolls[i][1], 0, "#4169E177", "#4169E177", "#4169E177", "#0000FF77", "#FF000077"); end; for i=1,#speeds do - local data = split("=",speeds[i]); -- TODO: Turn beats into seconds for this calculation? - speedFrame[#speedFrame+1] = CreateLine(data[1], 0, + speedFrame[#speedFrame+1] = CreateLine(speeds[i][1], 0, "#ADFF2F77", "#ADFF2F77", "#ADFF2F77", "#7CFC0077", "#FF000077"); end; for i=1,#warps do - local data = split("=",warps[i]); - warpFrame[#warpFrame+1] = CreateLine(data[1], 0, + warpFrame[#warpFrame+1] = CreateLine(warps[i][1], 0, "#CC00CC77", "#CC00CC77", "#CC00CC77", "#FF33CC77", "#FF000077"); end; for i=1,#fakes do - local data = split("=",fakes[i]); - fakeFrame[#fakeFrame+1] = CreateLine(data[1], 0, + fakeFrame[#fakeFrame+1] = CreateLine(fakes[i][1], 0, "#BC8F8F77", "#BC8F8F77", "#BC8F8F77", "#F4A46077", "#FF000077"); end; end; diff --git a/src/TimingData.cpp b/src/TimingData.cpp index efa04bc13b..bad41a1bb3 100644 --- a/src/TimingData.cpp +++ b/src/TimingData.cpp @@ -991,6 +991,43 @@ vector TimingData::ToVectorString(TimingSegmentType tst, int dec) const // lua start #include "LuaBinding.h" +// This breaks encapsulation just as much as TimingData::ToVectorString does. +// But, it exists solely for the purpose of providing lua access, so it's as okay as all the other lua stuff that reaches past the encapsulation. +void TimingSegmentSetToLuaTable(TimingData* td, TimingSegmentType tst, lua_State *L); +void TimingSegmentSetToLuaTable(TimingData* td, TimingSegmentType tst, lua_State *L) +{ + const vector segs= td->GetTimingSegments(tst); + lua_createtable(L, segs.size(), 0); + if(tst == SEGMENT_LABEL) + { + for(size_t i= 0; i < segs.size(); ++i) + { + lua_createtable(L, 2, 0); + lua_pushnumber(L, segs[i]->GetBeat()); + lua_rawseti(L, -2, 1); + lua_pushstring(L, (ToLabel(segs[i]))->GetLabel().c_str()); + lua_rawseti(L, -2, 2); + lua_rawseti(L, -2, i+1); + } + } + else + { + for(size_t i= 0; i < segs.size(); ++i) + { + vector values= segs[i]->GetValues(); + lua_createtable(L, values.size()+1, 0); + lua_pushnumber(L, segs[i]->GetBeat()); + lua_rawseti(L, -2, 1); + for(size_t v= 0; v < values.size(); ++v) + { + lua_pushnumber(L, values[v]); + lua_rawseti(L, -2, v+2); + } + lua_rawseti(L, -2, i+1); + } + } +} + /** @brief Allow Lua to have access to the TimingData. */ class LunaTimingData: public Luna { @@ -1004,47 +1041,47 @@ public: static int HasScrollChanges( T* p, lua_State *L ) { lua_pushboolean(L, p->HasScrollChanges()); return 1; } static int GetWarps( T* p, lua_State *L ) { - LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_WARP), L); + TimingSegmentSetToLuaTable(p, SEGMENT_WARP, L); return 1; } static int GetFakes( T* p, lua_State *L ) { - LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_FAKE), L); + TimingSegmentSetToLuaTable(p, SEGMENT_FAKE, L); return 1; } static int GetScrolls( T* p, lua_State *L ) { - LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_SCROLL), L); + TimingSegmentSetToLuaTable(p, SEGMENT_SCROLL, L); return 1; } static int GetSpeeds( T* p, lua_State *L ) { - LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_SPEED), L); + TimingSegmentSetToLuaTable(p, SEGMENT_SPEED, L); return 1; } static int GetTimeSignatures( T* p, lua_State *L ) { - LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_TIME_SIG), L); + TimingSegmentSetToLuaTable(p, SEGMENT_TIME_SIG, L); return 1; } static int GetCombos( T* p, lua_State *L ) { - LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_COMBO), L); + TimingSegmentSetToLuaTable(p, SEGMENT_COMBO, L); return 1; } static int GetTickcounts( T* p, lua_State *L ) { - LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_TICKCOUNT), L); + TimingSegmentSetToLuaTable(p, SEGMENT_TICKCOUNT, L); return 1; } static int GetStops( T* p, lua_State *L ) { - LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_STOP), L); + TimingSegmentSetToLuaTable(p, SEGMENT_STOP, L); return 1; } static int GetDelays( T* p, lua_State *L ) { - LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_DELAY), L); + TimingSegmentSetToLuaTable(p, SEGMENT_DELAY, L); return 1; } static int GetBPMs( T* p, lua_State *L ) @@ -1060,12 +1097,12 @@ public: } static int GetLabels( T* p, lua_State *L ) { - LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_LABEL), L); + TimingSegmentSetToLuaTable(p, SEGMENT_LABEL, L); return 1; } static int GetBPMsAndTimes( T* p, lua_State *L ) { - LuaHelpers::CreateTableFromArray(p->ToVectorString(SEGMENT_BPM), L); + TimingSegmentSetToLuaTable(p, SEGMENT_BPM, L); return 1; } static int GetActualBPM( T* p, lua_State *L ) diff --git a/src/TimingSegments.cpp b/src/TimingSegments.cpp index c8b82e0a52..ac9d6a2ada 100644 --- a/src/TimingSegments.cpp +++ b/src/TimingSegments.cpp @@ -170,6 +170,14 @@ RString ComboSegment::ToString(int dec) const return ssprintf(str.c_str(), GetBeat(), GetCombo(), GetMissCombo()); } +vector ComboSegment::GetValues() const +{ + vector ret; + ret.push_back(GetCombo()); + ret.push_back(GetMissCombo()); + return ret; +} + RString LabelSegment::ToString(int dec) const { const RString str = "%.0" + IntToString(dec) + "f=%s"; @@ -189,6 +197,14 @@ RString TimeSignatureSegment::ToString(int dec) const return ssprintf(str.c_str(), GetBeat(), GetNum(), GetDen()); } +vector TimeSignatureSegment::GetValues() const +{ + vector ret; + ret.push_back(GetNum()); + ret.push_back(GetDen()); + return ret; +} + RString SpeedSegment::ToString(int dec) const { const RString str = "%.0" + IntToString(dec) @@ -198,6 +214,15 @@ RString SpeedSegment::ToString(int dec) const GetDelay(), GetUnit()); } +vector SpeedSegment::GetValues() const +{ + vector ret; + ret.push_back(GetRatio()); + ret.push_back(GetDelay()); + ret.push_back(GetUnit()); + return ret; +} + void SpeedSegment::Scale( int start, int oldLength, int newLength ) { if( GetUnit() == 0 ) diff --git a/src/TimingSegments.h b/src/TimingSegments.h index ef2c5e5e26..0fdf4a9db5 100644 --- a/src/TimingSegments.h +++ b/src/TimingSegments.h @@ -83,6 +83,11 @@ struct TimingSegment return FloatToString(GetBeat()); } + virtual vector GetValues() const + { + return vector(0); + } + bool operator<( const TimingSegment &other ) const { return GetRow() < other.GetRow(); @@ -148,6 +153,7 @@ struct FakeSegment : public TimingSegment void Scale( int start, int length, int newLength ); RString ToString( int dec ) const; + vector GetValues() const { return vector(1, GetLength()); } bool operator==( const FakeSegment &other ) const { @@ -205,6 +211,7 @@ struct WarpSegment : public TimingSegment void Scale( int start, int length, int newLength ); RString ToString( int dec ) const; + vector GetValues() const { return vector(1, GetLength()); } bool operator==( const WarpSegment &other ) const { @@ -259,6 +266,7 @@ struct TickcountSegment : public TimingSegment void SetTicks( int iTicks ) { m_iTicksPerBeat = iTicks; } RString ToString( int dec ) const; + vector GetValues() const { return vector(1, GetTicks()); } bool operator==( const TickcountSegment &other ) const { @@ -310,6 +318,7 @@ struct ComboSegment : public TimingSegment void SetMissCombo( int iCombo ) { m_iMissCombo = iCombo; } RString ToString( int dec ) const; + vector GetValues() const; bool operator==( const ComboSegment &other ) const { @@ -361,6 +370,8 @@ struct LabelSegment : public TimingSegment void SetLabel( const RString& sLabel ) { m_sLabel.assign(sLabel); } RString ToString( int dec ) const; + // Use the default definition for GetValues because the value for a LabelSegment is not a float or set of floats. + // TimingSegmentSetToLuaTable in TimingData.cpp has a special case for labels to handle this. bool operator==( const LabelSegment &other ) const { @@ -408,6 +419,7 @@ struct BPMSegment : public TimingSegment void SetBPM( float fBPM ) { m_fBPS = fBPM / 60.0f; } RString ToString( int dec ) const; + vector GetValues() const { return vector(1, GetBPM()); } bool operator==( const BPMSegment &other ) const { @@ -464,6 +476,7 @@ struct TimeSignatureSegment : public TimingSegment void Set( int num, int den ) { m_iNumerator = num; m_iDenominator = den; } RString ToString( int dec ) const; + vector GetValues() const; /** * @brief Retrieve the number of note rows per measure within the TimeSignatureSegment. @@ -545,6 +558,7 @@ struct SpeedSegment : public TimingSegment void Scale( int start, int length, int newLength ); RString ToString( int dec ) const; + vector GetValues() const; bool operator==( const SpeedSegment &other ) const { @@ -604,6 +618,7 @@ struct ScrollSegment : public TimingSegment void SetRatio( float fRatio ) { m_fRatio = fRatio; } RString ToString( int dec ) const; + vector GetValues() const { return vector(1, GetRatio()); } bool operator==( const ScrollSegment &other ) const { @@ -648,6 +663,7 @@ struct StopSegment : public TimingSegment void SetPause( float fSeconds ) { m_fSeconds = fSeconds; } RString ToString( int dec ) const; + vector GetValues() const { return vector(1, GetPause()); } bool operator==( const StopSegment &other ) const { @@ -691,6 +707,7 @@ struct DelaySegment : public TimingSegment void SetPause( float fSeconds ) { m_fSeconds = fSeconds; } RString ToString( int dec ) const; + vector GetValues() const { return vector(1, GetPause()); } bool operator==( const DelaySegment &other ) const {