From: Cameron Ball Date: Thu, 12 Dec 2013 05:13:43 +0000 (+0800) Subject: Change Globals.lua so now the callback has access to the whole actor, not just the... X-Git-Url: https://git.cameron1729.xyz/?a=commitdiff_plain;h=63ba271af705b6e3e33ae5f8bcd39a1b7402c601;p=GrooveNights.git Change Globals.lua so now the callback has access to the whole actor, not just the text. --- diff --git a/Themes/GrooveNights/Scripts/Globals.lua b/Themes/GrooveNights/Scripts/Globals.lua index d12d32b..90d1a4a 100644 --- a/Themes/GrooveNights/Scripts/Globals.lua +++ b/Themes/GrooveNights/Scripts/Globals.lua @@ -21,10 +21,10 @@ GetGlobal( Name ) [returns a previously saved actor] - Name: the name of the actor to retrieve. -RegisterGlobalCallback( Name, fn ) +RegisterGlobalCallback( Name, Actor ) [sets up a function to be called when a global is registered] - Name: the name of the global to apply the callback to - - fn: the callback + - Actor: the Actor that the callback will be applied to The intended way to use this API is by calling RegisterGlobal from your theme's metrics.ini. For example, to save away the song bpm to use later you would @@ -40,12 +40,14 @@ the bpm display has been updated, therefore when we call RegisterGlobal it gets Then we can set up callbacks to pull out the low and high BPMs like so: local function LowBPM( BPMDisplay ) - local pos = string.find(BPMDisplay, "-") + local pos = BPMDisplay:GetText() + pos = string.find(BPMDisplay, "-") if pos ~= nil then return string.sub(BPMDisplay,1,pos-1) else return BPMDisplay end end local function HighBPM( BPMDisplay ) - local pos = string.find(BPMDisplay, "-") + local pos = BPMDisplay:GetText() + pos = string.find(BPMDisplay, "-") if pos ~= nil then return string.sub(BPMDisplay,pos+1) else return BPMDisplay end end @@ -61,9 +63,11 @@ local GlobalsTable = {} local CallbackTable = {} function RegisterGlobal( Name, Actor ) - GlobalsTable[Name] = Actor:GetText() - - if CallbackTable[Name] ~= nil then GlobalsTable[Name] = CallbackTable[Name](GlobalsTable[Name]) end + if CallbackTable[Name] ~= nil + then GlobalsTable[Name] = CallbackTable[Name](Actor) + else + GlobalsTable[Name] = Actor:GetText() + end end function GetGlobal(Name) diff --git a/Themes/GrooveNights/Scripts/Other.lua b/Themes/GrooveNights/Scripts/Other.lua index c7856ee..8dcf776 100644 --- a/Themes/GrooveNights/Scripts/Other.lua +++ b/Themes/GrooveNights/Scripts/Other.lua @@ -473,7 +473,7 @@ function DisplayScrollSpeed(pn) local lowBPM = GetGlobal("LowBPM") local highBPM = GetGlobal("HighBPM") - if lowBPM == highBPM then highBPM = nil end + if lowBPM == highBPM then highBPM = nil end local rateMod = string.gsub(GetRateMod(),'x','') @@ -498,6 +498,7 @@ end function DisplaySongLength() local RateMod = string.gsub(GetRateMod(), "x" ,"") local ratio = 1/RateMod + local seconds = (GetGlobal('TotalTimeSeconds') + (GetGlobal('TotalTimeMinutes')*60))*ratio return string.format("%.2d:%.2d", math.mod(seconds/60,60), math.mod(seconds,60)) diff --git a/Themes/GrooveNights/Scripts/gnSystem.lua b/Themes/GrooveNights/Scripts/gnSystem.lua index 87ac603..504649a 100644 --- a/Themes/GrooveNights/Scripts/gnSystem.lua +++ b/Themes/GrooveNights/Scripts/gnSystem.lua @@ -350,7 +350,7 @@ end --easter eggs local function BlazeIt(Params) - local spaces = string.rep(" ", string.len(DisplayScrollSpeed(Params.pn))) + local spaces = string.rep(" ", string.len(DisplayScrollSpeed(Params.pn))) if DisplayScrollSpeed(Params.pn) == '420' then Params.Actor:settext(spaces .. " Blaze It!") @@ -362,7 +362,7 @@ local function BlazeIt(Params) end local function NoScope(Params) - local spaces = string.rep(" ", string.len(DisplayScrollSpeed(Params.pn))) + local spaces = string.rep(" ", string.len(DisplayScrollSpeed(Params.pn))) if DisplayScrollSpeed(Params.pn) == '360' then Params.Actor:settext(spaces .. " No Scope!") @@ -378,21 +378,29 @@ RegisterEasterEgg("NoScope", NoScope) --global variable callbacks local function LowBPM( BPMDisplay ) + BPMDisplay = BPMDisplay:GetText() + local pos = string.find(BPMDisplay, "-") if pos ~= nil then return string.sub(BPMDisplay,1,pos-1) else return BPMDisplay end end local function HighBPM( BPMDisplay ) + BPMDisplay = BPMDisplay:GetText() + local pos = string.find(BPMDisplay, "-") if pos ~= nil then return string.sub(BPMDisplay,pos+1) else return BPMDisplay end end local function TotalTimeMinutes( TimeDisplay ) + TimeDisplay = TimeDisplay:GetText() + local pos = string.find(TimeDisplay, ':') return string.sub(TimeDisplay, 1, pos-1) end local function TotalTimeSeconds( TimeDisplay ) + TimeDisplay = TimeDisplay:GetText() + local pos = string.find(TimeDisplay, ':') return string.sub(TimeDisplay, pos+1) end @@ -400,4 +408,20 @@ end RegisterGlobalCallback("HighBPM", HighBPM) RegisterGlobalCallback("LowBPM", LowBPM) RegisterGlobalCallback("TotalTimeMinutes", TotalTimeMinutes) -RegisterGlobalCallback("TotalTimeSeconds", TotalTimeSeconds) \ No newline at end of file +RegisterGlobalCallback("TotalTimeSeconds", TotalTimeSeconds) + +--actor setters + +function SetFromDisplayScrollSpeed( Actor, pn ) + Actor:settext(DisplayScrollSpeed(pn)) + + local function GetWidthCallback( ScrollSpeedDisplay ) + return ScrollSpeedDisplay:GetWidth() + end + + if not GetGlobal("ScrollSpeedDisplayWidth") then + RegisterGlobalCallback("ScrollSpeedDisplayWidth", GetWidthCallback) + end + + RegisterGlobal("ScrollSpeedDisplayWidth", Actor) +end