Changed GameColor functions to silently return a default color instead of a nil error if the part of the GameColor table they use doesn't exist.

This commit is contained in:
Kyzentun
2015-02-28 03:48:57 -07:00
parent d35933f1e5
commit caa7d12204
+17 -10
View File
@@ -129,10 +129,14 @@ function ColorDarkTone(c)
return { c[1]/2, c[2]/2, c[3]/2, c[4] } return { c[1]/2, c[2]/2, c[3]/2, c[4] }
end end
local pn_to_color_name= {[PLAYER_1]= "PLAYER_1", [PLAYER_2]= "PLAYER_2"}
local default_color= color("1,1,1,1")
function PlayerColor( pn ) function PlayerColor( pn )
if pn == PLAYER_1 then return GameColor.PlayerColors["PLAYER_1"] end if not GameColor or not GameColor.PlayerColors then
if pn == PLAYER_2 then return GameColor.PlayerColors["PLAYER_2"] end return default_color
return color("1,1,1,1") end
return GameColor.PlayerColors[pn_to_color_name[pn]] or default_color
end end
function PlayerScoreColor( pn ) function PlayerScoreColor( pn )
@@ -140,9 +144,9 @@ function PlayerScoreColor( pn )
end end
function PlayerDarkColor( pn ) function PlayerDarkColor( pn )
if pn == PLAYER_1 then return GameColor.PlayerDarkColors["PLAYER_1"] end if not GameColor then return default_color end
if pn == PLAYER_2 then return GameColor.PlayerDarkColors["PLAYER_2"] end if not GameColor.PlayerDarkColors then return PlayerColor(pn) end
return color("1,1,1,1") return GameColor.PlayerDarkColors[pn_to_color_name[pn]] or default_color
end end
local function GameColorDifficultyWrapper(diff) local function GameColorDifficultyWrapper(diff)
@@ -168,21 +172,24 @@ function StepsOrTrailToColor(StepsOrTrail)
return CustomDifficultyToColor( StepsOrTrailToCustomDifficulty(stepsOrTrail) ) return CustomDifficultyToColor( StepsOrTrailToCustomDifficulty(stepsOrTrail) )
end end
local stage_default= color("#000000")
function StageToColor( stage ) function StageToColor( stage )
return GameColor.Stage[stage] or color("#000000") if not GameColor or not GameColor.Stage then return stage_default end
return GameColor.Stage[stage] or stage_default
end end
function StageToStrokeColor( stage ) function StageToStrokeColor( stage )
local c = GameColor.Stage[stage] local c = StageToColor(stage)
return { c[1]/2, c[2]/2, c[3]/2, c[4] } return { c[1]/2, c[2]/2, c[3]/2, c[4] }
end end
function JudgmentLineToColor( i ) function JudgmentLineToColor( i )
return GameColor.Judgment[i] or color("#000000") if not GameColor or not GameColor.Judgment then return stage_default end
return GameColor.Judgment[i] or stage_default
end end
function JudgmentLineToStrokeColor( i ) function JudgmentLineToStrokeColor( i )
local c = GameColor.Judgment[i] local c = JudgmentLineToColor(i)
return { c[1]/2, c[2]/2, c[3]/2, c[4] } return { c[1]/2, c[2]/2, c[3]/2, c[4] }
end end