Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.48 KB | None | 0 0
  1. --[[~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2.                                                                 **BPM Display**
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4.  
  5.     Better optimized frame update bpm display.
  6. ]]
  7. local BPM
  8. local a = GAMESTATE:GetPlayerState(PLAYER_1):GetSongPosition()
  9. local r = GAMESTATE:GetSongOptionsObject("ModsLevel_Current"):MusicRate() * 60
  10. local GetBPS = SongPosition.GetCurBPS
  11.  
  12. local function UpdateBPM(self)
  13.     local bpm = GetBPS(a) * r
  14.     settextf("%4.1f BPM",GetBPS(a) * r)
  15. end
  16.  
  17. t[#t + 1] =
  18.     Def.ActorFrame {
  19.     Name = "BPMText",
  20.     InitCommand = function(self)
  21.         BPM = self:GetChild("BPM")
  22.         if (allowedCustomization) then
  23.             Movable.DeviceButton_x.element = self
  24.             Movable.DeviceButton_c.element = self
  25.             Movable.DeviceButton_x.condition = true
  26.             Movable.DeviceButton_c.condition = true
  27.             Movable.DeviceButton_x.Border = self:GetChild("Border")
  28.             Movable.DeviceButton_c.Border = self:GetChild("Border")
  29.         end
  30.         self:x(MovableValues.BPMTextX):y(MovableValues.BPMTextY):zoom(MovableValues.BPMTextZoom)
  31.         if #GAMESTATE:GetCurrentSong():GetTimingData():GetBPMs() > 1 then -- dont bother updating for single bpm files
  32.             self:SetUpdateFunction(UpdateBPM)
  33.             self:SetUpdateRate(0.5)
  34.             BPM:settextf("%4.1f BPM",GetBPS(a) * r)
  35.         else
  36.             BPM:settextf("%4.1f BPM", GetBPS(a) * r) -- i wasn't thinking when i did this, we don't need to avoid formatting for performance because we only call this once -mina
  37.         end
  38.     end,
  39.     LoadFont("Common Normal") ..
  40.         {
  41.             Name = "BPMText2",
  42.             InitCommand = function(self)
  43.                 self:halign(1):zoom(1)
  44.             end,
  45.             OnCommand = function(self)
  46.                 if allowedCustomization then
  47.                     setBorderToText(self:GetParent():GetChild("Border"), self)
  48.                 end
  49.             end
  50.         },
  51.     DoneLoadingNextSongMessageCommand = function(self)
  52.         self:queuecommand("Init")
  53.     end,
  54.     -- basically a copy of the init
  55.     CurrentRateChangedMessageCommand = function(self)
  56.         r = GAMESTATE:GetSongOptionsObject("ModsLevel_Current"):MusicRate() * 60
  57.         if #GAMESTATE:GetCurrentSong():GetTimingData():GetBPMs() > 1 then
  58.             self:SetUpdateFunction(UpdateBPM)
  59.             self:SetUpdateRate(0.5)
  60.             BPM:settextf("%4.1f BPM",GetBPS(a) * r)
  61.         else
  62.             BPM:settextf("%4.1f BPM", GetBPS(a) * r)
  63.         end
  64.     end,
  65.     PracticeModeReloadMessageCommand = function(self)
  66.         self:playcommand("CurrentRateChanged")
  67.     end,
  68.     MovableBorder(40, 13, 1, 0, 0)
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement