diff --git a/Docs/Luadoc/Lua.xml b/Docs/Luadoc/Lua.xml index 28ed64add2..6b0c5f0555 100644 --- a/Docs/Luadoc/Lua.xml +++ b/Docs/Luadoc/Lua.xml @@ -139,6 +139,7 @@ + @@ -1005,7 +1006,7 @@ - + @@ -1089,6 +1090,7 @@ + @@ -1136,6 +1138,7 @@ + diff --git a/Docs/Luadoc/LuaDocumentation.xml b/Docs/Luadoc/LuaDocumentation.xml index 34ba687243..6a916c3c27 100644 --- a/Docs/Luadoc/LuaDocumentation.xml +++ b/Docs/Luadoc/LuaDocumentation.xml @@ -447,6 +447,10 @@ save yourself some time, copy this for undocumented things: [02 Colors.lua] Modifies the saturation of the specified color + + Saves a screenshot. If pn is nil, saves to the machine's Screenshots dir, otherwise saves to the profile's Screenshots dir. Saves as jpg if compress is true, or png if compress is false. The screenshot is signed if sign is true. prefix and suffix are optional strings to add to the beginning and end of the filename.
+ Returns success and full path of the resulting screenshot. +
Scales x, originally within low1 and high1, to fall between low2 and high2. @@ -2551,6 +2555,9 @@ save yourself some time, copy this for undocumented things: Returns the Grade of this high score. + + Returns the HighScore for this PlayerStageStats. + Return the number of HoldNoteScores that match hns. @@ -3217,6 +3224,9 @@ save yourself some time, copy this for undocumented things:
+ + Adds a screenshot entry to the profile. filename must be the full path of the screenshot, as returned by SaveScreenshot. + Returns a table of all high score names that have been used on this profile. diff --git a/src/PlayerStageStats.cpp b/src/PlayerStageStats.cpp index 8bcc3b9de6..489f1a34c3 100644 --- a/src/PlayerStageStats.cpp +++ b/src/PlayerStageStats.cpp @@ -721,6 +721,12 @@ public: DEFINE_METHOD( GetSongsPassed, m_iSongsPassed ) DEFINE_METHOD( GetSongsPlayed, m_iSongsPlayed ) + static int GetHighScore( T* p, lua_State *L ) + { + p->m_HighScore.PushSelf(L); + return 1; + } + static int GetPlayedSteps( T* p, lua_State *L ) { lua_newtable(L); @@ -839,6 +845,7 @@ public: ADD_METHOD( MaxCombo ); ADD_METHOD( GetCurrentLife ); ADD_METHOD( GetGrade ); + ADD_METHOD( GetHighScore ); ADD_METHOD( GetActualDancePoints ); ADD_METHOD( GetPossibleDancePoints ); ADD_METHOD( GetCurrentPossibleDancePoints ); diff --git a/src/Profile.cpp b/src/Profile.cpp index 058a2f58e1..ff0d808392 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -2018,6 +2018,18 @@ RString Profile::MakeFileNameNoExtension( RString sFileNameBeginning, int iIndex class LunaProfile: public Luna { public: + static int AddScreenshot( T* p, lua_State *L ) + { + HighScore* hs= Luna::check(L, 1); + RString filename= SArg(2); + Screenshot screenshot; + screenshot.sFileName= filename; + screenshot.sMD5= BinaryToHex(CRYPTMAN->GetMD5ForFile(filename)); + screenshot.highScore= *hs; + p->AddScreenshot(screenshot); + return 0; + } + static int GetDisplayName( T* p, lua_State *L ) { lua_pushstring(L, p->m_sDisplayName ); return 1; } static int GetLastUsedHighScoreName( T* p, lua_State *L ) { lua_pushstring(L, p->m_sLastUsedHighScoreName ); return 1; } static int SetLastUsedHighScoreName( T* p, lua_State *L ) @@ -2202,6 +2214,7 @@ public: LunaProfile() { + ADD_METHOD( AddScreenshot ); ADD_METHOD( GetDisplayName ); ADD_METHOD( GetLastUsedHighScoreName ); ADD_METHOD( SetLastUsedHighScoreName ); diff --git a/src/ScreenEvaluation.cpp b/src/ScreenEvaluation.cpp index aae94c0baf..02f7939ce0 100644 --- a/src/ScreenEvaluation.cpp +++ b/src/ScreenEvaluation.cpp @@ -703,8 +703,7 @@ bool ScreenEvaluation::Input( const InputEventPlus &input ) Profile* pProfile = PROFILEMAN->GetProfile(pn); RString sDir = PROFILEMAN->GetProfileDir((ProfileSlot)pn) + "Screenshots/"; - int iScreenshotIndex = pProfile->GetNextScreenshotIndex(); - RString sFileName = StepMania::SaveScreenshot( sDir, true, true, iScreenshotIndex ); + RString sFileName = StepMania::SaveScreenshot( sDir, true, true, "", "" ); if( !sFileName.empty() ) { diff --git a/src/StepMania.cpp b/src/StepMania.cpp index 56489f08e7..e6de401827 100644 --- a/src/StepMania.cpp +++ b/src/StepMania.cpp @@ -1192,32 +1192,32 @@ int main(int argc, char* argv[]) return 0; } -RString StepMania::SaveScreenshot( RString sDir, bool bSaveCompressed, bool bMakeSignature, int iIndex ) +RString StepMania::SaveScreenshot( RString Dir, bool SaveCompressed, bool MakeSignature, RString NamePrefix, RString NameSuffix ) { /* As of sm-ssc v1.0 rc2, screenshots are no longer named by an arbitrary * index. This was causing naming issues for some unknown reason, so we have * changed the screenshot names to a non-blocking format: date and time. * As before, we ignore the extension. -aj */ - RString sFileNameNoExtension = DateTime::GetNowDateTime().GetString(); + RString FileNameNoExtension = NamePrefix + DateTime::GetNowDateTime().GetString() + NameSuffix; // replace space with underscore. - sFileNameNoExtension.Replace(" ","_"); + FileNameNoExtension.Replace(" ","_"); // colons are illegal in filenames. - sFileNameNoExtension.Replace(":",""); + FileNameNoExtension.Replace(":",""); // Save the screenshot. If writing lossy to a memcard, use // SAVE_LOSSY_LOW_QUAL, so we don't eat up lots of space. RageDisplay::GraphicsFileFormat fmt; - if( bSaveCompressed && MEMCARDMAN->PathIsMemCard(sDir) ) + if( SaveCompressed && MEMCARDMAN->PathIsMemCard(Dir) ) fmt = RageDisplay::SAVE_LOSSY_LOW_QUAL; - else if( bSaveCompressed ) + else if( SaveCompressed ) fmt = RageDisplay::SAVE_LOSSY_HIGH_QUAL; else fmt = RageDisplay::SAVE_LOSSLESS_SENSIBLE; - RString sFileName = sFileNameNoExtension + "." + (bSaveCompressed ? "jpg" : "png"); - RString sPath = sDir+sFileName; - bool bResult = DISPLAY->SaveScreenshot( sPath, fmt ); - if( !bResult ) + RString FileName = FileNameNoExtension + "." + (SaveCompressed ? "jpg" : "png"); + RString Path = Dir+FileName; + bool Result = DISPLAY->SaveScreenshot( Path, fmt ); + if( !Result ) { SCREENMAN->PlayInvalidSound(); return RString(); @@ -1225,10 +1225,10 @@ RString StepMania::SaveScreenshot( RString sDir, bool bSaveCompressed, bool bMak SCREENMAN->PlayScreenshotSound(); - if( PREFSMAN->m_bSignProfileData && bMakeSignature ) - CryptManager::SignFileToFile( sPath ); + if( PREFSMAN->m_bSignProfileData && MakeSignature ) + CryptManager::SignFileToFile( Path ); - return sFileName; + return FileName; } void StepMania::InsertCoin( int iNum, bool bCountInBookkeeping ) @@ -1427,7 +1427,7 @@ bool HandleGlobalInputs( const InputEventPlus &input ) || INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, KEY_RSHIFT) ) ); bool bSaveCompressed = !bHoldingShift; RageTimer timer; - StepMania::SaveScreenshot( "Screenshots/", bSaveCompressed, false, -1 ); + StepMania::SaveScreenshot( "Screenshots/", bSaveCompressed, false, "", "" ); LOG->Trace( "Screenshot took %f seconds.", timer.GetDeltaTime() ); return true; // handled } @@ -1562,6 +1562,48 @@ void HandleInputEvents(float fDeltaTime) } } +#include "LuaManager.h" +int LuaFunc_SaveScreenshot(lua_State *L); +int LuaFunc_SaveScreenshot(lua_State *L) +{ + // If pn is provided, save to that player's profile. + // Otherwise, save to the machine. + PlayerNumber pn= Enum::Check(L, 1, true); + bool compress= lua_toboolean(L, 2); + bool sign= lua_toboolean(L, 3); + RString prefix= luaL_optstring(L, 4, ""); + RString suffix= luaL_optstring(L, 5, ""); + RString dir; + if(pn == PlayerNumber_Invalid) + { + dir= "Screenshots/"; + } + else + { + dir= PROFILEMAN->GetProfileDir((ProfileSlot)pn) + "Screenshots/"; + if(PROFILEMAN->ProfileWasLoadedFromMemoryCard(pn)) + { + MEMCARDMAN->MountCard(pn); + } + } + RString filename= StepMania::SaveScreenshot(dir, compress, sign, prefix, suffix); + if(pn != PlayerNumber_Invalid) + { + if(PROFILEMAN->ProfileWasLoadedFromMemoryCard(pn)) + { + MEMCARDMAN->UnmountCard(pn); + } + } + RString path= dir + filename; + lua_pushboolean(L, !filename.empty()); + lua_pushstring(L, path); + return 2; +} +void LuaFunc_Register_SaveScreenshot(lua_State *L); +void LuaFunc_Register_SaveScreenshot(lua_State *L) +{ lua_register(L, "SaveScreenshot", LuaFunc_SaveScreenshot); } +REGISTER_WITH_LUA_FUNCTION(LuaFunc_Register_SaveScreenshot); + /* * (c) 2001-2004 Chris Danford, Glenn Maynard * All rights reserved. diff --git a/src/StepMania.h b/src/StepMania.h index 6e121fa636..00da5d0048 100644 --- a/src/StepMania.h +++ b/src/StepMania.h @@ -18,7 +18,7 @@ namespace StepMania void ChangeCurrentGame( const Game* g ); // If successful, return filename of screenshot in sDir, else return "" - RString SaveScreenshot( RString sDir, bool bSaveCompressed, bool bMakeSignature, int iIndex = -1 ); + RString SaveScreenshot( RString Dir, bool SaveCompressed, bool MakeSignature, RString NamePrefix, RString NameSuffix ); void InsertCoin( int iNum = 1, bool bCountInBookkeeping = true ); void InsertCredit();