Updated globals.lua for #13 and added license and usage examples.
authorCameron Ball <c.ball1729@gmail.com>
Tue, 10 Dec 2013 04:57:11 +0000 (12:57 +0800)
committerCameron Ball <c.ball1729@gmail.com>
Tue, 10 Dec 2013 04:57:11 +0000 (12:57 +0800)
Themes/GrooveNights/Scripts/Globals.lua
Themes/GrooveNights/Scripts/Other.lua

index ea44226..6d3c608 100644 (file)
@@ -1,10 +1,52 @@
+--[[\r
+Simple API to save screen elements for later use for 3.95/OpenITG, version 1.0\r
+Licensed under Creative Commons Attribution-Share Alike 3.0 Unported\r
+(http://creativecommons.org/licenses/by-sa/3.0/)\r
+\r
+Globally callable functions to safely store an actor to be used on a later screen.\r
+\r
+Written by Cameron Ball for OpenITG (http://www.boxorroxors.net/)\r
+All I ask is that you keep this notice intact and don't redistribute in bytecode.\r
+--]]\r
+\r
+--[[\r
+Callable functions:\r
+\r
+RegisterGlobal( Actor, Name )\r
+[saves Actor for later use]\r
+        - Actor: the actor to save.\r
+        - Name: the name of the actor for later reference, must be unique.\r
+\r
+GetGlobal( Names )\r
+[returns a previously saved actor]\r
+        - Name: the name of the actor to retrieve.\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 length to use later you would\r
+put this in metrics.ini under [ScreenSelectMusic]:\r
+\r
+TotalTimeOnCommand=%function(self) RegisterGlobal(self, "TotalTime") end\r
+\r
+Then if you wanted to use the song length actor on the options screen, you can\r
+access it like this:\r
+\r
+local SongLength = GetGlobal("TotalTime")\r
+\r
+After which you can do any sort of actor goodness on it as per usual. EG:\r
+\r
+SongLength:GetText()\r
+SongLength:rainbow()\r
+\r
+etc\r
+]]--\r
+\r
 local GlobalsTable = {}\r
 \r
-function RegisterGlobal(Actor, name)\r
-       -- Todo: check that this global isn't already registered        \r
-       GlobalsTable[name] = Actor:GetText()    \r
+function RegisterGlobal(Actor, Name)\r
+       assert(GlobalsTable[Name] == nil, "Cannot register actor ".. name .. ". It has already been registered")\r
+       GlobalsTable[Name] = Actor\r
 end\r
 \r
-function GetGlobal(name)\r
-       return GlobalsTable[name]\r
+function GetGlobal(Name)\r
+       return GlobalsTable[Name]\r
 end
\ No newline at end of file
index 7f761dd..59e6f08 100644 (file)
@@ -430,9 +430,9 @@ end
 
 function oitgACoptions()
     -- Right now we return the same line names for both OITG and whatever else happens to be running. But in the future they might be different.
-    if OPENITG then return "1,2,3,4,5,6,7,8,9,10,11" end
+    if OPENITG then return "1,2,3,4,5,6,7,8,9,10,11,12" end
 
-    return "1,2,3,4,5,6,7,8,9,10,11"
+    return "1,2,3,4,5,6,7,8,9,10,11,12"
 end
 
 function SongModifiers()
@@ -492,8 +492,8 @@ function DisplayScrollSpeed(pn)
 end
 
 function DisplaySongLength()
-       local SongLength = GetGlobal("TotalTime")
-       local RateMod = string.gsub(GetRateMod(), "x" ,"");
+       local SongLength = GetGlobal("TotalTime"):GetText()
+       local RateMod = string.gsub(GetRateMod(), "x" ,"")
        local ratio = 1/RateMod
        
        local pos = string.find(SongLength, ':')