Index: ps/trunk/source/i18n/scripting/JSInterface_L10n.cpp
===================================================================
--- ps/trunk/source/i18n/scripting/JSInterface_L10n.cpp (revision 24993)
+++ ps/trunk/source/i18n/scripting/JSInterface_L10n.cpp (revision 24994)
@@ -1,101 +1,102 @@
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 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
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see .
*/
#include "precompiled.h"
#include "JSInterface_L10n.h"
#include "i18n/L10n.h"
#include "lib/utf8.h"
+#include "ps/CLogger.h"
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/ScriptInterface.h"
namespace JSI_L10n
{
L10n* L10nGetter(const ScriptRequest&, JS::CallArgs&)
{
if (!g_L10n.IsInitialised())
{
LOGERROR("Trying to access g_L10n when it's not initialized!");
return nullptr;
}
return &g_L10n.GetSingleton();
}
std::vector TranslateArray(const std::vector& sourceArray)
{
std::vector translatedArray;
if (g_L10n.IsInitialised())
for (const std::string& elem : sourceArray)
translatedArray.push_back(g_L10n.Translate(elem));
return translatedArray;
}
// Return a localized version of a time given in milliseconds.
std::string FormatMillisecondsIntoDateStringLocal(UDate milliseconds, const std::string& formatString)
{
return g_L10n.FormatMillisecondsIntoDateString(milliseconds, formatString, true);
}
// Return a localized version of a duration or a time in GMT given in milliseconds.
std::string FormatMillisecondsIntoDateStringGMT(UDate milliseconds, const std::string& formatString)
{
return g_L10n.FormatMillisecondsIntoDateString(milliseconds, formatString, false);
}
void RegisterScriptFunctions(const ScriptRequest& rq)
{
#define REGISTER_L10N(name) \
ScriptFunction::Register<&L10n::name, &L10nGetter>(rq, #name);
#define REGISTER_L10N_FUNC(func, name) \
ScriptFunction::Register(rq, name);
REGISTER_L10N(Translate)
REGISTER_L10N(TranslateWithContext)
REGISTER_L10N(TranslatePlural)
REGISTER_L10N(TranslatePluralWithContext)
REGISTER_L10N(TranslateLines)
ScriptFunction::Register<&TranslateArray>(rq, "TranslateArray");
ScriptFunction::Register<&FormatMillisecondsIntoDateStringLocal>(rq, "FormatMillisecondsIntoDateStringLocal");
ScriptFunction::Register<&FormatMillisecondsIntoDateStringGMT>(rq, "FormatMillisecondsIntoDateStringGMT");
REGISTER_L10N(FormatDecimalNumberIntoString)
REGISTER_L10N(GetSupportedLocaleBaseNames)
REGISTER_L10N(GetSupportedLocaleDisplayNames)
REGISTER_L10N_FUNC(&L10n::GetCurrentLocaleString, "GetCurrentLocale");
REGISTER_L10N(GetAllLocales)
// Select the appropriate overload.
REGISTER_L10N_FUNC(static_cast(&L10n::GetDictionaryLocale), "GetDictionaryLocale");
REGISTER_L10N(GetDictionariesForLocale)
REGISTER_L10N(UseLongStrings)
REGISTER_L10N(GetLocaleLanguage)
REGISTER_L10N(GetLocaleBaseName)
REGISTER_L10N(GetLocaleCountry)
REGISTER_L10N(GetLocaleScript)
// Select the appropriate overload.
REGISTER_L10N_FUNC(static_cast(&L10n::GetFallbackToAvailableDictLocale), "GetFallbackToAvailableDictLocale");
// Select the appropriate overloads.
REGISTER_L10N_FUNC(static_cast(&L10n::ValidateLocale), "ValidateLocale");
REGISTER_L10N_FUNC(static_cast(&L10n::SaveLocale), "SaveLocale");
REGISTER_L10N(ReevaluateCurrentLocaleAndReload)
#undef REGISTER_L10N
#undef REGISTER_L10N_FUNC
}
}
Index: ps/trunk/source/ps/VisualReplay.h
===================================================================
--- ps/trunk/source/ps/VisualReplay.h (revision 24993)
+++ ps/trunk/source/ps/VisualReplay.h (revision 24994)
@@ -1,126 +1,128 @@
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 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
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see .
*/
#ifndef INCLUDED_VISUAL_REPLAY
#define INCLUDED_VISUAL_REPLAY
#include "lib/os_path.h"
+#include "scriptinterface/ScriptTypes.h"
class CSimulation2;
class CGUIManager;
+class CStrW;
class ScriptInterface;
/**
* Contains functions for visually replaying past games.
*/
namespace VisualReplay
{
/**
* Returns the absolute path to the sim-log directory (that contains the directories with the replay files.
*/
OsPath GetDirectoryPath();
/**
* Returns the absolute path to the replay cache file.
*/
OsPath GetCacheFilePath();
/**
* Returns the absolute path to the temporary replay cache file used to
* always have a valid cache file in place even if bad things happen.
*/
OsPath GetTempCacheFilePath();
/**
* Replays the commands.txt file in the given subdirectory visually.
*/
bool StartVisualReplay(const OsPath& directory);
/**
* Reads the replay Cache file and parses it into a jsObject
*
* @param scriptInterface - the ScriptInterface in which to create the return data.
* @param cachedReplaysObject - the cached replays.
* @return true on succes
*/
bool ReadCacheFile(const ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject);
/**
* Stores the replay list in the replay cache file
*
* @param scriptInterface - the ScriptInterface in which to create the return data.
* @param replays - the replay list to store.
*/
void StoreCacheFile(const ScriptInterface& scriptInterface, JS::HandleObject replays);
/**
* Load the replay cache and check if there are new/deleted replays. If so, update the cache.
*
* @param scriptInterface - the ScriptInterface in which to create the return data.
* @param compareFiles - compare the directory name and the FileSize of the replays and the cache.
* @return cache entries
*/
JS::HandleObject ReloadReplayCache(const ScriptInterface& scriptInterface, bool compareFiles);
/**
* Get a list of replays to display in the GUI.
*
* @param scriptInterface - the ScriptInterface in which to create the return data.
* @param compareFiles - reload the cache, which takes more time,
* but nearly ensures, that no changed replay is missed.
* @return array of objects containing replay data
*/
JS::Value GetReplays(const ScriptInterface& scriptInterface, bool compareFiles);
/**
* Parses a commands.txt file and extracts metadata.
* Works similarly to CGame::LoadReplayData().
*/
JS::Value LoadReplayData(const ScriptInterface& scriptInterface, const OsPath& directory);
/**
* Permanently deletes the visual replay (including the parent directory)
*
* @param replayFile - path to commands.txt, whose parent directory will be deleted.
* @return true if deletion was successful, false on error
*/
bool DeleteReplay(const OsPath& replayFile);
/**
* Returns the parsed header of the replay file (commands.txt).
*/
JS::Value GetReplayAttributes(const ScriptInterface& scriptInterface, const OsPath& directoryName);
/**
* Returns whether or not the metadata / summary screen data has been saved properly when the game ended.
*/
bool HasReplayMetadata(const OsPath& directoryName);
/**
* Returns the metadata of a replay.
*/
JS::Value GetReplayMetadata(const ScriptInterface& scriptInterface, const OsPath& directoryName);
/**
* Adds a replay to the replayCache.
*/
void AddReplayToCache(const ScriptInterface& scriptInterface, const CStrW& directoryName);
}
#endif