forked from 0ad/0ad
Gallaecio
e05c8263c5
It includes a marvelous language selection menu developed by Yves. It also includes the introduction of a sprintf implementation for JavaScript, as well as translation helper functions that use JavaScript-side translation caching. This patch includes code by Yves, sanderd17, leper and Gallaecio. Ref #67 This was SVN commit r14954.
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
function sortDecreasingDate(a, b)
|
|
{
|
|
return b.metadata.time - a.metadata.time;
|
|
}
|
|
|
|
function generateLabel(metadata, engineInfo)
|
|
{
|
|
var dateTimeString = Engine.FormatMillisecondsIntoDateString(metadata.time*1000, translate("yyyy-MM-dd HH:mm:ss"));
|
|
var dateString = sprintf(translate("[%(date)s]"), { date: dateTimeString });
|
|
if (engineInfo)
|
|
{
|
|
if (!hasSameVersion(metadata, engineInfo))
|
|
dateString = "[color=\"red\"]" + dateString + "[/color]";
|
|
else if (!hasSameMods(metadata, engineInfo))
|
|
dateString = "[color=\"orange\"]" + dateString + "[/color]";
|
|
}
|
|
if (metadata.description)
|
|
return sprintf(translate("%(dateString)s %(map)s - %(description)s"), { dateString: dateString, map: metadata.initAttributes.map, description: metadata.description });
|
|
else
|
|
return sprintf(translate("%(dateString)s %(map)s"), { dateString: dateString, map: metadata.initAttributes.map });
|
|
}
|
|
|
|
/**
|
|
* Check the version compatibility between the saved game to be loaded and the engine
|
|
*/
|
|
function hasSameVersion(metadata, engineInfo)
|
|
{
|
|
return (metadata.version_major == engineInfo.version_major);
|
|
}
|
|
|
|
/**
|
|
* Check the mod compatibility between the saved game to be loaded and the engine
|
|
*/
|
|
function hasSameMods(metadata, engineInfo)
|
|
{
|
|
if (!metadata.mods) // only here for backwards compatibility with previous saved games
|
|
var gameMods = [];
|
|
else
|
|
var gameMods = metadata.mods;
|
|
|
|
if (gameMods.length != engineInfo.mods.length)
|
|
return false;
|
|
for (var i = 0; i < gameMods.length; ++i)
|
|
if (gameMods[i] != engineInfo.mods[i])
|
|
return false;
|
|
return true;
|
|
}
|