#7 Lots of code cleanup and testing of other speedmodrow types. Everything seems...
authorCameron Ball <c.ball1729@gmail.com>
Mon, 9 Dec 2013 06:56:38 +0000 (14:56 +0800)
committerCameron Ball <c.ball1729@gmail.com>
Mon, 9 Dec 2013 06:56:38 +0000 (14:56 +0800)
Themes/GrooveNights/Scripts/SpeedMods.lua

index fc40eda..2c84c59 100644 (file)
@@ -1,5 +1,5 @@
 function GetRateMods()\r
-       return { "1.0x", "1.1x", "1.2x", "1.3x", "1.4x", "1.5x", "1.6x", "1.7x", "2.0x"}\r
+    return { "1.0x", "1.1x", "1.2x", "1.3x", "1.4x", "1.5x", "1.6x", "1.7x", "2.0x"}\r
 end\r
 \r
 function GetBaseSpeeds()\r
@@ -8,30 +8,30 @@ function GetBaseSpeeds()
     end\r
         \r
     if GetSpeedModRowType() == "advanced" then\r
-        if OPENITG then baseSpeed = { "0.25x", "0.5x", "0.75x", "1x", "1.25x", "1.5x", "1.75x", "2x", "2.25x", "2.5x", "2.75x", "3x", "3.25x", "3.5x", "3.75x", "4x", "4.25x", "4.5x", "4.75x", "5x", "5.25x", "5.5x", "5.75x", "6x", "6.25x", "6.5x", "6.75x", "7x", "c400", "c425", "c450", "c475", "c500", "c525", "c550", "c575", "c600", "c625", "c650", "c675", "c700", "c725", "c750", "c775", "c800", "c825", "c850", "c875", "c900", "c925", "c950", "c975", "c1000", "m400", "m425", "m450", "m475", "m500", "m525", "m550", "m575", "m600", "m625", "m650", "m675", "m700", "m725", "m750", "m775", "m800", "m825", "m850", "m875", "m900", "m925", "m950", "m975", "m1000" }\r
-        else baseSpeed = { "0.25x", "0.5x", "0.75x", "1x", "1.25x", "1.5x", "1.75x", "2x", "2.25x", "2.5x", "2.75x", "3x", "3.25x", "3.5x", "3.75x", "4x", "4.25x", "4.5x", "4.75x", "5x", "5.25x", "5.5x", "5.75x", "6x", "6.25x", "6.5x", "6.75x", "7x", "c400", "c425", "c450", "c475", "c500", "c525", "c550", "c575", "c600", "c625", "c650", "c675", "c700", "c725", "c750", "c775", "c800", "c825", "c850", "c875", "c900", "c925", "c950", "c975", "c1000" }\r
+        if OPENITG then return { "0.25x", "0.5x", "0.75x", "1x", "1.25x", "1.5x", "1.75x", "2x", "2.25x", "2.5x", "2.75x", "3x", "3.25x", "3.5x", "3.75x", "4x", "4.25x", "4.5x", "4.75x", "5x", "5.25x", "5.5x", "5.75x", "6x", "6.25x", "6.5x", "6.75x", "7x", "c400", "c425", "c450", "c475", "c500", "c525", "c550", "c575", "c600", "c625", "c650", "c675", "c700", "c725", "c750", "c775", "c800", "c825", "c850", "c875", "c900", "c925", "c950", "c975", "c1000", "m400", "m425", "m450", "m475", "m500", "m525", "m550", "m575", "m600", "m625", "m650", "m675", "m700", "m725", "m750", "m775", "m800", "m825", "m850", "m875", "m900", "m925", "m950", "m975", "m1000" }\r
+        else return { "0.25x", "0.5x", "0.75x", "1x", "1.25x", "1.5x", "1.75x", "2x", "2.25x", "2.5x", "2.75x", "3x", "3.25x", "3.5x", "3.75x", "4x", "4.25x", "4.5x", "4.75x", "5x", "5.25x", "5.5x", "5.75x", "6x", "6.25x", "6.5x", "6.75x", "7x", "c400", "c425", "c450", "c475", "c500", "c525", "c550", "c575", "c600", "c625", "c650", "c675", "c700", "c725", "c750", "c775", "c800", "c825", "c850", "c875", "c900", "c925", "c950", "c975", "c1000" }\r
         end\r
     end\r
 \r
     if GetSpeedModRowType() == "basic" then\r
