From bf4a10ce7b12bddd0d0ca16b5378adde7ae052fd Mon Sep 17 00:00:00 2001 From: Colby Klein Date: Thu, 18 Aug 2011 11:35:14 -0700 Subject: [PATCH] Cleanup, part 2 (working on fallback) --- Themes/_fallback/Scripts/00 init.lua | 4 +- Themes/_fallback/Scripts/01 alias.lua | 2 +- Themes/_fallback/Scripts/01 base.lua | 18 ++---- Themes/_fallback/Scripts/01 compat.lua | 50 ++-------------- Themes/_fallback/Scripts/02 Actor.lua | 50 ++++++++-------- Themes/_fallback/Scripts/02 Branches.lua | 26 ++++----- Themes/_fallback/Scripts/02 Colors.lua | 20 +++---- Themes/_fallback/Scripts/02 Other.lua | 70 ++++++++++++----------- Themes/_fallback/Scripts/02 Sprite.lua | 8 +-- Themes/_fallback/Scripts/02 StageMods.lua | 35 +++++------- 10 files changed, 118 insertions(+), 165 deletions(-) diff --git a/Themes/_fallback/Scripts/00 init.lua b/Themes/_fallback/Scripts/00 init.lua index ed8bded4f4..33c3105106 100644 --- a/Themes/_fallback/Scripts/00 init.lua +++ b/Themes/_fallback/Scripts/00 init.lua @@ -16,10 +16,10 @@ PLAYER_1 = "PlayerNumber_P1" PLAYER_2 = "PlayerNumber_P2" NUM_PLAYERS = #PlayerNumber -function string:find_last( text ) +function string:find_last(text) local LastPos = 0 while true do - local p = string.find( self, text, LastPos+1, true ) + local p = string.find(self, text, LastPos+1, true) if not p then return LastPos end diff --git a/Themes/_fallback/Scripts/01 alias.lua b/Themes/_fallback/Scripts/01 alias.lua index 05935425bf..126d9c69ef 100644 --- a/Themes/_fallback/Scripts/01 alias.lua +++ b/Themes/_fallback/Scripts/01 alias.lua @@ -20,4 +20,4 @@ local _screen = { h = SCREEN_HEIGHT, cx = SCREEN_CENTER_X, cy = SCREEN_CENTER_Y -} \ No newline at end of file +} diff --git a/Themes/_fallback/Scripts/01 base.lua b/Themes/_fallback/Scripts/01 base.lua index 0cad9786b4..942a442b8a 100644 --- a/Themes/_fallback/Scripts/01 base.lua +++ b/Themes/_fallback/Scripts/01 base.lua @@ -1,35 +1,27 @@ -- Override Lua's loadfile to use lua.ReadFile. function loadfile(file) - local data, err = lua.ReadFile(file); + local data, err = lua.ReadFile(file) if not data then return nil, ("what " .. file) end - local chunk, err = load( - function() - local ret = data - data = nil - return ret - end, - "@" .. file ); + local chunk, err = load(data, "@" .. file) if not chunk then return nil, err end -- Set the environment, like loadfile does. - setfenv( chunk, getfenv(2) ); + setfenv(chunk, getfenv(2)) return chunk end -- Override Lua's dofile to use our loadfile. function dofile(file) if not file then - error( "dofile(nil) unsupported", 2 ); + error( "dofile(nil) unsupported", 2 ) end - local chunk, err = loadfile(file) if not chunk then - error( err, 2 ); + error(err, 2) end - return chunk end diff --git a/Themes/_fallback/Scripts/01 compat.lua b/Themes/_fallback/Scripts/01 compat.lua index 4103cc9dbc..422324ad13 100644 --- a/Themes/_fallback/Scripts/01 compat.lua +++ b/Themes/_fallback/Scripts/01 compat.lua @@ -9,52 +9,14 @@ function Actor:hidden(bHide) self:visible(not bHide) end --- for when horizalign and vertalign get killed by glenn: ---[[ -function Actor:horizalign(v) - local values = { - left = 0, - center = 0.5, - right = 1 - } - self:halign(values[v]) -end - -function Actor:vertalign(v) - local values = { - top = 0, - middle = 0.5, - bottom = 1 - } - self:valign(values[v]) -end ---]] - --[[ ActorScroller: all of these got renamed, so alias the lowercase ones if things are going to look for them. ]] -function ActorScroller:getsecondtodestination() - self:GetSecondsToDestination() -end - -function ActorScroller:setsecondsperitem(secs) - self:SetSecondsPerItem(secs) -end - -function ActorScroller:setnumsubdivisions(subs) - self:SetNumSubdivisions(subs) -end - -function ActorScroller:scrollthroughallitems() - self:ScrollThroughAllItems() -end - -function ActorScroller:scrollwithpadding(fPadStart,fPadEnd) - self:ScrollWithPadding(fPadStart,fPadEnd) -end - -function ActorScroller:setfastcatchup(bFastCatchup) - self:SetFastCatchup(bFastCatchup) -end +ActorScroller.getsecondtodestination = ActorScroller.GetSecondsToDestination +ActorScroller.setsecondsperitem = ActorScroller.SetSecondsPerItem +ActorScroller.setnumsubdivisions = ActorScroller.SetNumSubdivisions +ActorScroller.scrollthroughallitems = ActorScroller.ScrollThroughAllItems +ActorScroller.scrollwithpadding = ActorScroller.ScrollWithPadding +ActorScroller.setfastcatchup = ActorScroller.SetFastCatchup --[[ GameState ]] --Aliases for old GAMESTATE timing functions. diff --git a/Themes/_fallback/Scripts/02 Actor.lua b/Themes/_fallback/Scripts/02 Actor.lua index 5736536221..52fc579c7a 100644 --- a/Themes/_fallback/Scripts/02 Actor.lua +++ b/Themes/_fallback/Scripts/02 Actor.lua @@ -1,29 +1,29 @@ -- Convenience aliases: -left = "HorizAlign_Left"; -center = "HorizAlign_Center"; -right = "HorizAlign_Right"; -top = "VertAlign_Top"; -middle = "VertAlign_Middle"; -bottom = "VertAlign_Bottom"; +left = "HorizAlign_Left" +center = "HorizAlign_Center" +right = "HorizAlign_Right" +top = "VertAlign_Top" +middle = "VertAlign_Middle" +bottom = "VertAlign_Bottom" function Actor:ease(t, fEase) -- Optimizations: -- fEase = -100 is equivalent to TweenType_Accelerate. if fEase == -100 then - self:accelerate(t); - return; + self:accelerate(t) + return end -- fEase = 0 is equivalent to TweenType_Linear. if fEase == 0 then - self:linear(t); - return; + self:linear(t) + return end -- fEase = +100 is equivalent to TweenType_Decelerate. if fEase == 100 then - self:decelerate(t); - return; + self:decelerate(t) + return end self:tween( t, "TweenType_Bezier", @@ -33,7 +33,7 @@ function Actor:ease(t, fEase) scale(fEase, -100, 100, 1/3, 3/3), 1 } - ); + ) end -- Notes On Beziers -- -- They can be 1D ( Quadratic ) or 2D ( Bezier ) @@ -51,7 +51,7 @@ local BounceBeginBezier = 1, 1 } function Actor:bouncebegin(t) - self:tween( t, "TweenType_Bezier", BounceBeginBezier ); + self:tween( t, "TweenType_Bezier", BounceBeginBezier ) end local BounceEndBezier = @@ -62,7 +62,7 @@ local BounceEndBezier = 1, 1 } function Actor:bounceend(t) - self:tween( t, "TweenType_Bezier", BounceEndBezier ); + self:tween( t, "TweenType_Bezier", BounceEndBezier ) end local SmoothBezier = @@ -70,7 +70,7 @@ local SmoothBezier = 0, 0, 1, 1 } function Actor:smooth(t) - self:tween( t, "TweenType_Bezier", SmoothBezier ); + self:tween( t, "TweenType_Bezier", SmoothBezier ) end -- SSC Additions local DropBezier = @@ -81,7 +81,7 @@ local DropBezier = 1 , 1, } function Actor:drop(t) - self:tween( t, "TweenType_Bezier", DropBezier ); + self:tween( t, "TweenType_Bezier", DropBezier ) end -- compound tweens "combine multiple interpolators to allow generating more @@ -133,9 +133,9 @@ function Actor:player(p) end function ActorFrame:propagatecommand(...) - self:propagate(1); - self:playcommand(...); - self:propagate(0); + self:propagate(1) + self:playcommand(...) + self:propagate(0) end -- Shortcut for alignment. @@ -143,12 +143,12 @@ end -- cmd(align,0.0,0.0) -- align top-left -- cmd(align,0.5,0.0) -- align top-center function Actor:align(h, v) - self:halign( h ); - self:valign( v ); + self:halign( h ) + self:valign( v ) end function Actor:FullScreen() - self:stretchto( 0,0,SCREEN_WIDTH,SCREEN_HEIGHT ); + self:stretchto( 0,0,SCREEN_WIDTH,SCREEN_HEIGHT ) end --[[ Typical background sizes: @@ -166,10 +166,10 @@ function Actor:scale_or_crop_background() if graphicAspect == displayAspect then -- bga matches the current aspect, we can stretch it. - self:stretchto( 0,0,SCREEN_WIDTH,SCREEN_HEIGHT ); + self:stretchto( 0,0,SCREEN_WIDTH,SCREEN_HEIGHT ) else -- temp - self:scaletocover( 0,0,SCREEN_WIDTH,SCREEN_HEIGHT ); + self:scaletocover( 0,0,SCREEN_WIDTH,SCREEN_HEIGHT ) --[[ -- bga doesn't match the aspect. if displayAspect > graphicAspect then diff --git a/Themes/_fallback/Scripts/02 Branches.lua b/Themes/_fallback/Scripts/02 Branches.lua index 3f89ca77da..1a68631282 100644 --- a/Themes/_fallback/Scripts/02 Branches.lua +++ b/Themes/_fallback/Scripts/02 Branches.lua @@ -18,7 +18,7 @@ end function SelectMusicOrCourse() if IsNetSMOnline() then - return "ScreenNetSelectMusic"; + return "ScreenNetSelectMusic" elseif GAMESTATE:IsCourseMode() then return "ScreenSelectCourse" else @@ -28,7 +28,7 @@ end -- functions used for Routine mode function IsRoutine() - return GAMESTATE:GetCurrentStyle() and GAMESTATE:GetCurrentStyle():GetStyleType() == "StyleType_TwoPlayersSharedSides"; + return GAMESTATE:GetCurrentStyle() and GAMESTATE:GetCurrentStyle():GetStyleType() == "StyleType_TwoPlayersSharedSides" end Branch = { @@ -63,20 +63,20 @@ Branch = { -- a possibility someone will use their existing StepMania simfile -- collection with sm-ssc via AdditionalFolders/AdditionalSongFolders. if SONGMAN:GetNumSongs() == 0 and SONGMAN:GetNumAdditionalSongs() == 0 then - return "ScreenHowToInstallSongs"; - end; + return "ScreenHowToInstallSongs" + end if PROFILEMAN:GetNumLocalProfiles() >= 2 then - return "ScreenSelectProfile"; + return "ScreenSelectProfile" else - return "ScreenProfileLoad"; + return "ScreenProfileLoad" end end, OptionsEdit = function() -- Similar to above, don't let anyone in here with 0 songs. if SONGMAN:GetNumSongs() == 0 and SONGMAN:GetNumAdditionalSongs() == 0 then - return "ScreenHowToInstallSongs"; - end; - return "ScreenOptionsEdit"; + return "ScreenHowToInstallSongs" + end + return "ScreenOptionsEdit" end, AfterProfileLoad = function() return Branch.AfterSelectProfile() @@ -147,17 +147,17 @@ Branch = { local pm = GAMESTATE:GetPlayMode() local restricted = { "PlayMode_Oni", "PlayMode_Rave", --"PlayMode_Battle" -- ?? - }; + } local optionsScreen = "ScreenPlayerOptions" for i=1,#restricted do if restricted[i] == pm then optionsScreen = "ScreenPlayerOptionsRestricted" - end; + end end if SCREENMAN:GetTopScreen():GetGoToOptions() then - return optionsScreen; + return optionsScreen else - return "ScreenStageInformation"; + return "ScreenStageInformation" end end, SongOptions = function() diff --git a/Themes/_fallback/Scripts/02 Colors.lua b/Themes/_fallback/Scripts/02 Colors.lua index b46d9c5fe5..15127adaba 100644 --- a/Themes/_fallback/Scripts/02 Colors.lua +++ b/Themes/_fallback/Scripts/02 Colors.lua @@ -25,9 +25,8 @@ Color = { Saturation(hInput) Alpha(hInput) HSV(iHue,fSaturation,fValue or any other overload) --]] - Alpha = function(cColor,fAlpha) - local c = cColor; - return { c[1],c[2],c[3],fAlpha }; + Alpha = function(c, fAlpha) + return { c[1],c[2],c[3], fAlpha } end } @@ -38,8 +37,8 @@ setmetatable(Color, { __call = function(self, c) return self[c] end }) GameColor = { PlayerColors = { - PLAYER_1 = color("#ef403d"), - PLAYER_2 = color("#0089cf"), + PLAYER_1 = color("#ef403d"), + PLAYER_2 = color("#0089cf"), }, Difficulty = { --[[ These are for 'Custom' Difficulty Ranks. It can be very useful @@ -91,11 +90,12 @@ GameColor = { JudgmentLine_Miss = color("#ff3c3c"), JudgmentLine_MaxCombo = color("#ffc600") }, -}; -GameColor.Difficulty["Crazy"] = GameColor.Difficulty["Hard"]; -GameColor.Difficulty["Freestyle"] = GameColor.Difficulty["Easy"]; -GameColor.Difficulty["Nightmare"] = GameColor.Difficulty["Challenge"]; -GameColor.Difficulty["HalfDouble"] = GameColor.Difficulty["Medium"]; +} + +GameColor.Difficulty["Crazy"] = GameColor.Difficulty["Hard"] +GameColor.Difficulty["Freestyle"] = GameColor.Difficulty["Easy"] +GameColor.Difficulty["Nightmare"] = GameColor.Difficulty["Challenge"] +GameColor.Difficulty["HalfDouble"] = GameColor.Difficulty["Medium"] --[[ Fallbacks ]] function BoostColor( cColor, fBoost ) diff --git a/Themes/_fallback/Scripts/02 Other.lua b/Themes/_fallback/Scripts/02 Other.lua index 91f81f06e1..da02a7f26e 100644 --- a/Themes/_fallback/Scripts/02 Other.lua +++ b/Themes/_fallback/Scripts/02 Other.lua @@ -8,37 +8,37 @@ function LoadFallbackB() -- The fallback metrics group and element name will come either from LuaThreadVars -- (loading from C++) or from the Lua globals above (loading from Lua). - --Warn( "g_element " .. (g_element or "") ); - --Warn( "MatchingElement " .. (Var 'MatchingElement' or "") ); - --Warn( "g_metrics_group " .. (g_metrics_group or "") ); - --Warn( "MatchingMetricsGroup " .. (Var 'MatchingMetricsGroup' or "") ); + --Warn( "g_element " .. (g_element or "") ) + --Warn( "MatchingElement " .. (Var 'MatchingElement' or "") ) + --Warn( "g_metrics_group " .. (g_metrics_group or "") ) + --Warn( "MatchingMetricsGroup " .. (Var 'MatchingMetricsGroup' or "") ) - local metrics_group = g_metrics_group or Var 'MatchingMetricsGroup'; - local element = g_element or Var 'MatchingElement'; - local fallback = THEME:GetMetric(metrics_group,'Fallback'); + local metrics_group = g_metrics_group or Var 'MatchingMetricsGroup' + local element = g_element or Var 'MatchingElement' + local fallback = THEME:GetMetric(metrics_group,'Fallback') - local old_metrics_group = g_metrics_group; - local old_element = g_element; + local old_metrics_group = g_metrics_group + local old_element = g_element - local path; - path, g_metrics_group, g_element = THEME:GetPathInfoB(fallback,element); - --Trace('path ' .. path ); - local t = LoadActor( path ); + local path + path, g_metrics_group, g_element = THEME:GetPathInfoB(fallback,element) + --Trace('path ' .. path ) + local t = LoadActor( path ) - g_metrics_group = old_metrics_group; - g_element = old_element; + g_metrics_group = old_metrics_group + g_element = old_element - return t; + return t end function FormatNumSongsPlayed( num ) - local s = num..' song'; + local s = num..' song' if s == 1 then - s = s .. ' '; + s = s .. ' ' else - s = s .. 's'; + s = s .. 's' end - return s..' played'; + return s..' played' end function JudgmentTransformCommand( self, params ) @@ -87,7 +87,7 @@ function GetEditModeSubScreens() "ScreenMiniMenuInsertTapAttack," .. "ScreenMiniMenuInsertCourseAttack," .. "ScreenMiniMenuCourseDisplay," .. - "ScreenEditOptions"; + "ScreenEditOptions" end function GetCoursesToShowRanking() @@ -105,24 +105,30 @@ end ScreenMetric = Screen.Metric Screen.String = function ( sName ) - local sClass = Var "LoadingScreen"; + local sClass = Var "LoadingScreen" return THEME:GetString( sClass, sName ) end ScreenString = Screen.String function TextBannerAfterSet(self,param) - local Title=self:GetChild("Title"); - local Subtitle=self:GetChild("Subtitle"); - --local Artist=self:GetChild("Artist"); + local Title=self:GetChild("Title") + local Subtitle=self:GetChild("Subtitle") + if Subtitle:GetText() == "" then - (cmd(maxwidth,208;y,0;zoom,1.0;))(Title); - (cmd(visible,false))(Subtitle); - --(cmd(zoom,0.66;maxwidth,300;y,7))(Artist); + Title:maxwidth(208) + Title:y(0) + Title:zoom(1) + + Subtitle:visible(false) else - -- subtitle below - (cmd(zoom,1;y,-6;zoom,0.9;))(Title); - (cmd(visible,true;zoom,0.6;y,7))(Subtitle); - --(cmd(zoom,0.66;maxwidth,300;y,9))(Artist); + Title:zoom(1) + Title:y(-6) + Title:zoom(0.9) + + -- subtitle below title + Subtitle:visible(true) + Subtitle:zoom(0.6) + Subtitle:y(7) end end diff --git a/Themes/_fallback/Scripts/02 Sprite.lua b/Themes/_fallback/Scripts/02 Sprite.lua index 3c340f4795..bb931eb67a 100644 --- a/Themes/_fallback/Scripts/02 Sprite.lua +++ b/Themes/_fallback/Scripts/02 Sprite.lua @@ -28,18 +28,18 @@ function LoadSongBackground() end function Sprite:LoadFromCurrentSongBackground() - local song = GAMESTATE:GetCurrentSong(); + local song = GAMESTATE:GetCurrentSong() if not song then - local trail = GAMESTATE:GetCurrentTrail(GAMESTATE:GetMasterPlayerNumber()); + local trail = GAMESTATE:GetCurrentTrail(GAMESTATE:GetMasterPlayerNumber()) local e = trail:GetTrailEntries() if #e > 0 then - song = e[1]:GetSong(); + song = e[1]:GetSong() end end if not song then return end - self:LoadFromSongBackground(song); + self:LoadFromSongBackground(song) end function Sprite:position( f ) diff --git a/Themes/_fallback/Scripts/02 StageMods.lua b/Themes/_fallback/Scripts/02 StageMods.lua index 0c552bde5d..15b1132b22 100644 --- a/Themes/_fallback/Scripts/02 StageMods.lua +++ b/Themes/_fallback/Scripts/02 StageMods.lua @@ -14,29 +14,22 @@ function AreStageSongModsForced() end function SetFail() - local sFail = ""; + local sFail = "" if GetGamePref("DefaultFail") then - sFail = string.format("Fail%s", GetGamePref("DefaultFail")); + sFail = string.format("Fail%s", GetGamePref("DefaultFail")) else - sFail = "FailOff"; + sFail = "FailOff" end - sFail = tostring(sFail); --- SCREENMAN:SystemMessage( 'NEW FAIL IS: ' .. tostring(sFail) ); + sFail = tostring(sFail) for pn in ivalues(GAMESTATE:GetHumanPlayers()) do --- GAMESTATE:ApplyGameCommand( "stagemod,FailImmediateContinue", pn ); --- GAMESTATE:GetPlayerState(pn):SetPlayerOptions( "ModsLevel_Song", 'mod,FailImmediateContinue' ); - MESSAGEMAN:Broadcast( "PlayerOptionsChanged", {PlayerNumber = pn} ); + MESSAGEMAN:Broadcast( "PlayerOptionsChanged", {PlayerNumber = pn} ) end --- GAMESTATE:SetSongOptions( "ModsLevel_Preferred", 'mod,FailImmediateContinue' ); --- GAMESTATE:SetSongOptions( "ModsLevel_Stage", 'mod,FailImmediateContinue' ); --- GAMESTATE:SetSongOptions( "ModsLevel_Song",'mod,FailImmediateContinue' ); - GAMESTATE:ApplyGameCommand( "mod," .. sFail); --- GAMESTATE:ApplyGameCommand( "stagemod,FailImmediateContinue"); - MESSAGEMAN:Broadcast( "SongOptionsChanged" ); + GAMESTATE:ApplyGameCommand( "mod," .. sFail) + MESSAGEMAN:Broadcast( "SongOptionsChanged" ) end function ScreenSelectMusic:setupmusicstagemods() @@ -44,9 +37,9 @@ function ScreenSelectMusic:setupmusicstagemods() local pm = GAMESTATE:GetPlayMode() if pm == "PlayMode_Battle" or pm == "PlayMode_Rave" then - local so = GAMESTATE:GetDefaultSongOptions(); - GAMESTATE:SetSongOptions( "ModsLevel_Stage", so ); - MESSAGEMAN:Broadcast( "SongOptionsChanged" ); + local so = GAMESTATE:GetDefaultSongOptions() + GAMESTATE:SetSongOptions( "ModsLevel_Stage", so ) + MESSAGEMAN:Broadcast( "SongOptionsChanged" ) elseif GAMESTATE:IsAnExtraStage() then if GAMESTATE:GetPreferredSongGroup() == "---Group All---" then local song = GAMESTATE:GetCurrentSong() @@ -58,11 +51,11 @@ function ScreenSelectMusic:setupmusicstagemods() local song, steps = SONGMAN:GetExtraStageInfo( bExtra2, style ) local po, so if bExtra2 then - po = THEME:GetMetric("SongManager","OMESPlayerModifiers"); - so = THEME:GetMetric("SongManager","OMESStageModifiers"); + po = THEME:GetMetric("SongManager","OMESPlayerModifiers") + so = THEME:GetMetric("SongManager","OMESStageModifiers") else - po = THEME:GetMetric("SongManager","ExtraStagePlayerModifiers"); - so = THEME:GetMetric("SongManager","ExtraStageStageModifiers"); + po = THEME:GetMetric("SongManager","ExtraStagePlayerModifiers") + so = THEME:GetMetric("SongManager","ExtraStageStageModifiers") end local difficulty = steps:GetDifficulty()