0ad/binaries/data/mods/public/gui/loadgame/SavegameLoader.js
Dunedan 93ce94655d
Use @stylistic/brace-style for eslint
Up to now `eslint-plugin-brace-rules` was used to enforce a common brace
style for JavaScript code. This plugin was however updated the last time
over 9 years ago and will be incompatible with ESLint v10, as that
[removes `context.getSourceCode()`][1], the plugin relies on.

To keep the eslint config working with ESLint v10, this replaces
`eslint-plugin-brace-rules` with the [`@stylistic/brace-style`][2] rule
from `@stylistic/eslint-plugin`, a package we already use.

While `@stylistic/brace-style` doesn't offer an option to format braces
in exactly the same way as before, the "allman" style seems to be the
one closest to the existing code.

[1]: https://eslint.org/blog/2025/11/eslint-v10.0.0-alpha.0-released/#removed-deprecated-rule-context-members
[2]: https://eslint.style/rules/brace-style
2026-01-12 21:33:52 +01:00

70 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* This class is responsible for display and performance of the Load button.
*/
class SavegameLoader
{
constructor(closePageCallback)
{
this.closePageCallback = closePageCallback;
this.confirmButton = Engine.GetGUIObjectByName("confirmButton");
this.confirmButton.caption = translate("Load");
this.confirmButton.enabled = false;
}
onSelectionChange(gameID, metadata, label)
{
this.confirmButton.enabled = !!metadata;
this.confirmButton.onPress = () =>
{
this.loadGame(gameID, metadata);
};
}
async loadGame(gameId, metadata)
{
// Check compatibility before really loading it
const engineInfo = Engine.GetEngineInfo();
const sameMods = hasSameMods(metadata.mods, engineInfo.mods);
const compatibleEngineVersions = metadata.engine_serialization_version && metadata.engine_serialization_version == engineInfo.engine_serialization_version;
if (compatibleEngineVersions && sameMods)
{
this.closePageCallback(gameId);
return;
}
// Version not compatible ... ask for confirmation
let message = "";
if (!compatibleEngineVersions)
{
if (metadata.engine_serialization_version)
message += sprintf(translate("This savegame needs 0 A.D. version %(requiredCompatibleVersion)s or compatible. You are running version %(currentVersion)s, compatible down to %(compatibleVersion)s."), {
"requiredCompatibleVersion": metadata.engine_serialization_version,
"currentVersion": engineInfo.engine_version,
"compatibleVersion": engineInfo.engine_serialization_version,
}) + "\n";
else
message += translate("This savegame needs an older version of 0 A.D.") + "\n";
}
if (!sameMods)
{
if (!metadata.mods)
metadata.mods = [];
message += translate("This savegame needs a different sequence of mods:") + "\n" +
comparedModsString(metadata.mods, engineInfo.mods) + "\n";
}
message += translate("Do you still want to proceed?");
const buttonIndex = await messageBox(
500, 250,
message,
translate("Warning"),
[translate("No"), translate("Yes")]);
if (buttonIndex === 1)
this.closePageCallback(gameId);
}
}