Changeset View
Changeset View
Standalone View
Standalone View
source/ps/scripting/JSInterface_SavedGame.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2023 Wildfire Games. | ||||||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||||||
* | * | ||||||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||||||
* (at your option) any later version. | * (at your option) any later version. | ||||||||
* | * | ||||||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||||||
* | * | ||||||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||||||
*/ | */ | ||||||||
#include "precompiled.h" | #include "precompiled.h" | ||||||||
#include "JSInterface_SavedGame.h" | #include "JSInterface_SavedGame.h" | ||||||||
#include "i18n/L10n.h" | |||||||||
#include "network/NetClient.h" | #include "network/NetClient.h" | ||||||||
#include "network/NetServer.h" | #include "network/NetServer.h" | ||||||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||||||
#include "ps/SavedGame.h" | #include "ps/SavedGame.h" | ||||||||
#include "scriptinterface/FunctionWrapper.h" | #include "scriptinterface/FunctionWrapper.h" | ||||||||
#include "scriptinterface/StructuredClone.h" | #include "scriptinterface/StructuredClone.h" | ||||||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||||||
Show All 20 Lines | |||||||||
void SaveGamePrefix(const ScriptRequest& rq, const std::wstring& prefix, const std::wstring& description, JS::HandleValue GUIMetadata) | void SaveGamePrefix(const ScriptRequest& rq, const std::wstring& prefix, const std::wstring& description, JS::HandleValue GUIMetadata) | ||||||||
{ | { | ||||||||
Script::StructuredClone GUIMetadataClone = Script::WriteStructuredClone(rq, GUIMetadata); | Script::StructuredClone GUIMetadataClone = Script::WriteStructuredClone(rq, GUIMetadata); | ||||||||
if (SavedGames::SavePrefix(prefix, description, *g_Game->GetSimulation2(), GUIMetadataClone) < 0) | if (SavedGames::SavePrefix(prefix, description, *g_Game->GetSimulation2(), GUIMetadataClone) < 0) | ||||||||
LOGERROR("Failed to save game"); | LOGERROR("Failed to save game"); | ||||||||
} | } | ||||||||
void QuickSave(JS::HandleValue GUIMetadata) | void QuickSave(const ScriptRequest& rq, JS::HandleValue GUIMetadata) | ||||||||
{ | { | ||||||||
if (g_NetServer || g_NetClient) | if (!g_Game) | ||||||||
Stan: I suppose this should be translated too if the other are. | |||||||||
LOGERROR("Can't store quicksave during multiplayer!"); | LOGERROR(g_L10n.Translate("Can't store quicksave if game is not running!")); | ||||||||
else if (g_Game) | else if (g_NetServer || g_NetClient) | ||||||||
Done Inline Actions!= INFO::Ok ? Stan: != INFO::Ok ? | |||||||||
g_Game->GetTurnManager()->QuickSave(GUIMetadata); | LOGERROR(g_L10n.Translate("Can't store quicksave during multiplayer!")); | ||||||||
Done Inline ActionsI suppose this should be translated too if the other are. Stan: I suppose this should be translated too if the other are. | |||||||||
else | else | ||||||||
LOGERROR("Can't store quicksave if game is not running!"); | { | ||||||||
Script::StructuredClone GUIMetadataClone = Script::WriteStructuredClone(rq, GUIMetadata); | |||||||||
if (SavedGames::QuickSave(*g_Game->GetSimulation2(), GUIMetadataClone) != INFO::OK) | |||||||||
LOGERROR(g_L10n.Translate("Failed to quicksave game")); | |||||||||
} | |||||||||
} | } | ||||||||
void QuickLoad() | void QuickLoad() | ||||||||
{ | { | ||||||||
if (g_NetServer || g_NetClient) | if (g_NetServer || g_NetClient) | ||||||||
LOGERROR("Can't load quicksave during multiplayer!"); | LOGERROR(g_L10n.Translate("Can't load quicksave during multiplayer!")); | ||||||||
Done Inline ActionsIt is now possible to load a quicksave if the game is not running. phosit: It is now possible to load a quicksave if the game is not running. | |||||||||
Done Inline ActionsI suppose this should be translated too if the other are. Stan: I suppose this should be translated too if the other are. | |||||||||
else if (g_Game) | |||||||||
g_Game->GetTurnManager()->QuickLoad(); | |||||||||
else | else | ||||||||
Done Inline Actions!= INFO::Ok ? Stan: != INFO::Ok ? | |||||||||
LOGERROR("Can't load quicksave if game is not running!"); | { | ||||||||
Done Inline Actionsthis message is redundant Silier: this message is redundant | |||||||||
Status status = SavedGames::QuickLoad(*g_Game->GetSimulation2()); | |||||||||
if (status == INFO::OK) | |||||||||
LOGMESSAGERENDER(g_L10n.Translate("Game loaded")); | |||||||||
else if (status == INFO::CANNOT_HANDLE) | |||||||||
LOGERROR(g_L10n.Translate("Cannot quickload game - current match is not quicksaved")); | |||||||||
Done Inline Actions
is or was, i think both would work Silier: is or was, i think both would work | |||||||||
else | |||||||||
LOGERROR(g_L10n.Translate("Failed to quickload game")); | |||||||||
} | |||||||||
} | } | ||||||||
JS::Value StartSavedGame(const ScriptInterface& scriptInterface, const std::wstring& name) | JS::Value StartSavedGame(const ScriptInterface& scriptInterface, const std::wstring& name) | ||||||||
{ | { | ||||||||
// We need to be careful with different compartments and contexts. | // We need to be careful with different compartments and contexts. | ||||||||
// The GUI calls this function from the GUI context and expects the return value in the same context. | // The GUI calls this function from the GUI context and expects the return value in the same context. | ||||||||
// The game we start from here creates another context and expects data in this context. | // The game we start from here creates another context and expects data in this context. | ||||||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
I suppose this should be translated too if the other are.