Gamesetup OOP cleanup, refs #5322.

Move procedural updateGameDescription and getMapPreview to OOP
g_MiscControls from b4e5858f6d/D322.
Delete unused variable childSize following ac7b5ce861.
Remove host check in launchGame from 1c0536bf08 needless since
d1d7afe46c.

This was SVN commit r22826.
This commit is contained in:
elexis 2019-09-01 15:35:10 +00:00
parent 67795d4451
commit 398475b4ef
5 changed files with 23 additions and 44 deletions

View file

@ -75,13 +75,11 @@ function getMapDescriptionAndPreview(mapType, mapName, gameAttributes = undefine
* Sets the mappreview image correctly.
* It needs to be cropped as the engine only allows loading square textures.
*
* @param {string} guiObject
* @param {string} filename
*/
function setMapPreviewImage(guiObject, filename)
function getMapPreviewImage(filename)
{
Engine.GetGUIObjectByName(guiObject).sprite =
"cropped:" + 400 / 512 + "," + 300 / 512 + ":" +
return "cropped:" + 400 / 512 + "," + 300 / 512 + ":" +
g_MapPreviewPath + filename;
}

View file

@ -1002,6 +1002,22 @@ var g_MiscControls = {
"chatInput": {
"tooltip": () => colorizeAutocompleteHotkey(translate("Press %(hotkey)s to autocomplete player names or settings.")),
},
"mapInfoName": {
"caption": () => translateMapTitle(getMapDisplayName(g_GameAttributes.map))
},
"mapInfoDescription": {
"caption": getGameDescription
},
"mapPreview": {
"sprite": () => {
let biomePreview = g_GameAttributes.settings.Biome && getBiomePreview(g_GameAttributes.map, g_GameAttributes.settings.Biome);
if (biomePreview)
return getMapPreviewImage(biomePreview);
let mapData = loadMapData(g_GameAttributes.map);
return getMapPreviewImage(mapData && mapData.settings && mapData.settings.Preview || "nopreview.png");
}
},
"cheatWarningText": {
"hidden": () => !g_IsNetworked || !g_GameAttributes.settings.CheatsEnabled,
},
@ -1484,7 +1500,6 @@ function distributeSettings()
thisColumn = 0;
}
let childSize = child.size;
child.size = new GUISize(
column * columnWidth,
yPos,
@ -1676,19 +1691,6 @@ function getMapDisplayName(map)
return mapData.settings.Name;
}
function getMapPreview(map)
{
let biomePreview = g_GameAttributes.settings.Biome && getBiomePreview(map, g_GameAttributes.settings.Biome);
if (biomePreview)
return biomePreview;
let mapData = loadMapData(map);
if (!mapData || !mapData.settings || !mapData.settings.Preview)
return "nopreview.png";
return mapData.settings.Preview;
}
/**
* Filter maps with filterFunc and by chosen map type.
*
@ -2193,12 +2195,6 @@ function updateGUIMiscControl(name, playerIdx)
function launchGame()
{
if (!g_IsController)
{
error("Only host can start game");
return;
}
if (!g_GameAttributes.map || g_GameStarted)
return;
@ -2351,7 +2347,6 @@ function updateGUIObjects()
for (let name in g_MiscControls)
updateGUIMiscControl(name);
updateGameDescription();
distributeSettings();
rightAlignCancelButton();
updateAutocompleteEntries();
@ -2390,16 +2385,6 @@ function rightAlignCancelButton()
cancelGame.size = cancelGameSize;
}
function updateGameDescription()
{
setMapPreviewImage("mapPreview", getMapPreview(g_GameAttributes.map));
Engine.GetGUIObjectByName("mapInfoName").caption =
translateMapTitle(getMapDisplayName(g_GameAttributes.map));
Engine.GetGUIObjectByName("mapInfoDescription").caption = getGameDescription();
}
/**
* Broadcast the changed settings to all clients and the lobbybot.
*/

View file

@ -106,9 +106,8 @@ function selectionChanged()
return;
Engine.GetGUIObjectByName("savedMapName").caption = translate(metadata.initAttributes.settings.Name);
let mapData = getMapDescriptionAndPreview(metadata.initAttributes.mapType, metadata.initAttributes.map, metadata.initAttributes);
setMapPreviewImage("savedInfoPreview", mapData.preview);
Engine.GetGUIObjectByName("savedInfoPreview").sprite = getMapPreviewImage(
getMapDescriptionAndPreview(metadata.initAttributes.mapType, metadata.initAttributes.map, metadata.initAttributes).preview);
Engine.GetGUIObjectByName("savedPlayers").caption = metadata.initAttributes.settings.PlayerData.length - 1;
Engine.GetGUIObjectByName("savedPlayedTime").caption = timeToString(metadata.gui.timeElapsed ? metadata.gui.timeElapsed : 0);
Engine.GetGUIObjectByName("savedMapType").caption = translateMapType(metadata.initAttributes.mapType);

View file

@ -1157,9 +1157,8 @@ function updateGameSelection()
Engine.GetGUIObjectByName("sgMapType").caption = g_MapTypes.Title[mapTypeIdx] || "";
let mapData = getMapDescriptionAndPreview(game.mapType, game.mapName);
Engine.GetGUIObjectByName("sgMapPreview").sprite = getMapPreviewImage(mapData.preview);
Engine.GetGUIObjectByName("sgMapDescription").caption = mapData.description;
setMapPreviewImage("sgMapPreview", mapData.preview);
}
function selectedGame()

View file

@ -281,15 +281,13 @@ function displayReplayDetails()
Engine.GetGUIObjectByName("showSpoiler").checked &&
metadata &&
metadata.playerStates &&
metadata.playerStates.map(pState => pState.state)
);
metadata.playerStates.map(pState => pState.state));
let mapData = getMapDescriptionAndPreview(replay.attribs.settings.mapType, replay.attribs.map, replay.attribs);
Engine.GetGUIObjectByName("sgMapPreview").sprite = getMapPreviewImage(mapData.preview);
Engine.GetGUIObjectByName("sgMapDescription").caption = mapData.description;
Engine.GetGUIObjectByName("summaryButton").hidden = !Engine.HasReplayMetadata(replay.directory);
setMapPreviewImage("sgMapPreview", mapData.preview);
}
/**