Use date in screenshot filenames to ensure each screenshot's filename is unique
This commit is contained in:
parent
23af1042b4
commit
c8c0f90871
@ -373,7 +373,7 @@ String DoMigration(ByteString fromDir, ByteString toDir)
|
|||||||
auto scripts = DirectorySearch(fromDir + "scripts", "", { ".lua", ".txt" });
|
auto scripts = DirectorySearch(fromDir + "scripts", "", { ".lua", ".txt" });
|
||||||
auto downloadedScripts = DirectorySearch(fromDir + "scripts/downloaded", "", { ".lua" });
|
auto downloadedScripts = DirectorySearch(fromDir + "scripts/downloaded", "", { ".lua" });
|
||||||
bool hasScriptinfo = FileExists(toDir + "scripts/downloaded/scriptinfo");
|
bool hasScriptinfo = FileExists(toDir + "scripts/downloaded/scriptinfo");
|
||||||
auto screenshots = DirectorySearch(fromDir, "powdertoy-", { ".png" });
|
auto screenshots = DirectorySearch(fromDir, "screenshot", { ".png" });
|
||||||
bool hasAutorun = FileExists(fromDir + "autorun.lua");
|
bool hasAutorun = FileExists(fromDir + "autorun.lua");
|
||||||
bool hasPref = FileExists(fromDir + "powder.pref");
|
bool hasPref = FileExists(fromDir + "powder.pref");
|
||||||
|
|
||||||
|
@ -1543,6 +1543,11 @@ String GameController::WallName(int type)
|
|||||||
return String();
|
return String();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ByteString GameController::TakeScreenshot(int captureUI, int fileType)
|
||||||
|
{
|
||||||
|
return gameView->TakeScreenshot(captureUI, fileType);
|
||||||
|
}
|
||||||
|
|
||||||
int GameController::Record(bool record)
|
int GameController::Record(bool record)
|
||||||
{
|
{
|
||||||
return gameView->Record(record);
|
return gameView->Record(record);
|
||||||
|
@ -160,6 +160,7 @@ public:
|
|||||||
String BasicParticleInfo(Particle const &sample_part);
|
String BasicParticleInfo(Particle const &sample_part);
|
||||||
bool IsValidElement(int type);
|
bool IsValidElement(int type);
|
||||||
String WallName(int type);
|
String WallName(int type);
|
||||||
|
ByteString TakeScreenshot(int captureUI, int fileType);
|
||||||
int Record(bool record);
|
int Record(bool record);
|
||||||
|
|
||||||
void ResetAir();
|
void ResetAir();
|
||||||
|
@ -193,7 +193,9 @@ GameView::GameView():
|
|||||||
introTextMessage(ByteString(introTextData).FromUtf8()),
|
introTextMessage(ByteString(introTextData).FromUtf8()),
|
||||||
|
|
||||||
doScreenshot(false),
|
doScreenshot(false),
|
||||||
screenshotIndex(0),
|
screenshotIndex(1),
|
||||||
|
lastScreenshotTime(0),
|
||||||
|
recordingIndex(0),
|
||||||
recording(false),
|
recording(false),
|
||||||
recordingFolder(0),
|
recordingFolder(0),
|
||||||
currentPoint(ui::Point(0, 0)),
|
currentPoint(ui::Point(0, 0)),
|
||||||
@ -889,9 +891,53 @@ void GameView::NotifyBrushChanged(GameModel * sender)
|
|||||||
activeBrush = sender->GetBrush();
|
activeBrush = sender->GetBrush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::screenshot()
|
ByteString GameView::TakeScreenshot(int captureUI, int fileType)
|
||||||
{
|
{
|
||||||
doScreenshot = true;
|
VideoBuffer *screenshot;
|
||||||
|
std::vector<char> data;
|
||||||
|
time_t screenshotTime = time(nullptr);
|
||||||
|
std::string extension;
|
||||||
|
|
||||||
|
if (captureUI)
|
||||||
|
screenshot = new VideoBuffer(ren->DumpFrame());
|
||||||
|
else
|
||||||
|
screenshot = new VideoBuffer(ui::Engine::Ref().g->DumpFrame());
|
||||||
|
|
||||||
|
if (fileType == 1)
|
||||||
|
{
|
||||||
|
data = format::VideoBufferToBMP(screenshot);
|
||||||
|
extension = ".bmp";
|
||||||
|
}
|
||||||
|
else if (fileType == 2)
|
||||||
|
{
|
||||||
|
data = format::VideoBufferToPPM(screenshot);
|
||||||
|
extension = ".ppm";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data = format::VideoBufferToPNG(screenshot);
|
||||||
|
extension = ".png";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optional suffix to distinguish screenshots taken at the exact same time
|
||||||
|
ByteString suffix = "";
|
||||||
|
if (screenshotTime == lastScreenshotTime)
|
||||||
|
{
|
||||||
|
screenshotIndex++;
|
||||||
|
suffix = ByteString::Build(" (", screenshotIndex, ")");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
screenshotIndex = 1;
|
||||||
|
}
|
||||||
|
std::string date = format::UnixtimeToDate(screenshotTime, "%Y-%m-%d %H.%M.%S");
|
||||||
|
ByteString filename = ByteString::Build("screenshot ", date, suffix, extension);
|
||||||
|
|
||||||
|
Client::Ref().WriteFile(data, filename);
|
||||||
|
doScreenshot = false;
|
||||||
|
lastScreenshotTime = screenshotTime;
|
||||||
|
|
||||||
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GameView::Record(bool record)
|
int GameView::Record(bool record)
|
||||||
@ -912,6 +958,7 @@ int GameView::Record(bool record)
|
|||||||
Platform::MakeDirectory("recordings");
|
Platform::MakeDirectory("recordings");
|
||||||
Platform::MakeDirectory(ByteString::Build("recordings", PATH_SEP, recordingFolder).c_str());
|
Platform::MakeDirectory(ByteString::Build("recordings", PATH_SEP, recordingFolder).c_str());
|
||||||
recording = true;
|
recording = true;
|
||||||
|
recordingIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return recordingFolder;
|
return recordingFolder;
|
||||||
@ -1328,7 +1375,7 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl,
|
|||||||
c->SetActiveTool(0, "DEFAULT_UI_PROPERTY");
|
c->SetActiveTool(0, "DEFAULT_UI_PROPERTY");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
screenshot();
|
doScreenshot = true;
|
||||||
break;
|
break;
|
||||||
case SDL_SCANCODE_F3:
|
case SDL_SCANCODE_F3:
|
||||||
SetDebugHUD(!GetDebugHUD());
|
SetDebugHUD(!GetDebugHUD());
|
||||||
@ -2088,15 +2135,9 @@ void GameView::OnDraw()
|
|||||||
|
|
||||||
ren->RenderEnd();
|
ren->RenderEnd();
|
||||||
|
|
||||||
if(doScreenshot)
|
if (doScreenshot)
|
||||||
{
|
{
|
||||||
VideoBuffer screenshot(ren->DumpFrame());
|
TakeScreenshot(0, 0);
|
||||||
std::vector<char> data = format::VideoBufferToPNG(screenshot);
|
|
||||||
|
|
||||||
ByteString filename = ByteString::Build("screenshot_", Format::Width(screenshotIndex++, 6), ".png");
|
|
||||||
|
|
||||||
Client::Ref().WriteFile(data, filename);
|
|
||||||
doScreenshot = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(recording)
|
if(recording)
|
||||||
@ -2104,7 +2145,7 @@ void GameView::OnDraw()
|
|||||||
VideoBuffer screenshot(ren->DumpFrame());
|
VideoBuffer screenshot(ren->DumpFrame());
|
||||||
std::vector<char> data = format::VideoBufferToPPM(screenshot);
|
std::vector<char> data = format::VideoBufferToPPM(screenshot);
|
||||||
|
|
||||||
ByteString filename = ByteString::Build("recordings", PATH_SEP, recordingFolder, PATH_SEP, "frame_", Format::Width(screenshotIndex++, 6), ".ppm");
|
ByteString filename = ByteString::Build("recordings", PATH_SEP, recordingFolder, PATH_SEP, "frame_", Format::Width(recordingIndex++, 6), ".ppm");
|
||||||
|
|
||||||
Client::Ref().WriteFile(data, filename);
|
Client::Ref().WriteFile(data, filename);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef GAMEVIEW_H
|
#ifndef GAMEVIEW_H
|
||||||
#define GAMEVIEW_H
|
#define GAMEVIEW_H
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include "common/String.h"
|
#include "common/String.h"
|
||||||
@ -71,6 +72,8 @@ private:
|
|||||||
|
|
||||||
bool doScreenshot;
|
bool doScreenshot;
|
||||||
int screenshotIndex;
|
int screenshotIndex;
|
||||||
|
time_t lastScreenshotTime;
|
||||||
|
int recordingIndex;
|
||||||
bool recording;
|
bool recording;
|
||||||
int recordingFolder;
|
int recordingFolder;
|
||||||
|
|
||||||
@ -124,8 +127,6 @@ private:
|
|||||||
|
|
||||||
void SetSaveButtonTooltips();
|
void SetSaveButtonTooltips();
|
||||||
|
|
||||||
void screenshot();
|
|
||||||
|
|
||||||
void enableShiftBehaviour();
|
void enableShiftBehaviour();
|
||||||
void disableShiftBehaviour();
|
void disableShiftBehaviour();
|
||||||
void enableCtrlBehaviour();
|
void enableCtrlBehaviour();
|
||||||
@ -157,6 +158,7 @@ public:
|
|||||||
void BeginStampSelection();
|
void BeginStampSelection();
|
||||||
ui::Point GetPlaceSaveOffset() { return placeSaveOffset; }
|
ui::Point GetPlaceSaveOffset() { return placeSaveOffset; }
|
||||||
void SetPlaceSaveOffset(ui::Point offset) { placeSaveOffset = offset; }
|
void SetPlaceSaveOffset(ui::Point offset) { placeSaveOffset = offset; }
|
||||||
|
ByteString TakeScreenshot(int captureUI, int fileType);
|
||||||
int Record(bool record);
|
int Record(bool record);
|
||||||
|
|
||||||
//all of these are only here for one debug lines
|
//all of these are only here for one debug lines
|
||||||
|
@ -1414,38 +1414,8 @@ int luatpt_screenshot(lua_State* l)
|
|||||||
{
|
{
|
||||||
int captureUI = luaL_optint(l, 1, 0);
|
int captureUI = luaL_optint(l, 1, 0);
|
||||||
int fileType = luaL_optint(l, 2, 0);
|
int fileType = luaL_optint(l, 2, 0);
|
||||||
std::vector<char> data;
|
|
||||||
if(captureUI)
|
ByteString filename = luacon_controller->TakeScreenshot(captureUI, fileType);
|
||||||
{
|
|
||||||
VideoBuffer screenshot(ui::Engine::Ref().g->DumpFrame());
|
|
||||||
if(fileType == 1) {
|
|
||||||
data = format::VideoBufferToBMP(screenshot);
|
|
||||||
} else if(fileType == 2) {
|
|
||||||
data = format::VideoBufferToPPM(screenshot);
|
|
||||||
} else {
|
|
||||||
data = format::VideoBufferToPNG(screenshot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
VideoBuffer screenshot(luacon_ren->DumpFrame());
|
|
||||||
if(fileType == 1) {
|
|
||||||
data = format::VideoBufferToBMP(screenshot);
|
|
||||||
} else if(fileType == 2) {
|
|
||||||
data = format::VideoBufferToPPM(screenshot);
|
|
||||||
} else {
|
|
||||||
data = format::VideoBufferToPNG(screenshot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ByteString filename = ByteString::Build("screenshot_", Format::Width(screenshotIndex++, 6));
|
|
||||||
if(fileType == 1) {
|
|
||||||
filename += ".bmp";
|
|
||||||
} else if(fileType == 2) {
|
|
||||||
filename += ".ppm";
|
|
||||||
} else {
|
|
||||||
filename += ".png";
|
|
||||||
}
|
|
||||||
Client::Ref().WriteFile(data, filename);
|
|
||||||
lua_pushstring(l, filename.c_str());
|
lua_pushstring(l, filename.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user