-        if OPENITG then baseSpeed = { "1x", "1.5x", "2x", "2.5x", "3x", "3.5x", "4x", "4.5x", "5x", "6x", "c450", "m450" }\r
-        else baseSpeed = { "1x", "1.5x", "2x", "2.5x", "3x", "3.5x", "4x", "4.5x", "5x", "5.5x", "6x", "c450" }\r
+        if OPENITG then return { "1x", "1.5x", "2x", "2.5x", "3x", "3.5x", "4x", "4.5x", "5x", "6x", "c450", "m450" }\r
+        else return { "1x", "1.5x", "2x", "2.5x", "3x", "3.5x", "4x", "4.5x", "5x", "5.5x", "6x", "c450" }\r
         end\r
     end\r
 end   \r
 \r
 function GetExtraSpeeds()\r
-       if GetSpeedModRowType() == "pro" then \r
-               return { "0", "+0.25", "+0.5", "+0.75", "+0.1", "+0.2", "+0.3", "+0.4", "+0.6", "+0.7", "+0.8", "+0.9" }\r
-       end\r
-       \r
-       if GetSpeedModRowType() == "advanced" then\r
-               return { "0" }\r
-       end\r
-       \r
-       if GetSpeedModRowType() == "basic" then\r
-               return { "0" }\r
-       end\r
+    if GetSpeedModRowType() == "pro" then \r
+        return { "0", "+0.25", "+0.5", "+0.75", "+0.1", "+0.2", "+0.3", "+0.4", "+0.6", "+0.7", "+0.8", "+0.9" }\r
+    end\r
+\r
+    if GetSpeedModRowType() == "advanced" then\r
+        return { "0" }\r
+    end\r
+\r
+    if GetSpeedModRowType() == "basic" then\r
+        return { "0" }\r
+    end\r
 end\r
 \r
 function GetSpeedModTypes() \r
@@ -43,36 +43,36 @@ function GetSpeedModTypes()
 end\r
 \r
 function GetRateMod()\r
-       local RateMods = GetRateMods()\r
-       for n = 1, table.getn(RateMods) do\r
-               if GAMESTATE:PlayerIsUsingModifier(0, RateMods[n] .. 'music') or GAMESTATE:PlayerIsUsingModifier(1, RateMods[n] .. 'music') then\r
-                       return RateMods[n]\r
-               end\r
-       end\r
+    local RateMods = GetRateMods()\r
+    for n = 1, table.getn(RateMods) do\r
+        if GAMESTATE:PlayerIsUsingModifier(0, RateMods[n] .. 'music') or GAMESTATE:PlayerIsUsingModifier(1, RateMods[n] .. 'music') then\r
+            return RateMods[n]\r
+        end\r
+    end\r
 \r
-       return nil\r
+    return nil\r
 end\r
 \r
 function RateMods()\r
-       local modList = GetRateMods();\r
+    local modList = GetRateMods();\r
 \r
-       local function Load(self, list, pn)\r
-               for n = 1, table.getn(modList) do\r
-                       if GAMESTATE:PlayerIsUsingModifier(pn,modList[n]..'music') then list[n] = true else list[n] = false end\r
-               end\r
-       end\r
+    local function Load(self, list, pn)\r
+        for n = 1, table.getn(modList) do\r
+            if GAMESTATE:PlayerIsUsingModifier(pn,modList[n]..'music') then list[n] = true else list[n] = false end\r
+        end\r
+    end\r
 \r
-       local function Save(self, list, pn)\r
-               for n = 1, table.getn(modList) do\r
-                       if list[n] then\r
-                               GAMESTATE:ApplyGameCommand('mod,'..modList[n]..'music',pn)\r
-                               MESSAGEMAN:Broadcast('RateModChanged')\r
-                       end\r
-               end\r
-       end\r
+    local function Save(self, list, pn)\r
+        for n = 1, table.getn(modList) do\r
+            if list[n] then\r
+                GAMESTATE:ApplyGameCommand('mod,'..modList[n]..'music',pn)\r
+                MESSAGEMAN:Broadcast('RateModChanged')\r
+            end\r
+        end\r
+    end\r
 \r
-       local Params = { Name = "Rate" }\r
-       return CreateOptionRow( Params, modList, Load, Save )\r
+    local Params = { Name = "Rate" }\r
+    return CreateOptionRow( Params, modList, Load, Save )\r
 end\r
 \r
 function GetSpeedMod(pn)\r
@@ -88,61 +88,36 @@ function GetSpeedMod(pn)
                 local CombinedSpeeds = BaseSpeeds[n] + string.gsub(ExtraSpeeds[m], 'x', '') --combines the speeds in to things like 4.50\r
 \r
                 --check x-mods\r
