From 28c1b3e70b217f51b969a680b6e0e9eb264af753 Mon Sep 17 00:00:00 2001 From: AJ Kelly Date: Thu, 27 Oct 2011 18:56:23 -0500 Subject: [PATCH] update scripts as a part of a cleanup --- Themes/_fallback/Scripts/02 Actor.lua | 179 ++++++++++++++++-- Themes/_fallback/Scripts/02 Lyrics.lua | 71 ------- Themes/_fallback/Scripts/02 Utilities.lua | 63 +++++- .../_fallback/Scripts/03 CustomSpeedMods.lua | 6 +- Themes/_fallback/Scripts/03 EnvUtils2.lua | 13 +- .../_fallback/Scripts/03 GamePreferences.lua | 1 + .../Scripts/03 ProductivityHelpers.lua | 142 -------------- .../_fallback/Scripts/03 UserPreferences2.lua | 1 + Themes/_fallback/Scripts/04 FileUtils.lua | 32 ---- .../Scripts/04 WidescreenHelpers.lua | 12 +- 10 files changed, 237 insertions(+), 283 deletions(-) delete mode 100644 Themes/_fallback/Scripts/02 Lyrics.lua delete mode 100644 Themes/_fallback/Scripts/04 FileUtils.lua diff --git a/Themes/_fallback/Scripts/02 Actor.lua b/Themes/_fallback/Scripts/02 Actor.lua index c523e22e12..acd9f3eac3 100644 --- a/Themes/_fallback/Scripts/02 Actor.lua +++ b/Themes/_fallback/Scripts/02 Actor.lua @@ -181,21 +181,176 @@ function Actor:scale_or_crop_background() end end +-- xy(actorX,actorY) +-- Sets the x and y of an actor in one command. +function Actor:xy(actorX,actorY) + self:x(actorX) + self:y(actorY) +end + +function Actor:CenterX() + self:x(SCREEN_CENTER_X) +end + +function Actor:CenterY() + self:y(SCREEN_CENTER_Y) +end + function Actor:Center() - self:x(SCREEN_CENTER_X) - self:y(SCREEN_CENTER_Y) + self:x(SCREEN_CENTER_X) + self:y(SCREEN_CENTER_Y) end function Actor:bezier(...) - local a = {...} - local b = {} - local c = 0 - assert((a == 9 or a == 5), "bad number of arguments for Actor:bezier()") - for i=3,c do - b[#b+1] = a[i] - end - self:tween(a[2], "TweenMode_Bezier", b) -end + local a = {...} + local b = {} + local c = 0 + assert((a == 9 or a == 5), "bad number of arguments for Actor:bezier()") + for i=3,c do + b[#b+1] = a[i] + end + self:tween(a[2], "TweenMode_Bezier", b) +end + +function Actor:Real() + -- scale back down to real pixels. + self:basezoom(GetReal()) + -- don't make this ugly + self:SetTextureFiltering(false) +end + +-- Scale things back up after they have already been scaled down. +function Actor:RealInverse() + -- scale back up to theme resolution + self:basezoom(GetRealInverse()) + self:SetTextureFiltering(true) +end + +-- MaskSource([clearzbuffer]) +-- Sets an actor up as the source for a mask. Clears zBuffer by default. +function Actor:MaskSource(noclear) + if noclear == true then + self:clearzbuffer(true) + end + self:zwrite(true) + self:blend('BlendMode_NoEffect') +end + +-- MaskDest() +-- Sets an actor up to be masked by anything with MaskSource(). +function Actor:MaskDest() + self:ztest(true) +end + +-- Thump() +-- A customized version of pulse that is more appealing for on-beat +-- effects; +function Actor:thump(fEffectPeriod) + self:pulse() + if fEffectPeriod ~= nil then + self:effecttiming(0,0,0.75*fEffectPeriod,0.25*fEffectPeriod) + else + self:effecttiming(0,0,0.75,0.25) + end + -- The default effectmagnitude will make this effect look very bad. + self:effectmagnitude(1,1.125,1) +end + +-- Heartbeat() +-- A customized version of pulse that is more appealing for on-beat +-- effects; +function Actor:heartbeat(fEffectPeriod) + self:pulse() + if fEffectPeriod ~= nil then + self:effecttiming(0,0.125*fEffectPeriod,0.125*fEffectPeriod,0.75*fEffectPeriod); + else + self:effecttiming(0,0.125,0.125,0.75); + end + self:effecmagnitude(1,1.125,1) +end + +--[[ BitmapText commands ]] + +-- PixelFont() +-- An alias that turns off texture filtering. +-- Named because it works best with pixel fonts. +function BitmapText:PixelFont() + self:SetTextureFiltering(false) +end + +-- Stroke(color) +-- Sets the text's stroke color. +function BitmapText:Stroke(c) + self:strokecolor( c ) +end + +-- NoStroke() +-- Removes any stroke. +function BitmapText:NoStroke() + self:strokecolor( color("0,0,0,0") ) +end + +-- Set Text With Format (contributed by Daisuke Master) +-- this function is my hero - shake +function BitmapText:settextf(...) + self:settext(string.format(...)) +end + +-- DiffuseAndStroke(diffuse,stroke) +-- Set diffuse and stroke at the same time. +function BitmapText:DiffuseAndStroke(diffuseC,strokeC) + self:diffuse(diffuseC) + self:strokecolor(strokeC) +end; +--[[ end BitmapText commands ]] + +function Actor:LyricCommand(side) + self:settext( Var "LyricText" ) + self:draworder(102) + + self:stoptweening() + self:shadowlengthx(0) + self:shadowlengthy(5) + self:strokecolor(color("#000000")) + + local Zoom = SCREEN_WIDTH / (self:GetZoomedWidth()+1) + if( Zoom > 1 ) then + Zoom = 1 + end + self:zoomx( Zoom ) + + local lyricColor = Var "LyricColor" + local Factor = 1 + if side == "Back" then + Factor = 0.5 + elseif side == "Front" then + Factor = 0.9 + end + self:diffuse( { + lyricColor[1] * Factor, + lyricColor[2] * Factor, + lyricColor[3] * Factor, + lyricColor[4] * Factor } ) + + if side == "Front" then + self:cropright(1) + else + self:cropleft(0) + end + + self:diffusealpha(0) + self:linear(0.2) + self:diffusealpha(0.75) + self:linear( Var "LyricDuration" * 0.75) + if side == "Front" then + self:cropright(0) + else + self:cropleft(1) + end + self:sleep( Var "LyricDuration" * 0.25 ) + self:linear(0.2) + self:diffusealpha(0) +end -- formerly in 02 HelpDisplay.lua, although nothing uses it: function HelpDisplay:setfromsongorcourse() @@ -222,7 +377,7 @@ function ActorSound:playforplayer(pn) self:play() end --- (c) 2006 Glenn Maynard +-- (c) 2006-2011 Glenn Maynard, SSC -- All rights reserved. -- -- Permission is hereby granted, free of charge, to any person obtaining a diff --git a/Themes/_fallback/Scripts/02 Lyrics.lua b/Themes/_fallback/Scripts/02 Lyrics.lua deleted file mode 100644 index 9c3be1833e..0000000000 --- a/Themes/_fallback/Scripts/02 Lyrics.lua +++ /dev/null @@ -1,71 +0,0 @@ -function Actor:LyricCommand(side) - self:settext( Var "LyricText" ) - self:draworder(102) - - self:stoptweening() - self:shadowlengthx(0) - self:shadowlengthy(5) - self:strokecolor(color("#000000")) - - local Zoom = SCREEN_WIDTH / (self:GetZoomedWidth()+1) - if( Zoom > 1 ) then - Zoom = 1 - end - self:zoomx( Zoom ) - - local lyricColor = Var "LyricColor" - local Factor = 1 - if side == "Back" then - Factor = 0.5 - elseif side == "Front" then - Factor = 0.9 - end - self:diffuse( { - lyricColor[1] * Factor, - lyricColor[2] * Factor, - lyricColor[3] * Factor, - lyricColor[4] * Factor } ) - - if side == "Front" then - self:cropright(1) - else - self:cropleft(0) - end - - self:diffusealpha(0) - self:linear(0.2) - self:diffusealpha(0.75) - self:linear( Var "LyricDuration" * 0.75) - if side == "Front" then - self:cropright(0) - else - self:cropleft(1) - end - self:sleep( Var "LyricDuration" * 0.25 ) - self:linear(0.2) - self:diffusealpha(0) -end - --- (c) 2006 Glenn Maynard --- All rights reserved. --- --- Permission is hereby granted, free of charge, to any person obtaining a --- copy of this software and associated documentation files (the --- "Software"), to deal in the Software without restriction, including --- without limitation the rights to use, copy, modify, merge, publish, --- distribute, and/or sell copies of the Software, and to permit persons to --- whom the Software is furnished to do so, provided that the above --- copyright notice(s) and this permission notice appear in all copies of --- the Software and that both the above copyright notice(s) and this --- permission notice appear in supporting documentation. --- --- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF --- THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS --- INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT --- OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS --- OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR --- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR --- PERFORMANCE OF THIS SOFTWARE. - diff --git a/Themes/_fallback/Scripts/02 Utilities.lua b/Themes/_fallback/Scripts/02 Utilities.lua index d4eac0a372..7d6181304c 100644 --- a/Themes/_fallback/Scripts/02 Utilities.lua +++ b/Themes/_fallback/Scripts/02 Utilities.lua @@ -182,6 +182,36 @@ function StepsOrTrailToCustomDifficulty(stepsOrTrail) end end +function IsArcade() + local sCoinMode = GAMESTATE:GetCoinMode(); + local bIsArcade = (sCoinMode ~= 'CoinMode_Home'); + return bIsArcade; +end + +function IsHome() + local sCoinMode = GAMESTATE:GetCoinMode(); + local bIsHome = (sCoinMode == 'CoinMode_Home'); + return bIsHome; +end + +function IsFreePlay() + return IsArcade() and (GAMESTATE:GetCoinMode() == 'CoinMode_Free') or false +end + +function Center1Player() + local styleType = GAMESTATE:GetCurrentStyle():GetStyleType() + -- always center in OnePlayerTwoSides. + if styleType == "StyleType_OnePlayerTwoSides" then + return true + -- only Center1P if Pref enabled and OnePlayerOneSide. + -- (implicitly excludes Rave, Battle, Versus, Routine) + elseif PREFSMAN:GetPreference("Center1Player") then + return styleType == "StyleType_OnePlayerOneSide" + else + return false + end +end + Date = { Today = function() return string.format("%i%02i%02i", Year(), (MonthOfYear()+1), DayOfMonth()) @@ -194,7 +224,38 @@ Time = { end } --- (c) 2005 Glenn Maynard, Chris Danford +-- file utilities +File = { + Write = function(path,buf) + local f = RageFileUtil.CreateRageFile() + if f:Open(path, 2) then + f:Write( tostring(buf) ) + f:destroy() + return true + else + Trace( "[FileUtils] Error writing to ".. path ..": ".. f:GetError() ) + f:ClearError() + f:destroy() + return false + end + end, + Read = function(path) + local f = RageFileUtil.CreateRageFile() + local ret = "" + if f:Open(path, 1) then + ret = tostring( f:Read() ) + f:destroy() + return ret + else + Trace( "[FileUtils] Error reading from ".. path ..": ".. f:GetError() ) + f:ClearError() + f:destroy() + return nil + end + end +} + +-- (c) 2005-2011 Glenn Maynard, Chris Danford, SSC -- All rights reserved. -- -- Permission is hereby granted, free of charge, to any person obtaining a diff --git a/Themes/_fallback/Scripts/03 CustomSpeedMods.lua b/Themes/_fallback/Scripts/03 CustomSpeedMods.lua index 709ad85343..315068298a 100644 --- a/Themes/_fallback/Scripts/03 CustomSpeedMods.lua +++ b/Themes/_fallback/Scripts/03 CustomSpeedMods.lua @@ -185,7 +185,7 @@ local function GetSpeedMods() local baseFilename = "SpeedMods.txt" local profileDirs = { - Fallback = "Data/", -- xxx: this seems to cause problems on windows vista/7 + --Fallback = "Data/", Machine = ProfileDir('ProfileSlot_Machine'), PlayerNumber_P1 = ProfileDir('ProfileSlot_Player1'), PlayerNumber_P2 = ProfileDir('ProfileSlot_Player2') @@ -194,7 +194,7 @@ local function GetSpeedMods() -- figure out how many players we have to deal with. local numPlayers = GAMESTATE:GetNumPlayersEnabled() -- load fallback - local fallbackMods = ParseSpeedModFile(profileDirs.Fallback..baseFilename) + --local fallbackMods = ParseSpeedModFile(profileDirs.Fallback..baseFilename) -- load machine local machineMods = ParseSpeedModFile(profileDirs.Machine..baseFilename) @@ -210,7 +210,7 @@ local function GetSpeedMods() end end - finalMods = fallbackMods + --finalMods = fallbackMods -- mine for duplicates, first pass (fallback <-> machine) machineMods = MarkDupes(machineMods,finalMods) for ply=1,#playerMods do diff --git a/Themes/_fallback/Scripts/03 EnvUtils2.lua b/Themes/_fallback/Scripts/03 EnvUtils2.lua index 9df8fefad1..ada8bbd384 100644 --- a/Themes/_fallback/Scripts/03 EnvUtils2.lua +++ b/Themes/_fallback/Scripts/03 EnvUtils2.lua @@ -1,22 +1,14 @@ --[[ EnvUtils2: Environmental Variable Utilities Written by AJ Kelly of KKI Labs / Version 2.0 - -This code is a rewrite of what typically exists in EnvUtils.lua -(as seen in dubaiOne), hereafter referred to as EnvUtils1. - -I felt it was time for a simplification of the code. -This new version should also work better and be less confusing. --]] -- Env table global envTable = GAMESTATE:Env() -- setenv(name,value) --- Sets aside an entry for /name/ and puts /value/ into it. --- Unlike EnvUtils1, this is the only setenv function available to you. --- If you need to store more than one value, you're welcome to use a --- table as /value/, it should work just fine. +-- Sets aside an entry for and puts into it. +-- Use a table as to store multiple values function setenv(name,value) envTable[name] = value end @@ -29,7 +21,6 @@ end --[[ Copyright © 2008 AJ Kelly/KKI Labs -Use freely. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE diff --git a/Themes/_fallback/Scripts/03 GamePreferences.lua b/Themes/_fallback/Scripts/03 GamePreferences.lua index 09724eee7e..1ea0901623 100644 --- a/Themes/_fallback/Scripts/03 GamePreferences.lua +++ b/Themes/_fallback/Scripts/03 GamePreferences.lua @@ -31,6 +31,7 @@ ThemeInfo is documented at http://kki.ajworld.net/wiki/ThemeInfo.lua After that's set up, read the docs. ]] +-- xxx: DON'T USE DATA!! local PrefPath = "Data/GamePrefs/" --[[ begin internal stuff; no need to edit below this line. ]] diff --git a/Themes/_fallback/Scripts/03 ProductivityHelpers.lua b/Themes/_fallback/Scripts/03 ProductivityHelpers.lua index 928f89f5b7..ad94dc4bf9 100644 --- a/Themes/_fallback/Scripts/03 ProductivityHelpers.lua +++ b/Themes/_fallback/Scripts/03 ProductivityHelpers.lua @@ -1,40 +1,4 @@ -- ProductivityHelpers: A set of useful aliases for theming. - ---[[ Globals ]] -function IsArcade() - local sCoinMode = GAMESTATE:GetCoinMode(); - local bIsArcade = (sCoinMode ~= 'CoinMode_Home'); - return bIsArcade; -end - -function IsHome() - local sCoinMode = GAMESTATE:GetCoinMode(); - local bIsHome = (sCoinMode == 'CoinMode_Home'); - return bIsHome; -end - -function IsFreePlay() - if IsArcade() then - return (GAMESTATE:GetCoinMode() == 'CoinMode_Free'); - else - return false - end -end - -function Center1Player() - local styleType = GAMESTATE:GetCurrentStyle():GetStyleType() - -- always center in OnePlayerTwoSides. - if styleType == "StyleType_OnePlayerTwoSides" then - return true - -- only Center1P if Pref enabled and OnePlayerOneSide. - -- (implicitly excludes Rave, Battle, Versus, Routine) - elseif PREFSMAN:GetPreference("Center1Player") then - return styleType == "StyleType_OnePlayerOneSide" - else - return false - end -end - --[[ 3.9 Functions ]] Game = { GetStage = function() @@ -103,118 +67,12 @@ function GetRealInverse() return res/theme end -function Actor:Real() - -- scale back down to real pixels. - self:basezoom(GetReal()) - -- don't make this ugly - self:SetTextureFiltering(false) -end - --- Scale things back up after they have already been scaled down. -function Actor:RealInverse() - -- scale back up to theme resolution - self:basezoom(GetRealInverse()) - self:SetTextureFiltering(true) -end - --[[ Actor commands ]] -function Actor:CenterX() - self:x(SCREEN_CENTER_X) -end - -function Actor:CenterY() - self:y(SCREEN_CENTER_Y) -end - --- xy(actorX,actorY) --- Sets the x and y of an actor in one command. -function Actor:xy(actorX,actorY) - self:x(actorX) - self:y(actorY) -end function PositionPerPlayer(player, p1X, p2X) return player == PLAYER_1 and p1X or p2X end --- MaskSource([clearzbuffer]) --- Sets an actor up as the source for a mask. Clears zBuffer by default. -function Actor:MaskSource(noclear) - if noclear == true then - self:clearzbuffer(true) - end - self:zwrite(true) - self:blend('BlendMode_NoEffect') -end - --- MaskDest() --- Sets an actor up to be masked by anything with MaskSource(). -function Actor:MaskDest() - self:ztest(true) -end - --- Thump() --- A customized version of pulse that is more appealing for on-beat --- effects; -function Actor:thump(fEffectPeriod) - self:pulse() - if fEffectPeriod ~= nil then - self:effecttiming(0,0,0.75*fEffectPeriod,0.25*fEffectPeriod) - else - self:effecttiming(0,0,0.75,0.25) - end - -- The default effectmagnitude will make this effect look very bad. - self:effectmagnitude(1,1.125,1) -end - --- Heartbeat() --- A customized version of pulse that is more appealing for on-beat --- effects; -function Actor:heartbeat(fEffectPeriod) - self:pulse() - if fEffectPeriod ~= nil then - self:effecttiming(0,0.125*fEffectPeriod,0.125*fEffectPeriod,0.75*fEffectPeriod); - else - self:effecttiming(0,0.125,0.125,0.75); - end - self:effecmagnitude(1,1.125,1) -end - ---[[ BitmapText commands ]] - --- PixelFont() --- An alias that turns off texture filtering. --- Named because it works best with pixel fonts. -function BitmapText:PixelFont() - self:SetTextureFiltering(false) -end - --- Stroke(color) --- Sets the text's stroke color. -function BitmapText:Stroke(c) - self:strokecolor( c ) -end - --- NoStroke() --- Removes any stroke. -function BitmapText:NoStroke() - self:strokecolor( color("0,0,0,0") ) -end - --- Set Text With Format (contributed by Daisuke Master) --- this function is my hero - shake -function BitmapText:settextf(...) - self:settext(string.format(...)) -end - --- DiffuseAndStroke(diffuse,stroke) --- Set diffuse and stroke at the same time. -function BitmapText:DiffuseAndStroke(diffuseC,strokeC) - self:diffuse(diffuseC) - self:strokecolor(strokeC) -end; ---[[ end BitmapText commands ]] - --[[ ----------------------------------------------------------------------- ]] --[[ profile stuff ]] diff --git a/Themes/_fallback/Scripts/03 UserPreferences2.lua b/Themes/_fallback/Scripts/03 UserPreferences2.lua index 644eecbb78..eacfc28026 100644 --- a/Themes/_fallback/Scripts/03 UserPreferences2.lua +++ b/Themes/_fallback/Scripts/03 UserPreferences2.lua @@ -31,6 +31,7 @@ ThemeInfo is documented at http://kki.ajworld.net/wiki/ThemeInfo.lua After that's set up, read the docs. ]] +-- xxx: DON'T WRITE TO DATA! local PrefPath = "Data/UserPrefs/".. THEME:GetThemeDisplayName() .."/" --[[ begin internal stuff; no need to edit below this line. ]] diff --git a/Themes/_fallback/Scripts/04 FileUtils.lua b/Themes/_fallback/Scripts/04 FileUtils.lua deleted file mode 100644 index 5aed0fa97b..0000000000 --- a/Themes/_fallback/Scripts/04 FileUtils.lua +++ /dev/null @@ -1,32 +0,0 @@ --- fileutils: quick and dirty, not user prefs oriented file io -File = { - Write = function(path,buf) - local f = RageFileUtil.CreateRageFile() - if f:Open(path, 2) then - f:Write( tostring(buf) ) - f:destroy() - return true - else - Trace( "[FileUtils] Error writing to ".. path ..": ".. f:GetError() ) - f:ClearError() - f:destroy() - return false - end - end, - Read = function(path) - local f = RageFileUtil.CreateRageFile() - local ret = "" - if f:Open(path, 1) then - ret = tostring( f:Read() ) - f:destroy() - return ret - else - Trace( "[FileUtils] Error reading from ".. path ..": ".. f:GetError() ) - f:ClearError() - f:destroy() - return nil - end - end -} --- this code if public domain and/or has no copyright, depending on your --- country's laws. I wish for you to use this code freely, without restriction. \ No newline at end of file diff --git a/Themes/_fallback/Scripts/04 WidescreenHelpers.lua b/Themes/_fallback/Scripts/04 WidescreenHelpers.lua index 71671163d6..3a03b96f0d 100644 --- a/Themes/_fallback/Scripts/04 WidescreenHelpers.lua +++ b/Themes/_fallback/Scripts/04 WidescreenHelpers.lua @@ -9,16 +9,6 @@ AspectRatios = { EightThree = 2.66666 -- 1280x480 (two monitors) } -function IsUsingWideScreen() - return GetScreenAspectRatio() >= AspectRatios.SixteenTen -end - -function IsUsingTwoScreens() - return GetScreenAspectRatio() == AspectRatios.EightThree -end - function WideScale(AR4_3, AR16_9) return scale( SCREEN_WIDTH, 640, 854, AR4_3, AR16_9 ) -end - --- take and use it as you like, I don't care -aj \ No newline at end of file +end \ No newline at end of file