Change Globals.lua so now the callback has access to the whole actor, not just the...
authorCameron Ball <c.ball1729@gmail.com>
Thu, 12 Dec 2013 05:13:43 +0000 (13:13 +0800)
committerCameron Ball <c.ball1729@gmail.com>
Thu, 12 Dec 2013 05:13:43 +0000 (13:13 +0800)
Themes/GrooveNights/Scripts/Globals.lua
Themes/GrooveNights/Scripts/Other.lua
Themes/GrooveNights/Scripts/gnSystem.lua

index d12d32b..90d1a4a 100644 (file)
@@ -21,10 +21,10 @@ GetGlobal( Name )
 [returns a previously saved actor]\r
         - Name: the name of the actor to retrieve.\r
                \r
-RegisterGlobalCallback( Name, fn )\r
+RegisterGlobalCallback( Name, Actor )\r
 [sets up a function to be called when a global is registered]\r
                - Name: the name of the global to apply the callback to\r
-               - fn: the callback\r
+               - Actor: the Actor that the callback will be applied to\r
 \r
 The intended way to use this API is by calling RegisterGlobal from your theme's\r
 metrics.ini. For example, to save away the song bpm to use later you would\r
@@ -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:\r
 \r
 local function LowBPM( BPMDisplay )\r
-       local pos = string.find(BPMDisplay, "-")\r
+        local pos = BPMDisplay:GetText()\r
+       pos = string.find(BPMDisplay, "-")\r
        if pos ~= nil then return string.sub(BPMDisplay,1,pos-1) else return BPMDisplay end\r
 end\r
 \r
 local function HighBPM( BPMDisplay )\r
-       local pos = string.find(BPMDisplay, "-")\r
+        local pos = BPMDisplay:GetText()\r
+       pos = string.find(BPMDisplay, "-")\r
        if pos ~= nil then return string.sub(BPMDisplay,pos+1) else return BPMDisplay end\r
 end\r
 \r
@@ -61,9 +63,11 @@ local GlobalsTable = {}
 local CallbackTable = {}\r
 \r
 function RegisterGlobal( Name, Actor )\r
-       GlobalsTable[Name] = Actor:GetText()\r
-       \r
-       if CallbackTable[Name] ~= nil then GlobalsTable[Name] = CallbackTable[Name](GlobalsTable[Name]) end\r
+        if CallbackTable[Name] ~= nil\r
+            then GlobalsTable[Name] = CallbackTable[Name](Actor)\r
+        else\r
+            GlobalsTable[Name] = Actor:GetText()       \r
+        end\r
 end\r
 \r
 function GetGlobal(Name)\r
index c7856ee..8dcf776 100644 (file)
@@ -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))
index 87ac603..504649a 100644 (file)
@@ -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