Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/mod/gui/common/mod.js
/** | /** | ||||
* Check the mod compatibility between the saved game to be loaded and the engine | * Check the mod compatibility between the saved game to be loaded and the engine. | ||||
* This is a wrapper around an engine function to allow mods to to fancier or specific things. | |||||
*/ | */ | ||||
function hasSameMods(modsA, modsB) | function hasSameMods(modsA, modsB) | ||||
{ | { | ||||
if (!modsA || !modsB || modsA.length != modsB.length) | if (!modsA || !modsB) | ||||
return false; | return false; | ||||
// Mods must be loaded in the same order. 0: modname, 1: modversion | return Engine.AreModsPlayCompatible(modsA, modsB); | ||||
return modsA.every((mod, index) => [0, 1].every(i => mod[i] == modsB[index][i])); | } | ||||
/** | |||||
* Print the shorthand identifier of a mod. | |||||
*/ | |||||
function modToString(mod) | |||||
{ | |||||
// Skip version for play-compatible mods. | |||||
if (mod.ignoreInCompatibilityChecks) | |||||
return mod.name; | |||||
return sprintf(translateWithContext("Mod comparison", "%(mod)s (%(version)s)"), { | |||||
"mod": mod.name, | |||||
"version": mod.version | |||||
}); | |||||
} | } | ||||
/** | /** | ||||
* Converts a list of mods and their version into a human-readable string. | * Converts a list of mods and their version into a human-readable string. | ||||
*/ | */ | ||||
function modsToString(mods) | function modsToString(mods) | ||||
{ | { | ||||
return mods.map(mod => sprintf(translateWithContext("Mod comparison", "%(mod)s (%(version)s)"), { | return mods.map(mod => modToString(mod)).join(translate(", ")); | ||||
"mod": mod[0], | |||||
"version": mod[1] | |||||
})).join(translate(", ")); | |||||
} | } | ||||
/** | /** | ||||
* Convert the required and active mods and their version into a humanreadable translated string. | * Convert the required and active mods and their version into a humanreadable translated string. | ||||
*/ | */ | ||||
function comparedModsString(required, active) | function comparedModsString(required, active) | ||||
{ | { | ||||
return sprintf(translateWithContext("Mod comparison", "Required: %(mods)s"), | return sprintf(translateWithContext("Mod comparison", "Required: %(mods)s"), | ||||
{ "mods": modsToString(required) }) + "\n" + | { "mods": modsToString(required) } | ||||
sprintf(translateWithContext("Mod comparison", "Active: %(mods)s"), | ) + "\n" + sprintf(translateWithContext("Mod comparison", "Active: %(mods)s"), | ||||
{ "mods": modsToString(active) }); | { "mods": modsToString(active) }); | ||||
} | } |
Wildfire Games · Phabricator