-                Trace('GetSpeedMod: Checking ' .. CombinedSpeeds .. 'x')\r
-                if GAMESTATE:PlayerIsUsingModifier(pn, CombinedSpeeds .. 'x') then\r
-                    Trace("GetSpeedMod: Hit!")\r
-                    return CombinedSpeeds .. 'x'\r
-                end\r
-                       end\r
-       end  \r
-    end\r
-       \r
-       for n = 1, table.getn(BaseSpeeds) do\r
-               if GetSpeedModRowType() == "basic" or GetSpeedModRowType() == "advanced" then\r
-            if GAMESTATE:PlayerIsUsingModifier(pn, BaseSpeeds[n]) then return BaseSpeeds[n] end\r
-        end\r
+                if GAMESTATE:PlayerIsUsingModifier(pn, CombinedSpeeds .. 'x') then return CombinedSpeeds .. 'x' end\r
        \r
-               for m = 1, table.getn(ExtraSpeeds) do\r
-                       local CombinedSpeeds = BaseSpeeds[n] + string.gsub(ExtraSpeeds[m], 'x', '') --combines the speeds in to things like 4.50\r
-               \r
-                       --check c-mods\r
-                       Trace('GetSpeedMod: Checking ' .. 'c' .. CombinedSpeeds*100)\r
-                       if GAMESTATE:PlayerIsUsingModifier(pn, 'c' .. CombinedSpeeds*100) then \r
-                               Trace('GetSpeedMod: Hit!')\r
-                               return 'c' .. CombinedSpeeds*100\r
-                       end\r
-               end\r
+                --check c-mods\r
+                if GAMESTATE:PlayerIsUsingModifier(pn, 'c' .. CombinedSpeeds*100) then return 'c' .. CombinedSpeeds*100 end\r
+            end\r
        end\r
-       \r
-       for n = 1, table.getn(BaseSpeeds) do\r
-               if GetSpeedModRowType() == "basic" or GetSpeedModRowType() == "advanced" then\r
-            if GAMESTATE:PlayerIsUsingModifier(pn, BaseSpeeds[n]) then return BaseSpeeds[n] end\r
-        end\r
+    end\r
 \r
-               for m = 1, table.getn(ExtraSpeeds) do\r
-                       local CombinedSpeeds = BaseSpeeds[n] + string.gsub(ExtraSpeeds[m], 'x', '') --combines the speeds in to things like 4.50                        \r
-                       \r
-                       --check m-mods (for some reason m0 is always applied, so skip it)\r
-                       Trace('GetSpeedMod: Checking ' .. 'm' .. CombinedSpeeds*100)\r
-                       if GAMESTATE:PlayerIsUsingModifier(pn, 'm' .. CombinedSpeeds*100) then \r
-                               Trace('GetSpeedMod: Hit!')\r
-                               return 'm' .. CombinedSpeeds*100\r
-                       end\r
-               end\r
-       end\r
+    -- M-Mods need to be checked last, as when the game starts m0 is always applied (even if a different default modifier has been chosen)\r
+    for n = 1, table.getn(BaseSpeeds) do\r
+        if GetSpeedModRowType() == "pro" then\r
+            for m = 1, table.getn(ExtraSpeeds) do\r
+                local CombinedSpeeds = BaseSpeeds[n] + string.gsub(ExtraSpeeds[m], 'x', '') --combines the speeds in to things like 4.50                       \r
+\r
+                if GAMESTATE:PlayerIsUsingModifier(pn, 'm' .. CombinedSpeeds*100) then return 'm' .. CombinedSpeeds*100 end\r
+            end\r
+        end\r
+    end\r
        \r
-       return nil\r
+    return nil\r
 end\r
 \r
 function GetSpeedModBase(pn)\r
     local SpeedMod = GetSpeedMod(pn)\r
     SpeedMod = string.gsub(SpeedMod, 'c', '')\r
     SpeedMod = string.gsub(SpeedMod, 'm', '')\r
-       SpeedMod = string.gsub(SpeedMod, 'x', '')\r
+    SpeedMod = string.gsub(SpeedMod, 'x', '')\r
        \r
-       if GetSpeedModType(pn) == 'c-mod' or GetSpeedModType(pn) == 'm-mod' then SpeedMod = SpeedMod/100 end\r
+    if GetSpeedModType(pn) == 'c-mod' or GetSpeedModType(pn) == 'm-mod' then SpeedMod = SpeedMod/100 end\r
        \r
