mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-23 06:44:38 +01:00
Emscripten: Reimplement save/load
This commit is contained in:
@@ -76,6 +76,13 @@
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
extern "C" {
|
||||
extern void EmscriptenSaveGame(bool isTrackDesign, bool isAutosave, bool saveAs, LoadSaveType type);
|
||||
extern void EmscriptenResetAutosave();
|
||||
}
|
||||
#endif
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
uint16_t gCurrentDeltaTime;
|
||||
@@ -455,8 +462,14 @@ void SaveGame()
|
||||
{
|
||||
if (!gFirstTimeSaving && !gIsAutosaveLoaded)
|
||||
{
|
||||
#ifndef __EMSCRIPTEN__
|
||||
const auto savePath = Path::WithExtension(gScenarioSavePath, ".park");
|
||||
SaveGameWithName(savePath);
|
||||
#else
|
||||
const auto savePath = Path::WithExtension("save", ".park");
|
||||
SaveGameWithName(savePath);
|
||||
EmscriptenSaveGame(false, false, false, LoadSaveType::park);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -512,6 +525,7 @@ void SaveGameAs()
|
||||
ContextOpenIntent(intent.get());
|
||||
}
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
static void LimitAutosaveCount(const size_t numberOfFilesToKeep, bool processLandscapeFolder)
|
||||
{
|
||||
size_t autosavesCount = 0;
|
||||
@@ -613,6 +627,14 @@ void GameAutosave()
|
||||
if (!ScenarioSave(gameState, path, saveFlags))
|
||||
Console::Error::WriteLine("Could not autosave the scenario. Is the save folder writeable?");
|
||||
}
|
||||
#else
|
||||
void GameAutosave()
|
||||
{
|
||||
const auto savePath = Path::WithExtension("save", ".park");
|
||||
SaveGameWithName(savePath);
|
||||
EmscriptenSaveGame(false, true, false, LoadSaveType::park);
|
||||
}
|
||||
#endif // __EMSCRIPTEN__
|
||||
|
||||
static void GameLoadOrQuitNoSavePromptCallback(ModalResult result, const utf8* path)
|
||||
{
|
||||
@@ -643,6 +665,9 @@ static void NewGameWindowCallback(const utf8* path)
|
||||
GetContext()->LoadParkFromFile(path, false, true);
|
||||
GameLoadScripts();
|
||||
GameNotifyMapChanged();
|
||||
#ifdef __EMSCRIPTEN__
|
||||
EmscriptenResetAutosave();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -685,6 +710,9 @@ void GameLoadOrQuitNoSavePrompt()
|
||||
gFirstTimeSaving = true;
|
||||
GameNotifyMapChange();
|
||||
GameUnloadScripts();
|
||||
#ifdef __EMSCRIPTEN__
|
||||
EmscriptenResetAutosave();
|
||||
#endif
|
||||
|
||||
auto* context = OpenRCT2::GetContext();
|
||||
context->SetActiveScene(context->GetTitleScene());
|
||||
|
||||
Reference in New Issue
Block a user