Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/common/gamedescription.js
Show All 28 Lines | |||||
*/ | */ | ||||
var g_Buddies = Engine.ConfigDB_GetValue("user", "lobby.buddies").split(g_BuddyListDelimiter); | var g_Buddies = Engine.ConfigDB_GetValue("user", "lobby.buddies").split(g_BuddyListDelimiter); | ||||
/** | /** | ||||
* Denotes which players are a lobby buddy of the current user. | * Denotes which players are a lobby buddy of the current user. | ||||
*/ | */ | ||||
var g_BuddySymbol = '•'; | var g_BuddySymbol = '•'; | ||||
var g_MapPreviewPath = "session/icons/mappreview/"; | |||||
/** | |||||
* Returns the biome specific mappreview image if it exists, or empty string otherwise. | |||||
*/ | |||||
function getBiomePreview(mapName, biomeName) | |||||
{ | |||||
let biomePreview = basename(mapName) + "_" + basename(biomeName) + ".png"; | |||||
if (Engine.TextureExists("art/textures/ui/" + g_MapPreviewPath + biomePreview)) | |||||
return biomePreview; | |||||
return ""; | |||||
} | |||||
/** | |||||
* Returns map description and preview image or placeholder. | |||||
*/ | |||||
function getMapDescriptionAndPreview(mapType, mapName, gameAttributes = undefined) | |||||
{ | |||||
let mapData; | |||||
if (mapType == "random" && mapName == "random") | |||||
mapData = { "settings": { "Description": translate("A randomly selected map.") } }; | |||||
else if (mapType == "random" && Engine.FileExists(mapName + ".json")) | |||||
mapData = Engine.ReadJSONFile(mapName + ".json"); | |||||
else if (Engine.FileExists(mapName + ".xml")) | |||||
mapData = Engine.LoadMapSettings(mapName + ".xml"); | |||||
let biomePreview = getBiomePreview(mapName, gameAttributes && gameAttributes.settings.Biome || ""); | |||||
return deepfreeze({ | |||||
"description": mapData && mapData.settings && mapData.settings.Description ? translate(mapData.settings.Description) : translate("Sorry, no description available."), | |||||
"preview": biomePreview ? biomePreview : | |||||
mapData && mapData.settings && mapData.settings.Preview ? mapData.settings.Preview : "nopreview.png" | |||||
}); | |||||
} | |||||
/** | |||||
* Sets the mappreview image correctly. | |||||
* It needs to be cropped as the engine only allows loading square textures. | |||||
* | |||||
* @param {string} filename | |||||
*/ | |||||
function getMapPreviewImage(filename) | |||||
{ | |||||
return "cropped:" + 400 / 512 + "," + 300 / 512 + ":" + | |||||
g_MapPreviewPath + filename; | |||||
} | |||||
/** | /** | ||||
* Returns a formatted string describing the player assignments. | * Returns a formatted string describing the player assignments. | ||||
* Needs g_CivData to translate! | * Needs g_CivData to translate! | ||||
* | * | ||||
* @param {object} playerDataArray - As known from gamesetup and simstate. | * @param {object} playerDataArray - As known from gamesetup and simstate. | ||||
* @param {(string[]|false)} playerStates - One of "won", "defeated", "active" for each player. | * @param {(string[]|false)} playerStates - One of "won", "defeated", "active" for each player. | ||||
* @returns {string} | * @returns {string} | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | function formatPlayerInfo(playerDataArray, playerStates) | ||||
return teamDescription.join("\n\n"); | return teamDescription.join("\n\n"); | ||||
} | } | ||||
/** | /** | ||||
* Sets an additional map label, map preview image and describes the chosen gamesettings more closely. | * Sets an additional map label, map preview image and describes the chosen gamesettings more closely. | ||||
* | * | ||||
* Requires g_GameAttributes and g_VictoryConditions. | * Requires g_GameAttributes and g_VictoryConditions. | ||||
*/ | */ | ||||
function getGameDescription() | function getGameDescription(mapCache) | ||||
{ | { | ||||
if (!g_GameAttributes.settings) | |||||
return ""; | |||||
let titles = []; | let titles = []; | ||||
if (!g_GameAttributes.settings.VictoryConditions.length) | if (!g_GameAttributes.settings.VictoryConditions || | ||||
!g_GameAttributes.settings.VictoryConditions.length) | |||||
titles.push({ | titles.push({ | ||||
"label": translateWithContext("victory condition", "Endless Game"), | "label": translateWithContext("victory condition", "Endless Game"), | ||||
"value": translate("No winner will be determined, even if everyone is defeated.") | "value": translate("No winner will be determined, even if everyone is defeated.") | ||||
}); | }); | ||||
if (g_GameAttributes.settings.VictoryConditions) | |||||
Stan: Missing indent. | |||||
Done Inline ActionsSee summary elexis: See summary | |||||
for (let victoryCondition of g_VictoryConditions) | for (let victoryCondition of g_VictoryConditions) | ||||
{ | { | ||||
if (g_GameAttributes.settings.VictoryConditions.indexOf(victoryCondition.Name) == -1) | if (g_GameAttributes.settings.VictoryConditions.indexOf(victoryCondition.Name) == -1) | ||||
continue; | continue; | ||||
let title = translateVictoryCondition(victoryCondition.Name); | let title = translateVictoryCondition(victoryCondition.Name); | ||||
if (victoryCondition.Name == "wonder") | if (victoryCondition.Name == "wonder") | ||||
title = sprintf( | title = sprintf( | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | titles.push({ | ||||
"value": translate("Only one player can win the game. If the remaining players are allies, the game continues until only one remains.") | "value": translate("Only one player can win the game. If the remaining players are allies, the game continues until only one remains.") | ||||
}); | }); | ||||
else | else | ||||
titles.push({ | titles.push({ | ||||
"label": translate("Allied Victory"), | "label": translate("Allied Victory"), | ||||
"value": translate("If one player wins, his or her allies win too. If one group of allies remains, they win.") | "value": translate("If one player wins, his or her allies win too. If one group of allies remains, they win.") | ||||
}); | }); | ||||
if (g_GameAttributes.settings.Ceasefire !== undefined) | |||||
titles.push({ | titles.push({ | ||||
"label": translate("Ceasefire"), | "label": translate("Ceasefire"), | ||||
"value": | "value": | ||||
g_GameAttributes.settings.Ceasefire == 0 ? | g_GameAttributes.settings.Ceasefire == 0 ? | ||||
translate("disabled") : | translate("disabled") : | ||||
sprintf(translatePlural( | sprintf(translatePlural( | ||||
"For the first minute, other players will stay neutral.", | "For the first minute, other players will stay neutral.", | ||||
"For the first %(min)s minutes, other players will stay neutral.", | "For the first %(min)s minutes, other players will stay neutral.", | ||||
g_GameAttributes.settings.Ceasefire), | g_GameAttributes.settings.Ceasefire), | ||||
{ "min": g_GameAttributes.settings.Ceasefire }) | { "min": g_GameAttributes.settings.Ceasefire }) | ||||
}); | }); | ||||
if (g_GameAttributes.map == "random") | if (g_GameAttributes.map !== undefined && g_GameAttributes.map == "random") | ||||
titles.push({ | titles.push({ | ||||
Not Done Inline ActionsMissing indent. Stan: Missing indent. | |||||
Done Inline ActionsSee summary elexis: See summary | |||||
"label": translateWithContext("Map Selection", "Random Map"), | "label": translateWithContext("Map Selection", "Random Map"), | ||||
"value": translate("Randomly select a map from the list.") | "value": translate("Randomly select a map from the list.") | ||||
}); | }); | ||||
else | else if (g_GameAttributes.mapType && g_GameAttributes.map) | ||||
{ | { | ||||
titles.push({ | titles.push({ | ||||
"label": translate("Map Name"), | "label": translate("Map Name"), | ||||
"value": translate(g_GameAttributes.settings.Name) | "value": mapCache.translateMapName( | ||||
mapCache.getTranslatableMapName(g_GameAttributes.mapType, g_GameAttributes.map, g_GameAttributes)) | |||||
}); | }); | ||||
titles.push({ | titles.push({ | ||||
"label": translate("Map Description"), | "label": translate("Map Description"), | ||||
"value": g_GameAttributes.settings.Description ? | "value": mapCache.getTranslatedMapDescription(g_GameAttributes.mapType, g_GameAttributes.map) | ||||
translate(g_GameAttributes.settings.Description) : | |||||
translate("Sorry, no description available.") | |||||
}); | }); | ||||
} | } | ||||
if (g_GameAttributes.mapType) | |||||
titles.push({ | titles.push({ | ||||
"label": translate("Map Type"), | "label": translate("Map Type"), | ||||
"value": g_MapTypes.Title[g_MapTypes.Name.indexOf(g_GameAttributes.mapType)] | "value": g_MapTypes.Title[g_MapTypes.Name.indexOf(g_GameAttributes.mapType)] | ||||
}); | }); | ||||
if (typeof g_MapFilterList !== "undefined") | if (g_GameAttributes.mapType == "random" && g_GameAttributes.settings.Size) | ||||
titles.push({ | |||||
"label": translate("Map Filter"), | |||||
"value": g_MapFilterList.name[g_MapFilterList.id.findIndex(id => id == g_GameAttributes.mapFilter)] | |||||
}); | |||||
Done Inline ActionsWhile MapFilters are very slightly useful to be informed about in the gamesetup stage for clients, they aren't a setting that determines simulation state nor has it other relevance for the played game, so it does not match the objectives of the objectives dialog / gamedescription function. elexis: While MapFilters are very slightly useful to be informed about in the gamesetup stage for… | |||||
if (g_GameAttributes.mapType == "random") | |||||
{ | { | ||||
let mapSize = g_MapSizes.Name[g_MapSizes.Tiles.indexOf(g_GameAttributes.settings.Size)]; | let mapSize = g_MapSizes.Name[g_MapSizes.Tiles.indexOf(g_GameAttributes.settings.Size)]; | ||||
if (mapSize) | if (mapSize) | ||||
titles.push({ | titles.push({ | ||||
"label": translate("Map Size"), | "label": translate("Map Size"), | ||||
"value": mapSize | "value": mapSize | ||||
}); | }); | ||||
} | } | ||||
Show All 11 Lines | function getGameDescription(mapCache) | ||||
{ | { | ||||
let triggerDifficulty = g_Settings.TriggerDifficulties.find(difficulty => difficulty.Difficulty == g_GameAttributes.settings.TriggerDifficulty); | let triggerDifficulty = g_Settings.TriggerDifficulties.find(difficulty => difficulty.Difficulty == g_GameAttributes.settings.TriggerDifficulty); | ||||
titles.push({ | titles.push({ | ||||
"label": triggerDifficulty.Title, | "label": triggerDifficulty.Title, | ||||
"value": triggerDifficulty.Tooltip | "value": triggerDifficulty.Tooltip | ||||
}); | }); | ||||
} | } | ||||
if (g_GameAttributes.settings.Nomad !== undefined) | |||||
titles.push({ | titles.push({ | ||||
"label": g_GameAttributes.settings.Nomad ? translate("Nomad Mode") : translate("Civic Centers"), | "label": g_GameAttributes.settings.Nomad ? translate("Nomad Mode") : translate("Civic Centers"), | ||||
"value": | "value": | ||||
g_GameAttributes.settings.Nomad ? | g_GameAttributes.settings.Nomad ? | ||||
translate("Players start with only few units and have to find a suitable place to build their city.") : | translate("Players start with only few units and have to find a suitable place to build their city.") : | ||||
translate("Players start with a Civic Center.") | translate("Players start with a Civic Center.") | ||||
}); | }); | ||||
if (g_GameAttributes.settings.StartingResources !== undefined) | |||||
titles.push({ | titles.push({ | ||||
"label": translate("Starting Resources"), | "label": translate("Starting Resources"), | ||||
"value": sprintf(translate("%(startingResourcesTitle)s (%(amount)s)"), { | "value": | ||||
g_GameAttributes.settings.PlayerData && | |||||
g_GameAttributes.settings.PlayerData.some(pData => pData && pData.Resources !== undefined) ? | |||||
translateWithContext("starting resources", "Per Player") : | |||||
sprintf(translate("%(startingResourcesTitle)s (%(amount)s)"), { | |||||
"startingResourcesTitle": | "startingResourcesTitle": | ||||
g_StartingResources.Title[ | g_StartingResources.Title[ | ||||
g_StartingResources.Resources.indexOf( | g_StartingResources.Resources.indexOf( | ||||
g_GameAttributes.settings.StartingResources)], | g_GameAttributes.settings.StartingResources)], | ||||
"amount": g_GameAttributes.settings.StartingResources | "amount": g_GameAttributes.settings.StartingResources | ||||
}) | }) | ||||
}); | }); | ||||
if (g_GameAttributes.settings.PopulationCap !== undefined) | |||||
titles.push({ | titles.push({ | ||||
"label": translate("Population Limit"), | "label": translate("Population Limit"), | ||||
"value": | "value": | ||||
g_GameAttributes.settings.PlayerData && | |||||
g_GameAttributes.settings.PlayerData.some(pData => pData && pData.PopulationLimit !== undefined) ? | |||||
translateWithContext("population limit", "Per Player") : | |||||
g_PopulationCapacities.Title[ | g_PopulationCapacities.Title[ | ||||
g_PopulationCapacities.Population.indexOf( | g_PopulationCapacities.Population.indexOf( | ||||
g_GameAttributes.settings.PopulationCap)] | g_GameAttributes.settings.PopulationCap)] | ||||
}); | }); | ||||
if (g_GameAttributes.settings.DisableTreasures !== undefined) | |||||
titles.push({ | titles.push({ | ||||
"label": translate("Treasures"), | "label": translate("Treasures"), | ||||
"value": g_GameAttributes.settings.DisableTreasures ? | "value": g_GameAttributes.settings.DisableTreasures ? | ||||
translateWithContext("treasures", "Disabled") : | translateWithContext("treasures", "Disabled") : | ||||
translateWithContext("treasures", "As defined by the map.") | translateWithContext("treasures", "As defined by the map.") | ||||
}); | }); | ||||
if (g_GameAttributes.settings.RevealMap !== undefined) | |||||
titles.push({ | titles.push({ | ||||
"label": translate("Revealed Map"), | "label": translate("Revealed Map"), | ||||
"value": g_GameAttributes.settings.RevealMap | "value": g_GameAttributes.settings.RevealMap | ||||
}); | }); | ||||
if (g_GameAttributes.settings.ExploreMap !== undefined) | |||||
titles.push({ | titles.push({ | ||||
"label": translate("Explored Map"), | "label": translate("Explored Map"), | ||||
"value": g_GameAttributes.settings.ExploreMap | "value": g_GameAttributes.settings.ExploreMap | ||||
}); | }); | ||||
if (g_GameAttributes.settings.CheatsEnabled !== undefined) | |||||
titles.push({ | titles.push({ | ||||
"label": translate("Cheats"), | "label": translate("Cheats"), | ||||
"value": g_GameAttributes.settings.CheatsEnabled | "value": g_GameAttributes.settings.CheatsEnabled | ||||
}); | }); | ||||
return titles.map(title => sprintf(translate("%(label)s %(details)s"), { | return titles.map(title => sprintf(translate("%(label)s %(details)s"), { | ||||
"label": coloredText(title.label, g_DescriptionHighlight), | "label": coloredText(title.label, g_DescriptionHighlight), | ||||
"details": | "details": | ||||
Show All 33 Lines |
Wildfire Games · Phabricator
Missing indent.