Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/common/functions_utility_loadsave.js
Show All 30 Lines | |||||
/** | /** | ||||
* Check the version compatibility between the saved game to be loaded and the engine | * Check the version compatibility between the saved game to be loaded and the engine | ||||
*/ | */ | ||||
function hasSameEngineVersion(metadata, engineInfo) | function hasSameEngineVersion(metadata, engineInfo) | ||||
{ | { | ||||
return metadata.engine_version && metadata.engine_version == engineInfo.engine_version; | return metadata.engine_version && metadata.engine_version == engineInfo.engine_version; | ||||
} | } | ||||
/** | |||||
* Check the mod compatibility between the saved game to be loaded and the engine | |||||
* | |||||
* @param metadata {string[]} | |||||
* @param engineInfo {string[]} | |||||
* @returns {boolean} | |||||
*/ | |||||
function hasSameMods(metadata, engineInfo) | |||||
{ | |||||
if (!metadata.mods || !engineInfo.mods) | |||||
return false; | |||||
// Ignore the "user" mod which is loaded for releases but not working-copies | |||||
let modsA = metadata.mods.filter(mod => mod != "user"); | |||||
let modsB = engineInfo.mods.filter(mod => mod != "user"); | |||||
if (modsA.length != modsB.length) | |||||
return false; | |||||
// Mods must be loaded in the same order | |||||
return modsA.every((mod, index) => mod == modsB[index]); | |||||
} | |||||
function deleteGame() | function deleteGame() | ||||
elexis: (This sounds like it should be in common/gui/mods/ or something, anyway. `gui/common/` is… | |||||
Done Inline ActionsWe soon will also have a function to validate the properties of a mod file. That code is not only relevant for the mod selection screen but for instance to test mod validity before launching mods when joining a modded MP game. elexis: We soon will also have a function to validate the properties of a mod file. That code is not… | |||||
{ | { | ||||
let gameSelection = Engine.GetGUIObjectByName("gameSelection"); | let gameSelection = Engine.GetGUIObjectByName("gameSelection"); | ||||
let gameID = gameSelection.list_data[gameSelection.selected]; | let gameID = gameSelection.list_data[gameSelection.selected]; | ||||
if (!gameID) | if (!gameID) | ||||
return; | return; | ||||
if (Engine.HotkeyIsPressed("session.savedgames.noconfirmation")) | if (Engine.HotkeyIsPressed("session.savedgames.noconfirmation")) | ||||
reallyDeleteGame(gameID); | reallyDeleteGame(gameID); | ||||
else | else | ||||
messageBox( | messageBox( | ||||
500, 200, | 500, 200, | ||||
Done Inline Actionsfor (let [mods, version] of [[metadata.mods, engineInfo.versions], [metadata_whatever, engine_otherone]) reduces 6 to 10 lines of code possibly, perhaps we end up with a single return :D elexis: `for (let [mods, version] of [[metadata.mods, engineInfo.versions], [metadata_whatever… | |||||
Done Inline ActionsThis elexis: This | |||||
sprintf(translate("\"%(label)s\""), { | sprintf(translate("\"%(label)s\""), { | ||||
"label": gameSelection.list[gameSelection.selected] | "label": gameSelection.list[gameSelection.selected] | ||||
}) + "\n" + translate("Saved game will be permanently deleted, are you sure?"), | }) + "\n" + translate("Saved game will be permanently deleted, are you sure?"), | ||||
translate("DELETE"), | translate("DELETE"), | ||||
[translate("No"), translate("Yes")], | [translate("No"), translate("Yes")], | ||||
[null, function(){ reallyDeleteGame(gameID); }] | [null, function(){ reallyDeleteGame(gameID); }] | ||||
); | ); | ||||
} | } | ||||
Show All 23 Lines |
Wildfire Games · Phabricator
(This sounds like it should be in common/gui/mods/ or something, anyway. gui/common/ is impossible to sort)