2019-04-20 07:12:32 -05:00
|
|
|
#include "graphics/Graphics.h"
|
|
|
|
#include "graphics/Renderer.h"
|
2018-04-30 13:13:24 -05:00
|
|
|
#include "common/String.h"
|
2023-01-19 12:43:33 -06:00
|
|
|
#include "common/tpt-rand.h"
|
2012-10-29 04:36:16 -05:00
|
|
|
#include "Format.h"
|
2013-03-22 09:14:17 -05:00
|
|
|
#include "gui/interface/Engine.h"
|
2012-10-29 04:36:16 -05:00
|
|
|
#include "client/GameSave.h"
|
|
|
|
#include "simulation/Simulation.h"
|
2023-01-27 10:31:40 -06:00
|
|
|
#include "common/platform/Platform.h"
|
2023-01-20 16:28:31 -06:00
|
|
|
#include <ctime>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <vector>
|
2012-10-29 04:36:16 -05:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
2018-04-03 20:46:01 -05:00
|
|
|
{
|
2020-09-15 14:23:05 -05:00
|
|
|
if (!argv[1] || !argv[2]) {
|
|
|
|
std::cout << "Usage: " << argv[0] << " <inputFilename> <outputPrefix>" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2022-08-07 08:27:04 -05:00
|
|
|
auto inputFilename = ByteString(argv[1]);
|
|
|
|
auto outputFilename = ByteString(argv[2]) + ".png";
|
2012-10-29 04:36:16 -05:00
|
|
|
|
2022-08-07 08:27:04 -05:00
|
|
|
std::vector<char> fileData;
|
2023-01-25 09:47:19 -06:00
|
|
|
if (!Platform::ReadFile(fileData, inputFilename))
|
2022-08-07 08:27:04 -05:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-10-29 04:36:16 -05:00
|
|
|
|
2023-05-11 05:40:23 -05:00
|
|
|
std::unique_ptr<GameSave> gameSave;
|
2015-01-10 17:47:42 -06:00
|
|
|
try
|
|
|
|
{
|
2023-05-11 05:40:23 -05:00
|
|
|
gameSave = std::make_unique<GameSave>(fileData, false);
|
2015-01-10 17:47:42 -06:00
|
|
|
}
|
2020-02-23 16:43:11 -06:00
|
|
|
catch (ParseException &e)
|
2015-01-10 17:47:42 -06:00
|
|
|
{
|
|
|
|
//Render the save again later or something? I don't know
|
2018-04-30 13:13:24 -05:00
|
|
|
if (ByteString(e.what()).FromUtf8() == "Save from newer version")
|
2015-01-10 17:47:42 -06:00
|
|
|
throw e;
|
|
|
|
}
|
2012-10-29 04:36:16 -05:00
|
|
|
|
|
|
|
Simulation * sim = new Simulation();
|
2023-04-03 06:53:19 -05:00
|
|
|
Renderer * ren = new Renderer(sim);
|
2012-10-29 04:36:16 -05:00
|
|
|
|
2015-01-10 17:47:42 -06:00
|
|
|
if (gameSave)
|
|
|
|
{
|
2023-05-13 06:18:12 -05:00
|
|
|
sim->Load(gameSave.get(), true, { 0, 0 });
|
2015-01-10 17:47:42 -06:00
|
|
|
|
|
|
|
//Render save
|
|
|
|
ren->decorations_enable = true;
|
|
|
|
ren->blackDecorations = true;
|
|
|
|
|
|
|
|
int frame = 15;
|
|
|
|
while(frame)
|
|
|
|
{
|
|
|
|
frame--;
|
|
|
|
ren->render_parts();
|
|
|
|
ren->render_fire();
|
2023-04-03 06:53:19 -05:00
|
|
|
ren->clearScreen();
|
2015-01-10 17:47:42 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2012-10-29 04:36:16 -05:00
|
|
|
{
|
2023-04-29 08:34:19 -05:00
|
|
|
int w = Graphics::TextSize("Save file invalid").X + 15, x = (XRES-w)/2, y = (YRES-24)/2;
|
2023-04-30 07:14:24 -05:00
|
|
|
ren->DrawRect(RectSized(Vec2{ x, y }, Vec2{ w, 24 }), 0xC0C0C0_rgb);
|
|
|
|
ren->BlendText({ x+8, y+8 }, "Save file invalid", 0xC0C0F0_rgb .WithAlpha(255));
|
2012-10-29 04:36:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ren->RenderBegin();
|
|
|
|
ren->RenderEnd();
|
|
|
|
|
2023-04-05 13:24:48 -05:00
|
|
|
if (auto data = ren->DumpFrame().ToPNG())
|
|
|
|
Platform::WriteFile(*data, outputFilename);
|
2012-10-29 04:36:16 -05:00
|
|
|
}
|