sphereofnoform

LA/RA/MA Ratio Toggle

Sep 16th, 2024 (edited)
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.81 KB | Source Code | 0 0
  1.     -- Boolean to check whether shift or alt/backslash is held
  2.     local shiftHeld = false
  3.     local altHeld = false
  4.  
  5.     t[#t+1] = Def.ActorFrame {
  6.         OnCommand = function(self)
  7.             SCREENMAN:GetTopScreen():AddInputCallback(function(event)
  8.                 -- Detect if first or repeated shift press
  9.                 local button = event.DeviceInput.button
  10.                 if button == "DeviceButton_left shift" or button == "DeviceButton_right shift" or button == "DeviceButton_tab" then
  11.                     if event.type == "InputEventType_FirstPress" or event.type == "InputEventType_Repeat" then
  12.                         if not shiftHeld then
  13.                             shiftHeld = true
  14.                             MESSAGEMAN:Broadcast("ShiftPressed")
  15.                         end
  16.                     elseif event.type == "InputEventType_Release" then
  17.                         if shiftHeld then
  18.                             shiftHeld = false
  19.                             MESSAGEMAN:Broadcast("ShiftReleased")
  20.                         end
  21.                     end
  22.                 elseif button == "DeviceButton_left alt" or button == "DeviceButton_right alt" or button == "DeviceButton_backslash" then
  23.                     if event.type == "InputEventType_FirstPress" or event.type == "InputEventType_Repeat" then
  24.                         if not altHeld then
  25.                             altHeld = true
  26.                             MESSAGEMAN:Broadcast("AltPressed")
  27.                         end
  28.                     elseif event.type == "InputEventType_Release" then
  29.                         if altHeld then
  30.                             altHeld = false
  31.                             MESSAGEMAN:Broadcast("AltReleased")
  32.                         end
  33.                     end
  34.                 end
  35.             end)
  36.         end
  37.     }
  38.  
  39.     -- Function for calculating RA and LA, returns the ratio of ridiculous to marvelous and ludicrous to ridiculous from offset plot in replay.
  40.     local function calculateRatios(score)
  41.         -- Get replay depending on whether custom windows were used or not
  42.         local replay = usingCustomWindows and REPLAYS:GetActiveReplay() or score:GetReplay()
  43.         replay:LoadAllData()
  44.         -- Offset and tap note vectors from replay
  45.         local offsetTable = replay:GetOffsetVector()
  46.         local typeTable = replay:GetTapNoteTypeVector()
  47.  
  48.         if not offsetTable or #offsetTable == 0 or not typeTable or #typeTable == 0 then
  49.             return -1, -1, -1
  50.         end
  51.  
  52.         -- Define judgement windows
  53.         local window = usingCustomWindows and getCurrentCustomWindowConfigJudgmentWindowTable() or {
  54.             TapNoteScore_W1 = 22.5 * ms.JudgeScalers[judge], -- j4 marv
  55.             TapNoteScore_W2 = 45 * ms.JudgeScalers[judge],   -- j4 perf
  56.             TapNoteScore_W3 = 90 * ms.JudgeScalers[judge],   -- j4 g
  57.         }
  58.         -- Define RA and LA thresholds
  59.         window["TapNoteScore_W0"] = window["TapNoteScore_W1"] / 2 -- ra threshold
  60.         window["TapNoteScore_W-1"] = window["TapNoteScore_W0"] / 2 -- la threshold
  61.  
  62.         local laThreshold = window["TapNoteScore_W-1"]
  63.         local raThreshold = window["TapNoteScore_W0"]
  64.         local marvThreshold = window["TapNoteScore_W1"] -- marv
  65.  
  66.         local ludic = 0
  67.         local ridicLA = 0
  68.         local ridic = 0
  69.         local marvRA = 0
  70.  
  71.         -- Iterate over offset table
  72.         for i, o in ipairs(offsetTable) do
  73.             -- Check if note is tap or hold
  74.             if typeTable[i] == "TapNoteType_Tap" or typeTable[i] == "TapNoteType_HoldHead" then
  75.                 local off = math.abs(o)
  76.                 if off <= raThreshold then
  77.                     ridic = ridic + 1
  78.                 elseif off <= marvThreshold then
  79.                     marvRA = marvRA + 1
  80.                 end
  81.                 if off <= laThreshold then
  82.                     ludic = ludic + 1
  83.                 elseif off <= raThreshold then
  84.                     ridicLA = ridicLA + 1
  85.                 end
  86.             end
  87.         end
  88.  
  89.         -- Return ratios, ridic count, and marv count
  90.         local ridiculousAttack = ridic / marvRA
  91.         local ludicrousAttack = ludic / ridicLA
  92.         return ridiculousAttack, ludicrousAttack, ridicLA, marvRA
  93.     end
  94.  
  95.     --[[
  96.     The following section first adds the ratioText, laRatio, raRatio, maRatio, and paRatio. Then the correct values are filled in.
  97.     When shift or alt/backslash is held, the display changes accordingly.
  98.     --]]
  99.     local ratioText, raRatio, laRatio, maRatio, paRatio, marvelousTaps, perfectTaps, greatTaps
  100.     t[#t+1] = Def.ActorFrame {
  101.         Name = "MAPARatioContainer",
  102.  
  103.         LoadFont("Common Large") .. {
  104.             Name = "Text",
  105.             InitCommand = function(self)
  106.                 ratioText = self
  107.                 self:settextf("%s:", translated_info["MAPARatio"])
  108.                 self:zoom(0.25):halign(1)
  109.             end
  110.         },
  111.         LoadFont("Common Large") .. {
  112.             Name = "LAText",
  113.             InitCommand = function(self)
  114.                 laRatio = self
  115.                 self:settextf("%.2f:1", 0)
  116.                 self:zoom(0.25):halign(1):rainbow() -- Rainbow cuz it's LA man come on
  117.                 self:visible(false)
  118.             end
  119.         },
  120.         LoadFont("Common Large") .. {
  121.             Name = "RAText",
  122.             InitCommand = function(self)
  123.                 raRatio = self
  124.                 self:settextf("%.2f:1", 0)
  125.                 self:zoom(0.25):halign(1)  -- No color, user can set whatever they want here. AAAAA is white so I left as white
  126.                 self:visible(false)
  127.             end
  128.         },
  129.         LoadFont("Common Large") .. {
  130.             Name = "MAText",
  131.             InitCommand = function(self)
  132.                 maRatio = self
  133.                 self:zoom(0.25):halign(1):diffuse(byJudgment(judges[1]))
  134.             end
  135.         },
  136.         LoadFont("Common Large") .. {
  137.             Name = "PAText",
  138.             InitCommand = function(self)
  139.                 paRatio = self
  140.                 self:xy(frameWidth + frameX, frameY + 210)
  141.                 self:zoom(0.25)
  142.                 self:halign(1)
  143.                 self:diffuse(byJudgment(judges[2]))
  144.  
  145.                 marvelousTaps = score:GetTapNoteScore(judges[1])
  146.                 perfectTaps = score:GetTapNoteScore(judges[2])
  147.                 greatTaps = score:GetTapNoteScore(judges[3])
  148.                 self:playcommand("Set")
  149.             end,
  150.             SetCommand = function(self)
  151.                 -- Fill in raRatio, laRatio, maRatio, and paRatio
  152.                 local ridiculousAttack, ludicrousAttack, ridics, marvs = calculateRatios(score)
  153.                 maRatio:settextf("%.1f:1", marvelousTaps / perfectTaps)
  154.                 paRatio:settextf("%.1f:1", perfectTaps / greatTaps)
  155.                 raRatio:settextf("%.2f:1", ridiculousAttack)
  156.                 laRatio:settextf("%.2f:1", ludicrousAttack)
  157.  
  158.                 -- Align with where paRatio was and move things accordingly
  159.                 if altHeld then
  160.                     -- Show LA/RA ratios
  161.                     laRatio:visible(true)
  162.                     raRatio:visible(true)
  163.                     maRatio:visible(false)
  164.                     paRatio:visible(false)
  165.  
  166.                     raRatio:settextf("%.2f:1", ridics / marvs) -- ridic:marv
  167.                     raRatio:xy(paRatio:GetX(), paRatio:GetY())
  168.                     local laRatioX = raRatio:GetX() - raRatio:GetZoomedWidth() - 10
  169.                     laRatio:xy(laRatioX, raRatio:GetY())
  170.                     local ratioTextX = laRatioX - laRatio:GetZoomedWidth() - 10
  171.                     ratioText:xy(ratioTextX, raRatio:GetY())
  172.  
  173.                     ratioText:settextf("LA/RA ratio:")
  174.                 elseif shiftHeld then
  175.                     -- Show RA/MA ratios
  176.                     raRatio:visible(true)
  177.                     laRatio:visible(false)
  178.                     maRatio:visible(true)
  179.                     paRatio:visible(false)
  180.  
  181.                     maRatio:settextf("%.1f:1", marvs / perfectTaps) -- marv:perf
  182.                     raRatio:xy(paRatio:GetX() - maRatio:GetZoomedWidth() - 10, paRatio:GetY())
  183.                     maRatio:xy(paRatio:GetX(), paRatio:GetY())
  184.                     local ratioTextX = raRatio:GetX() - raRatio:GetZoomedWidth() - 10
  185.                     ratioText:xy(ratioTextX, paRatio:GetY())
  186.  
  187.                     ratioText:settextf("RA/MA ratio:")
  188.                 else
  189.                     -- Show MA/PA ratios
  190.                     raRatio:visible(false)
  191.                     laRatio:visible(false)
  192.                     maRatio:visible(true)
  193.                     paRatio:visible(true)
  194.  
  195.                     maRatio:settextf("%.1f:1", marvelousTaps / perfectTaps) -- marv:perf
  196.                     local maRatioX = paRatio:GetX() - paRatio:GetZoomedWidth() - 10
  197.                     maRatio:xy(maRatioX, paRatio:GetY())
  198.                     local ratioTextX = maRatioX - maRatio:GetZoomedWidth() - 10
  199.                     ratioText:xy(ratioTextX, paRatio:GetY())
  200.  
  201.                     ratioText:settextf("%s:", translated_info["MAPARatio"])
  202.                 end
  203.  
  204.                 if score:GetChordCohesion() == true then
  205.                     maRatio:maxwidth(maRatio:GetZoomedWidth()/0.25)
  206.                     self:maxwidth(self:GetZoomedWidth()/0.25)
  207.                     ratioText:maxwidth(capWideScale(get43size(65), 85)/0.27)
  208.                 end
  209.             end,
  210.  
  211.             ShiftPressedMessageCommand = function(self)
  212.                 self:playcommand("Set")
  213.             end,
  214.             ShiftReleasedMessageCommand = function(self)
  215.                 self:playcommand("Set")
  216.             end,
  217.             AltPressedMessageCommand = function(self)
  218.                 self:playcommand("Set")
  219.             end,
  220.             AltReleasedMessageCommand = function(self)
  221.                 self:playcommand("Set")
  222.             end,
  223.  
  224.             CodeMessageCommand = function(self, params)
  225.                 if usingCustomWindows then
  226.                     return
  227.                 end
  228.  
  229.                 if params.Name == "PrevJudge" or params.Name == "NextJudge" then
  230.                     marvelousTaps = getRescoredJudge(dvt, judge, 1)
  231.                     perfectTaps = getRescoredJudge(dvt, judge, 2)
  232.                     greatTaps = getRescoredJudge(dvt, judge, 3)
  233.                     self:playcommand("Set")
  234.                 end
  235.                 if params.Name == "ResetJudge" then
  236.                     marvelousTaps = score:GetTapNoteScore(judges[1])
  237.                     perfectTaps = score:GetTapNoteScore(judges[2])
  238.                     greatTaps = score:GetTapNoteScore(judges[3])
  239.                     self:playcommand("Set")
  240.                 end
  241.             end,
  242.             ForceWindowMessageCommand = function(self)
  243.                 marvelousTaps = getRescoredJudge(dvt, judge, 1)
  244.                 perfectTaps = getRescoredJudge(dvt, judge, 2)
  245.                 greatTaps = getRescoredJudge(dvt, judge, 3)
  246.                 self:playcommand("Set")
  247.             end,
  248.             ScoreChangedMessageCommand = function(self)
  249.                 self:playcommand("ForceWindow")
  250.             end,
  251.             LoadedCustomWindowMessageCommand = function(self)
  252.                 marvelousTaps = lastSnapshot:GetJudgments()["W1"]
  253.                 perfectTaps = lastSnapshot:GetJudgments()["W2"]
  254.                 greatTaps = lastSnapshot:GetJudgments()["W3"]
  255.                 self:playcommand("Set")
  256.             end,
  257.         },
  258.     }
Advertisement
Add Comment
Please, Sign In to add comment