--- /dev/null
+--[[
+Simple persisten row API for 3.95/OpenITG, version 1.2
+Licensed under Creative Commons Attribution-Share Alike 3.0 Unported
+(http://creativecommons.org/licenses/by-sa/3.0/)
+
+This script is based on PrefsRows originally writeen by Marc Cannon ("Vyhd")
+
+Base definitions and templates for StepMania LUA options lists to save to machine profile.
+Written by Cameron Ball for OpenITG (http://www.boxorroxors.net/).
+All I ask is that you keep this notice intact and don't redistribute in bytecode.
+--]]
+
+
+--[[
+Callable functions:
+
+CreateOptionRow( Params, Names, LoadFctn, SaveFctn )
+[creates a generic OptionRow with the given data]
+ - Params: table with OptionRow data. "Name" is required, others are optional.
+ - Names: table with the names of the objects to be used
+ - LoadFctn(self, list, pn): called on list load, sets an initial toggle
+ - SaveFctn(self, list, pn): called on list exit, uses a toggle to set a value
+
+CreateProfileRow( Params, Values )
+[creates a Profile-modifying OptionRow with this data]
+ - Params: a table of parameters to use (generally you would just set Params.Name)
+ - Values: table with the values to be used
+
+CreateProfileRowBool( Params )
+[generates an OptionsRow that toggles a boolean Preference]
+
+GetProfilePref( Name )
+[returns the value of Name in the machine profile table, if it exists]
+
+ToggleBooleanPref( Name )
+[toggles a boolean preference in the profile table, but does not save it]
+--]]
+
+-- This is purely for convenience
+local ProfileTable
+
+-- Without this check, when StepMania starts it will report a lua runtime error as PROFILEMAN apparently doesn't exist yet.
+if PROFILEMAN ~= nil then
+ ProfileTable = PROFILEMAN:GetMachineProfile():GetSaved()
+end
+
+-- This function originally written by Marc Cannon ("Vyhd")
+function CreateOptionRow( Params, Names, LoadFctn, SaveFctn )
+ if not Params.Name then return nil end
+
+ -- this needs to be used because Lua evaluates 'false' as 'nil', so
+ -- we can't use an OR operator to assign the value properly.
+ local function setbool( value, default )
+ if value ~= nil then return value else return default end
+ end
+
+ -- fill in with passed params or default values. only Name is required.
+ local t =
+ {
+ Name = Params.Name,
+
+ LayoutType = Params.LayoutType or "ShowAllInRow",
+ SelectType = Params.SelectType or "SelectOne",
+
+ OneChoiceForAllPlayers = setbool(Params.OneChoiceForAllPlayers, true),
+ EnabledForPlayers = Params.EnabledForPlayers or {PLAYER_1, PLAYER_2},
+
+ ExportOnChange = setbool(Params.ExportOnChange, false),
+ ReloadRowMessages= Params.ReloadRowMessages or {},
+
+ Choices = Names,
+ LoadSelections = LoadFctn,
+ SaveSelections = SaveFctn,
+ }
+
+ setmetatable( t, t )
+ return t
+end
+
+-- creates a row list given a list of names and values
+function CreateProfileRow( Params, Values )
+ local pref = ProfileTable[Params.Name]
+
+ local function Load(self, list, pn)
+ -- what we're doing here is checking what we got from profileman against the valid names.
+ for i=1,table.getn(Values) do
+ if pref == Values[i] then list[i] = true return end
+ end
+
+ if Params.Default then list[Params.Default] = true else list[1] = true end
+ end
+
+ local function Save(self, list, pn)
+ -- go through each item in the list and save the first one that is set to true
+ for i=1,table.getn(Values) do
+ if list[i] then
+ ProfileTable[Params.Name] = Values[i]
+ PROFILEMAN:SaveMachineProfile()
+ return
+ end
+ end
+ end
+
+ return CreateOptionRow( Params, Values, Load, Save )
+end
+
+function CreateProfileRowBool( Params )
+ local choices = {"OFF", "ON"}
+
+ local function Load(self, list, pn)
+ if ProfileTable[Params.Name] then list[2] = true else list[1] = true end
+ end
+
+ local function Save(self, list, pn)
+ if list[1] then ProfileTable[Params.Name] = false else ProfileTable[Params.Name] = true end
+ PROFILEMAN:SaveMachineProfile()
+ return
+ end
+ return CreateOptionRow( Params, choices, Load, Save )
+end
+
+function GetProfilePref(Name)
+ return ProfileTable[Name]
+end
+
+function ToggleBooleanPref(Name)
+ if type(ProfileTable[name]) == "boolean" then ProfileTable[Name] = not ProfileTable[Name] end
+end
--]]\r
\r
\r
--- This is purely for convenience\r
-local ProfileTable\r
-\r
--- Without this check, when StepMania starts it will report a lua runtime error as PROFILEMAN apparently doesn't exist yet.\r
-if PROFILEMAN ~= nil then\r
- ProfileTable = PROFILEMAN:GetMachineProfile():GetSaved()\r
-end\r
-\r
-- Valid speed mod row type names.\r
local Names = { "Basic", "Advanced", "Pro" }\r
\r
function SpeedModTypeRow()\r
- local type = GetSpeedModRowType()\r
-\r
- local function Load(self, list, pn)\r
- -- what we're doing here is checking what we got from profileman against the valid names.\r
- for i=1,3 do\r
- if type == string.lower(Names[i]) then list[i] = true return end\r
- end\r
-\r
- -- if nothing matched then just default to pro\r
- list[3] = true\r
- end\r
-\r
- local function Save(self, list, pn)\r
- -- go through each item in the list and save the first one that is set to true\r
- for i=1,3 do\r
- if list[i] then\r
- ProfileTable.SpeedModType = string.lower(Names[i])\r
- PROFILEMAN:SaveMachineProfile()\r
- return\r
- end\r
- end\r
- end\r
-\r
- local Params = { Name = "SpeedModType" }\r
-\r
- return CreateOptionRow( Params, Names, Load, Save )\r
+ return CreateProfileRow( { Name = "SpeedModType", Default = 3 }, Names )\r
end\r
\r
function GetSpeedModRowType()\r
- local type = ProfileTable.SpeedModType\r
+ local type = GetProfilePref("SpeedModRowType")\r
\r
-- as soon as we find a valid name, return it.\r
for i=1,3 do\r
if type == string.lower(Names[i]) then return type end\r
end\r
\r
- -- no pref, default to the first name in the list.\r
- return string.lower(Names[1])\r
+ -- no pref, default to pro\r
+ return string.lower(Names[3])\r
end\r
\r
function GetRateMods()\r
All I ask is that you keep this notice intact and don't redistribute in bytecode.\r
--]]\r
\r
+\r
--[[\r
Callable functions:\r
\r
-EasterEggsEnabled()\r
-[returns a boolean value depending on whether easter eggs have been enabled]\r
-\r
-ToggleEasterEggs()\r
-[turns easter eggs on/off]\r
-\r
RegisterEasterEgg( Name, fn )\r
[saves an easter egg function to be called later]\r
- Name: the name of the easter egg for later referene, must be unique.\r
end\r
end\r
\r
-RegisterEasterEgg(MyEasterEgg)\r
+RegisterEasterEgg("MyEasterEgg", MyEasterEgg)\r
\r
Then on an Actor you could apply something like:\r
\r
logic will be applied.\r
]]--\r
\r
--- This is purely for convenience\r
-local ProfileTable\r
local FunctionTable = {}\r
\r
--- Without this check, when StepMania starts it will report a lua runtime error as PROFILEMAN apparently doesn't exist yet.\r
-if PROFILEMAN ~= nil then\r
- ProfileTable = PROFILEMAN:GetMachineProfile():GetSaved()\r
-end\r
-\r
-local choices = { "OFF", "ON" }\r
-\r
function EasterEggsEnabled()\r
- --Default to off\r
- if ProfileTable.EasterEggs == nil then return false end\r
-\r
- return ProfileTable.EasterEggs\r
-end\r
-\r
-function ToggleEasterEggs()\r
- ProfileTable.EasterEggs = not ProfileTable.EasterEggs\r
+ local pref = GetProfilePref("EasterEggs")\r
+ if pref == nil then return false else return pref end\r
end\r
\r
function EasterEggsOptionsRow()\r
- local function Load(self, list, pn)\r
- if EasterEggsEnabled() then list[2] = true else list[1] = true end\r
- end\r
-\r
- local function Save(self, list, pn)\r
- if list[1] then ProfileTable.EasterEggs = false else ProfileTable.EasterEggs = true end\r
- PROFILEMAN:SaveMachineProfile()\r
- return\r
- end\r
-\r
local Params = { Name = "EasterEggs" }\r
- return CreateOptionRow( Params, choices, Load, Save )\r
+ return CreateProfileRowBool( Params )\r
end\r
\r
function RegisterEasterEgg(Name, fn)\r
+++ /dev/null
---[[
-Simple PrefsRows API for 3.95/OpenITG, version 1.2
-Licensed under Creative Commons Attribution-Share Alike 3.0 Unported
-(http://creativecommons.org/licenses/by-sa/3.0/)
-
-Base definitions and templates for StepMania LUA options lists.
-Written by Mark Cannon ("Vyhd") for OpenITG (http://www.boxorroxors.net/)
-All I ask is that you keep this notice intact and don't redistribute in bytecode.
---]]
-
-
-
---[[
-Callable functions:
-
-CreateOptionRow( Params, Names, LoadFctn, SaveFctn )
-[creates a generic OptionRow with the given data]
- - Params: table with OptionRow data. "Name" is required, others are optional.
- - Names: table with the names of the objects to be used
- - LoadFctn(self, list, pn): called on list load, sets an initial toggle
- - SaveFctn(self, list, pn): called on list exit, uses a toggle to set a value
-
-CreatePrefsRow( Params, Names, Values, prefname )
-[creates a Preference-modifying OptionRow with this data]
- - Values: table with the values to be used (1:1 map to Names)
- - prefname: string with the name of the Preference to modify
-
-CreatePrefsRowRange( Params, Names, prefname, start, delta )
-[generates an OptionsRow with a value range, set to the length of Names]
- - start: starting value, from which the value generation starts
- - delta: difference between each value in the list
-
-CreatePrefsRowEnum( Params, Names, prefname )
-[generates an OptionsRow that uses enumeration values]
-
-CreatePrefsRowBool( Params, prefname )
-[generates an OptionsRow that toggles a boolean Preference]
-
-CreateSimplePrefsRowBool( prefname )
-[same as above, except sets the OptionRow name to prefname, too]
-
-If you're still confused, check out my usage of these elsewhere.
---]]
-
-function CreateOptionRow( Params, Names, LoadFctn, SaveFctn )
- if not Params.Name then return nil end
-
- -- this needs to be used because Lua evaluates 'false' as 'nil', so
- -- we can't use an OR operator to assign the value properly.
- local function setbool( value, default )
- if value ~= nil then return value else return default end
- end
-
- -- fill in with passed params or default values. only Name is required.
- local t =
- {
- Name = Params.Name,
-
- LayoutType = Params.LayoutType or "ShowAllInRow",
- SelectType = Params.SelectType or "SelectOne",
-
- OneChoiceForAllPlayers = setbool(Params.OneChoiceForAllPlayers, true),
- EnabledForPlayers = Params.EnabledForPlayers or {PLAYER_1, PLAYER_2},
-
- ExportOnChange = setbool(Params.ExportOnChange, false),
- ReloadRowMessages= Params.ReloadRowMessages or {},
-
- Choices = Names,
- LoadSelections = LoadFctn,
- SaveSelections = SaveFctn,
- }
-
- setmetatable( t, t )
- return t
-end
-
--- creates a row list given a list of names and values
-function CreatePrefsRow( Params, Names, Values, prefname )
- local amt = table.getn(Names)
- local val = PREFSMAN:GetPreference(prefname)
-
- local function Load(self, list, pn)
- for i = 1, amt do
- if Values[i] == val then
- list[i] = true
- return
- end
- end
- list[1] = true -- fall back to first value
- end
-
- local function Save(self, list, pn)
- for i = 1, amt do
- if list[i] then
- PREFSMAN:SetPreference(prefname, Values[i])
- return
- end
- end
- end
-
- return CreateOptionRow( Params, Names, Load, Save )
-end
-
--- creates a ranged list, given an offset and delta between values
-function CreatePrefsRowRange( Params, Names, prefname, start, delta )
- local amt = table.getn(Names)
- local val = PREFSMAN:GetPreference(prefname)
-
- local function IndexToValue(i)
- return start+(delta*(i-1))
- end
-
- local function Load(self, list, pn)
- for i = 1, amt do
- if IndexToValue(i) == val then
- list[i] = true
- return
- end
- end
- list[1] = true -- fall back to first value
- end
-
- local function Save(self, list, pn)
- for i = 1,amt do
- if list[i] then
- PREFSMAN:SetPreference(prefname, IndexToValue(i))
- end
- end
- end
-
- return CreateOptionRow( Params, Names, Load, Save )
-end
-
--- creates an enumerated toggle for a preference
-function CreatePrefsRowEnum( Params, Names, prefname )
- local amt = table.getn(Names)
- local val = PREFSMAN:GetPreference(prefname)
-
- return CreateOptionRowRange( Params, Names, prefname, 0, 1 )
-end
-
--- creates a boolean toggle for a preference
-function CreatePrefsRowBool( Params, prefname )
- local OptionValues = { false, true }
- local OptionNames = { "OFF", "ON" }
-
- local val = PREFSMAN:GetPreference(prefname)
-
- local function Load(self, list, pn)
- if PREFSMAN:GetPreference(prefname) == true then
- list[2] = true
- else
- list[1] = true
- end
- end
-
- -- set 0 if "OFF" (index 1), 1 if "ON" (index 2)
- local function Save(self, list, pn)
- for i = 1,2 do
- if list[i] then
- PREFSMAN:SetPreference(prefname, OptionValues[i] )
- return
- end
- end
- end
-
- return CreateOptionRow( Params, OptionNames, Load, Save )
-end
-
--- very simple boolean toggle for a preference
-function CreateSimplePrefsRowBool( prefname )
- local Params = {}
- Params.Name = prefname
-
- return CreatePrefsRowBool( Params, prefname )
-end
\ No newline at end of file
end
local function GoodLuckCameronEasterEgg(Params)
- if GoodLuckCameronEnabled() then
+ if GetProfilePref("GoodLuckCameron") then
Params.Actor:Load(THEME:GetPath(EC_BGANIMATIONS, '', 'ScreenGameplay overlay/winning2.png'))
end
end
local function LowBPM( BPMDisplay )
BPMDisplay = BPMDisplay:GetText()
- Trace("YOLOSWEGGER " .. BPMDisplay)
-
local pos = string.find(BPMDisplay, "-")
if pos == 1 then pos = string.find(BPMDisplay, "-", 2) end -- if we have a negative bpm at the start then look for another occurence after
end
-
--throwing this down here until all this code is refactored and neatened
-local ProfileTable
-
--- Without this check, when StepMania starts it will report a lua runtime error as PROFILEMAN apparently doesn't exist yet.
-if PROFILEMAN ~= nil then
- ProfileTable = PROFILEMAN:GetMachineProfile():GetSaved()
-end
-
-local choices = { "OFF", "ON" }
-
-function GoodLuckCameronEnabled()
- --Default to off
- if ProfileTable.GoodLuckCameron == nil then return false end
-
- return ProfileTable.GoodLuckCameron
-end
-
-function ToggleGoodLuckCameron()
- ProfileTable.GoodLuckCameron = not ProfileTable.GoodLuckCameron
-end
-
function GoodLuckCameronOptionsRow()
- local function Load(self, list, pn)
- if GoodLuckCameronEnabled() then list[2] = true else list[1] = true end
- end
-
- local function Save(self, list, pn)
- if list[1] then ProfileTable.GoodLuckCameron = false else ProfileTable.GoodLuckCameron = true end
- PROFILEMAN:SaveMachineProfile()
- return
- end
-
local Params = { Name = "GoodLuckCameron" }
- return CreateOptionRow( Params, choices, Load, Save )
+ return CreateProfileRowBool( Params )
end
\ No newline at end of file