Tweaked Failure function, made case-correction code work

This commit is contained in:
Flameshadowxeroshin
2012-05-04 07:16:04 -05:00
parent 84eef100a6
commit 58669e616e
@@ -57,10 +57,11 @@ end
-- Tries to parse the file at path. If successful, returns a table of mods. -- Tries to parse the file at path. If successful, returns a table of mods.
-- If it can't open the file, it will write a fallback set of mods. -- If it can't open the file, it will write a fallback set of mods.
local function ParseSpeedModFile(path) local function ParseSpeedModFile(path)
local function Failure(file) local function Failure()
-- error; write a fallback mod file and return it -- error; write a fallback mod file and return it
local fallbackString = "0.5x,1x,1.5x,2x,3x,4x,5x,6x,7x,8x,C250,C450,m550" local fallbackString = "0.5x,1x,1.5x,2x,3x,4x,5x,6x,7x,8x,C250,C450,m550"
Trace("[CustomSpeedMods]: Could not read SpeedMods; writing fallback to "..path) Trace("[CustomSpeedMods]: Could not read SpeedMods; writing fallback to "..path)
local file = RageFileUtil.CreateRageFile()
file:Open(path, 2) file:Open(path, 2)
file:Write(fallbackString) file:Write(fallbackString)
file:destroy() file:destroy()
@@ -78,18 +79,17 @@ local function ParseSpeedModFile(path)
string.gsub(mods[i], "%s", "") string.gsub(mods[i], "%s", "")
if not(mods[i]:find("%d+.?%d*[xX]") or mods[i]:find("[cmCM]%d+")) then if not(mods[i]:find("%d+.?%d*[xX]") or mods[i]:find("[cmCM]%d+")) then
mods[i] = nil mods[i] = nil
--hack for those lazy with their capitalization elseif mods[i]:find("[mM]") then mods[i]=mods[i]:lower()
if mods[i]:find("[mM]") then mods[i]=mods[i]:lower() elseif mods[i]:find("[cC]") then mods[i]=mods[i]:upper() end
elseif mods[i]:find("[cC]") then mods[i]=mods[i]:upper() end
end
end end
if #mods==0 then return Failure(file) end if #mods==0 then file:destroy() return Failure() end
file:destroy() file:destroy()
return mods return mods
else else
return Failure(file) file:destroy()
return Failure()
end end
end end