Merge pull request #197 from kyzentun/SaveScreenshot

SaveScreenshot for Lua
This commit is contained in:
kyzentun
2014-06-23 12:51:55 -06:00
7 changed files with 92 additions and 18 deletions
+4 -1
View File
@@ -139,6 +139,7 @@
<Function name='RoutineSkinP2'/>
<Function name='SMOnlineScreen'/>
<Function name='Saturation'/>
<Function name='SaveScreenshot'/>
<Function name='ScoreKeeperClass'/>
<Function name='ScreenMetric'/>
<Function name='ScreenString'/>
@@ -1005,7 +1006,7 @@
<Function name='Twirl'/>
<Function name='Roll'/>
<Function name='Hidden'/>
<Function name='HIddenOffset'/>
<Function name='HiddenOffset'/>
<Function name='Sudden'/>
<Function name='SuddenOffset'/>
<Function name='Stealth'/>
@@ -1089,6 +1090,7 @@
<Function name='GetCurrentScoreMultiplier'/>
<Function name='GetFailed'/>
<Function name='GetGrade'/>
<Function name='GetHighScore'/>
<Function name='GetHoldNoteScores'/>
<Function name='GetLessonScoreActual'/>
<Function name='GetLessonScoreNeeded'/>
@@ -1136,6 +1138,7 @@
<Function name='SetPreferenceToDefault'/>
</Class>
<Class name='Profile'>
<Function name='AddScreenshot'/>
<Function name='GetAllUsedHighScoreNames'/>
<Function name='GetCaloriesBurnedToday'/>
<Function name='GetCharacter'/>
+10
View File
@@ -447,6 +447,10 @@ save yourself some time, copy this for undocumented things:
<Function name='Saturation' theme='_fallback' return='color' arguments='color c, float percent'>
[02 Colors.lua] Modifies the saturation of the specified color
</Function>
<Function name='SaveScreenshot' return= 'bool, string' arguments='PlayerNumber pn, bool compress, bool sign, string prefix, string suffix'>
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.<br/>
Returns success and full path of the resulting screenshot.
</Function>
<Function name='scale' return='float' arguments='float x, float low1, float high1, float low2, float high2'>
Scales <code>x</code>, originally within <code>low1</code> and <code>high1</code>, to fall between <code>low2</code> and <code>high2</code>.
</Function>
@@ -2551,6 +2555,9 @@ save yourself some time, copy this for undocumented things:
<Function name='GetGrade' return='Grade' arguments=''>
Returns the Grade of this high score.
</Function>
<Function name='GetHighScore' return='HighScore' arguments=''>
Returns the HighScore for this PlayerStageStats.
</Function>
<Function name='GetHoldNoteScore' return='int' arguments='HoldNoteScore hns'>
Return the number of HoldNoteScores that match <code>hns</code>.
</Function>
@@ -3217,6 +3224,9 @@ save yourself some time, copy this for undocumented things:
</Function>
</Class>
<Class name='Profile'>
<Function name='AddScreenshot' return='void' arguments='HighScore hs, string filename'>
Adds a screenshot entry to the profile. filename must be the full path of the screenshot, as returned by SaveScreenshot.
</Function>
<Function name='GetAllUsedHighScoreNames' return= '{string}' arguments='void'>
Returns a table of all high score names that have been used on this profile.
</Function>
+7
View File
@@ -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 );
+13
View File
@@ -2018,6 +2018,18 @@ RString Profile::MakeFileNameNoExtension( RString sFileNameBeginning, int iIndex
class LunaProfile: public Luna<Profile>
{
public:
static int AddScreenshot( T* p, lua_State *L )
{
HighScore* hs= Luna<HighScore>::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 );
+1 -2
View File
@@ -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() )
{
+56 -14
View File
@@ -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<PlayerNumber>(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.
+1 -1
View File
@@ -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();