-       Trace("GetSpeedModBase: The SpeedMod is " .. SpeedMod .. " returning " .. math.floor(SpeedMod) .. " as the base.")\r
     return tostring(math.floor(SpeedMod)) -- Consistency: all the others return a string due to concatenation or w/e\r
 end\r
 \r
@@ -150,35 +125,27 @@ function GetSpeedModExtra(pn)
     local SpeedMod = GetSpeedMod(pn)\r
     SpeedMod = string.gsub(SpeedMod, 'c', '')\r
     SpeedMod = string.gsub(SpeedMod, 'm', '')\r
-       SpeedMod = string.gsub(SpeedMod, 'x', '')\r
+    SpeedMod = string.gsub(SpeedMod, 'x', '')\r
        \r
-       if GetSpeedModType(pn) == 'c-mod' or GetSpeedModType(pn) == 'm-mod' then SpeedMod = SpeedMod/100 end\r
+    if GetSpeedModType(pn) == 'c-mod' or GetSpeedModType(pn) == 'm-mod' then SpeedMod = SpeedMod/100 end\r
 \r
-       Trace("GetSpeedModExtra: The SpeedMod is " .. SpeedMod .. " returning " .. '+' .. SpeedMod - math.floor(SpeedMod) .. " as extra.")\r
     return '+' .. SpeedMod - math.floor(SpeedMod)\r
 end\r
 \r
 function GetSpeedModType(pn)\r
     local SpeedMod = GetSpeedMod(pn)\r
 \r
-    if string.find(SpeedMod, "x") ~= nil then Trace("GetSpeedModType: Returning " .. "x-mod"); return 'x-mod' end\r
-    if string.find(SpeedMod, "c") ~= nil then Trace("GetSpeedModType: Returning " .. "c-mod"); return 'c-mod' end\r
-    if string.find(SpeedMod, "m") ~= nil then Trace("GetSpeedModType: Returning " .. "m-mod"); return 'm-mod' end\r
+    if string.find(SpeedMod, "x") ~= nil then return 'x-mod' end\r
+    if string.find(SpeedMod, "c") ~= nil then return 'c-mod' end\r
+    if string.find(SpeedMod, "m") ~= nil then return 'm-mod' end\r
 end\r
 \r
 function SpeedMods(name)\r
     local modList = GetBaseSpeeds()\r
     local s = "Speed"\r
 \r
-    if name == "Extra" then\r
-        modList = GetExtraSpeeds()\r
-        s = "Extra " .. s\r
-    end\r
-\r
-    if name == "Type" then\r
-        modList = GetSpeedModTypes()\r
-        s = s .. " Type"\r
-    end\r
+    if name == "Extra" then modList = GetExtraSpeeds() s = "Extra " .. s end\r
+    if name == "Type" then modList = GetSpeedModTypes() s = s .. " Type" end\r
 \r
     local Params = { Name = s, OneChoiceForAllPlayers = false }   \r
 \r
@@ -188,34 +155,17 @@ function SpeedMods(name)
 \r
         -- now loop through everything else in the list and see if it is set to true\r
         for i=2, table.getn(modList) do\r
-                if name == "Base" then\r
-                    if modList[i] == GetSpeedModBase(pn) then\r
-                        list[i] = true\r
-                        list[1] = false\r
-                    else\r
-                        list[i] = false\r
-                    end\r
-                end\r
-\r
-                               \r
-                if name == "Extra" then\r
-                    if string.gsub(modList[i], 'x', '') == GetSpeedModExtra(pn) then\r
-                        list[i] = true\r
-                        list[1] = false\r
-                    else\r
-                        list[i] = false\r
-                    end\r
-                end\r
-                               \r
-                if name == "Type" then                         \r
-                                       Trace("Comparing " .. modList[i] .. " with " .. GetSpeedModType(pn))\r
-                    if modList[i] == GetSpeedModType(pn) then\r
-                        list[i] = true\r
-                        list[1] = false\r
-                    else\r
-                        list[i] = false\r
-                    end\r
-                end\r
+            if name == "Base" then\r
+                if modList[i] == GetSpeedModBase(pn) then list[i] = true; list[1] = false else list[i] = false end\r
+            end\r
+\r
+            if name == "Extra" then\r
+                if string.gsub(modList[i], 'x', '') == GetSpeedModExtra(pn) then list[i] = true; list[1] = false else list[i] = false end\r
+            end\r
+\r
+            if name == "Type" then                             \r
+                if modList[i] == GetSpeedModType(pn) then list[i] = true; list[1] = false else list[i] = false end\r
+            end\r
         end\r
     end\r
 \r
