Emscripten: Add Platform::MarkPresentable

So the website knows when to swap the thumbnail with the canvas of the TPT instance
This commit is contained in:
Tamás Bálint Misius 2023-08-23 00:42:34 +02:00
parent 6ceb51b408
commit 7365d7e11c
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
10 changed files with 31 additions and 6 deletions

View File

@ -493,6 +493,7 @@ int Main(int argc, char *argv[])
catch (std::exception & e)
{
new ErrorMessage("Error", ByteString(e.what()).FromUtf8());
Platform::MarkPresentable();
}
}

View File

@ -49,10 +49,4 @@ void MainLoop()
{
UpdateFpsLimit();
MainLoopBody();
EM_ASM({
let canvas = document.querySelector("canvas.emscripten");
if (canvas) {
canvas.scrollIntoView(true);
}
});
}

View File

@ -74,6 +74,16 @@ int InvokeMain(int argc, char *argv[])
return 0;
}
void MarkPresentable()
{
EM_ASM({
try {
window.mark_presentable();
} catch (e) {
}
});
}
void MaybeTriggerSyncFs()
{
if (!syncFsInFlight && shouldSyncFs.exchange(false, std::memory_order_relaxed))

View File

@ -6,4 +6,8 @@ int InvokeMain(int argc, char *argv[])
{
return Main(argc, argv);
}
void MarkPresentable()
{
}
}

View File

@ -66,6 +66,8 @@ namespace Platform
ByteString DefaultDdir();
int InvokeMain(int argc, char *argv[]);
void MarkPresentable();
}
extern "C" int Main(int argc, char *argv[]);

View File

@ -1225,6 +1225,10 @@ void GameController::OpenSaveDone()
void GameController::OpenSavePreview(int saveID, int saveDate, SavePreviewType savePreviewType)
{
if (savePreviewType == savePreviewUrl)
{
gameView->SkipIntroText();
}
activePreview = new PreviewController(saveID, saveDate, savePreviewType, [this] { OpenSaveDone(); }, nullptr);
ui::Engine::Ref().ShowWindow(activePreview->GetView());
}

View File

@ -1659,6 +1659,11 @@ void GameView::OnFileDrop(ByteString filename)
c->LoadSaveFile(std::move(saveFile));
// hide the info text if it's not already hidden
SkipIntroText();
}
void GameView::SkipIntroText()
{
introText = 0;
}

View File

@ -225,4 +225,6 @@ public:
void DoKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override;
class OptionListener;
void SkipIntroText();
};

View File

@ -52,6 +52,7 @@ void PreviewController::Update()
}
if (previewModel->GetDoOpen() && previewModel->GetSaveInfo() && previewModel->GetSaveInfo()->GetGameSave())
{
Platform::MarkPresentable();
Exit();
}
}

View File

@ -25,6 +25,7 @@
#include "gui/Style.h"
#include "common/tpt-rand.h"
#include "common/platform/Platform.h"
#include "Format.h"
#include "Misc.h"
@ -607,6 +608,7 @@ void PreviewView::SaveLoadingError(String errorMessage)
{
doError = true;
doErrorMessage = errorMessage;
Platform::MarkPresentable();
}
void PreviewView::NotifyCommentsPageChanged(PreviewModel * sender)