Extend tpt.screenshot to return created filename and optionally, PPM format

This commit is contained in:
Robert Gadzerfraud 2013-12-08 12:16:12 -07:00
parent f65ea547e7
commit ced44c8be2

View File

@ -2021,7 +2021,22 @@ int screenshotIndex = 0;
int luatpt_screenshot(lua_State* l)
{
int captureUI = luaL_optint(l, 1, 0);
int fileType = luaL_optint(l, 2, 0);
std::vector<char> data;
if(fileType) {
if(captureUI)
{
VideoBuffer screenshot(ui::Engine::Ref().g->DumpFrame());
data = format::VideoBufferToPPM(screenshot);
}
else
{
VideoBuffer screenshot(luacon_ren->DumpFrame());
data = format::VideoBufferToPPM(screenshot);
}
}
else
{
if(captureUI)
{
VideoBuffer screenshot(ui::Engine::Ref().g->DumpFrame());
@ -2032,11 +2047,14 @@ int luatpt_screenshot(lua_State* l)
VideoBuffer screenshot(luacon_ren->DumpFrame());
data = format::VideoBufferToPNG(screenshot);
}
}
std::stringstream filename;
filename << "screenshot_";
filename << std::setfill('0') << std::setw(6) << (screenshotIndex++);
filename << ".png";
if(fileType) { filename << ".ppm"; }
else { filename << ".png"; }
Client::Ref().WriteFile(data, filename.str());
return 0;
lua_pushstring(l, filename.str().c_str());
return 1;
}
#endif