@@ -224,8 +174,6 @@ function SpeedMods(name)
         local ModBase = GetSpeedModBase(pn)\r
         local ModExtra = GetSpeedModExtra(pn)\r
         local ModType = GetSpeedModType(pn)\r
-               \r
-               Trace("SpeedMods: about to save. SpeedMod is " .. SpeedMod .. " ModBase is " .. ModBase .. " ModExtra is " .. ModExtra .. " ModType us " .. ModType)\r
 \r
         for i = 1, table.getn(modList) do\r
             if list[i] then\r
@@ -234,27 +182,28 @@ function SpeedMods(name)
                 if name == "Type" then ModType = modList[i] end\r
             end\r
         end\r
-               \r
-               Trace("SpeedMods: Did the for loop. SpeedMod is " .. SpeedMod .. " ModBase is " .. ModBase .. " ModExtra is " .. ModExtra .. " ModType us " .. ModType)\r
                        \r
-        SpeedMod = ModBase + ModExtra;\r
-               \r
-        if ModType == 'c-mod' then SpeedMod = 'c' .. SpeedMod*100 end\r
-        if ModType == 'm-mod' then SpeedMod = 'm' .. SpeedMod*100 end\r
-        if ModType == 'x-mod' then SpeedMod = SpeedMod .. 'x' end      \r
-          \r
-               Trace("SpeedMods: About to apply " .. SpeedMod)\r
+        if GetSpeedModRowType() ~= "pro" then\r
+            GAMESTATE:ApplyGameCommand('mod,' .. ModBase, pn+1)\r
+            MESSAGEMAN:Broadcast('SpeedModChanged')\r
+        else\r
+            SpeedMod = ModBase + ModExtra\r
                \r
-               --[[ This is the most retarded thing. For some reason when you apply an M-Mod or an X-Mod you can\r
-               get these weird situations where GAMESTATE:PlayerIsUsingModifier will tell you that there is an M and\r
-               an X mod in use. Therefore GetSpeedMod often returns the wrong speed mod (this seems to happen most when\r
-               you choose 0x or m0 and then try change the mod type). This is a silly fix that checks what the mod being\r
-               set is, then set the other one (IE if we're setting X, then change M) to a value outside of where GetSpeedMod\r
-               will ever look ]]--\r
-               if ModType == 'm-mod' then GAMESTATE:ApplyGameCommand('mod,99x',pn+1) end --quick fix. Need to make it go just one higher than the highest possible according to GetSpeeds\r
-               if ModType == 'x-mod' then GAMESTATE:ApplyGameCommand('mod,m9999',pn+1) end --quick fix. Need to make it go just one higher than the highest possible according to GetSpeeds\r
-        GAMESTATE:ApplyGameCommand('mod,'..SpeedMod,pn+1) --this is so annoying, the player number has to be 1 or 2 for ApplyGameCommand\r
-        MESSAGEMAN:Broadcast('SpeedModChanged')\r
+            if ModType == 'c-mod' then SpeedMod = 'c' .. SpeedMod*100 end\r
+            if ModType == 'm-mod' then SpeedMod = 'm' .. SpeedMod*100 end\r
+            if ModType == 'x-mod' then SpeedMod = SpeedMod .. 'x' end      \r
+\r
+            --[[ This is the most retarded thing. For some reason when you apply an M-Mod or an X-Mod you can\r
+            get these weird situations where GAMESTATE:PlayerIsUsingModifier will tell you that there is an M and\r
+            an X mod in use. Therefore GetSpeedMod often returns the wrong speed mod (this seems to happen most when\r
+            you choose 0x or m0 and then try change the mod type). This is a silly fix that checks what the mod being\r
+            set is, then set the other one (IE if we're setting X, then change M) to a value outside of where GetSpeedMod\r
+            will ever look ]]--\r
+            if ModType == 'm-mod' then GAMESTATE:ApplyGameCommand('mod,9999x',pn+1) end\r
+            if ModType == 'x-mod' then GAMESTATE:ApplyGameCommand('mod,m9999',pn+1) end\r
+            GAMESTATE:ApplyGameCommand('mod,'..SpeedMod,pn+1) --this is so annoying, the player number has to be 1 or 2 for ApplyGameCommand\r
+            MESSAGEMAN:Broadcast('SpeedModChanged')\r
+        end\r
     end\r
 \r
     return CreateOptionRow( Params, modList, Load, Save )\r