Changeset View
Standalone View
binaries/data/mods/public/gui/gamesetup/gamesetup.js
Show First 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | |||||
var g_IsNetworked; | var g_IsNetworked; | ||||
/** | /** | ||||
* Is this user in control of game settings (i.e. singleplayer or host of a multiplayergame). | * Is this user in control of game settings (i.e. singleplayer or host of a multiplayergame). | ||||
*/ | */ | ||||
var g_IsController; | var g_IsController; | ||||
/** | /** | ||||
* Whether this is a tutorial. | |||||
elexis: The comment doesn't tell us anything that the variable name already states.
Instead the reader… | |||||
*/ | |||||
var g_IsTutorial; | |||||
/** | |||||
* To report the game to the lobby bot. | * To report the game to the lobby bot. | ||||
*/ | */ | ||||
var g_ServerName; | var g_ServerName; | ||||
var g_ServerPort; | var g_ServerPort; | ||||
/** | /** | ||||
* States whether the GUI is currently updated in response to network messages instead of user input | * States whether the GUI is currently updated in response to network messages instead of user input | ||||
* and therefore shouldn't send further messages to the network. | * and therefore shouldn't send further messages to the network. | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | function init(attribs) | ||||
{ | { | ||||
error("Unexpected 'type' in gamesetup init: " + attribs.type); | error("Unexpected 'type' in gamesetup init: " + attribs.type); | ||||
cancelSetup(); | cancelSetup(); | ||||
return; | return; | ||||
} | } | ||||
g_IsNetworked = attribs.type != "offline"; | g_IsNetworked = attribs.type != "offline"; | ||||
g_IsController = attribs.type != "client"; | g_IsController = attribs.type != "client"; | ||||
g_IsTutorial = attribs.tutorial && attribs.tutorial == true; | |||||
Not Done Inline Actions!!foo.bar elexis: !!foo.bar | |||||
Not Done Inline Actionsand you find it more readable than what is written? i don't want to loose time arguing when you include such a thing in your own patches, but i will never write it myself! mimo: and you find it more readable than what is written? i don't want to loose time arguing when you… | |||||
Not Done Inline Actions!! returns a boolean, this && returns undefined or true
https://wildfiregames.com/forum/index.php?/topic/22251-coding-conventions-updates/ elexis: `!!` returns a boolean, this `&&` returns `undefined` or `true`
> Returns expr1 if it can be… | |||||
g_ServerName = attribs.serverName; | g_ServerName = attribs.serverName; | ||||
g_ServerPort = attribs.serverPort; | g_ServerPort = attribs.serverPort; | ||||
// Replace empty playername when entering a singleplayermatch for the first time | // Replace empty playername when entering a singleplayermatch for the first time | ||||
if (!g_IsNetworked) | if (!g_IsNetworked) | ||||
{ | { | ||||
Engine.ConfigDB_CreateValue("user", "playername.singleplayer", singleplayerName()); | Engine.ConfigDB_CreateValue("user", "playername.singleplayer", singleplayerName()); | ||||
Engine.ConfigDB_WriteValueToFile("user", "playername.singleplayer", singleplayerName(), "config/user.cfg"); | Engine.ConfigDB_WriteValueToFile("user", "playername.singleplayer", singleplayerName(), "config/user.cfg"); | ||||
▲ Show 20 Lines • Show All 689 Lines • ▼ Show 20 Lines | function loadMapData(name) | ||||
return g_MapData[name]; | return g_MapData[name]; | ||||
} | } | ||||
/** | /** | ||||
* Sets the gameattributes the way they were the last time the user left the gamesetup. | * Sets the gameattributes the way they were the last time the user left the gamesetup. | ||||
*/ | */ | ||||
function loadPersistMatchSettings() | function loadPersistMatchSettings() | ||||
{ | { | ||||
if (g_IsTutorial) | |||||
return; | |||||
if (Engine.ConfigDB_GetValue("user", "persistmatchsettings") != "true") | if (Engine.ConfigDB_GetValue("user", "persistmatchsettings") != "true") | ||||
return; | return; | ||||
let settingsFile = g_IsNetworked ? g_MatchSettings_MP : g_MatchSettings_SP; | let settingsFile = g_IsNetworked ? g_MatchSettings_MP : g_MatchSettings_SP; | ||||
if (!Engine.FileExists(settingsFile)) | if (!Engine.FileExists(settingsFile)) | ||||
return; | return; | ||||
let attrs = Engine.ReadJSONFile(settingsFile); | let attrs = Engine.ReadJSONFile(settingsFile); | ||||
Show All 37 Lines | function loadPersistMatchSettings() | ||||
g_GameAttributes.settings.RatingEnabled = Engine.HasXmppClient(); | g_GameAttributes.settings.RatingEnabled = Engine.HasXmppClient(); | ||||
Engine.SetRankedGame(g_GameAttributes.settings.RatingEnabled); | Engine.SetRankedGame(g_GameAttributes.settings.RatingEnabled); | ||||
updateGUIObjects(); | updateGUIObjects(); | ||||
} | } | ||||
function savePersistMatchSettings() | function savePersistMatchSettings() | ||||
{ | { | ||||
if (g_IsTutorial) | |||||
return; | |||||
let attributes = Engine.ConfigDB_GetValue("user", "persistmatchsettings") == "true" ? g_GameAttributes : {}; | let attributes = Engine.ConfigDB_GetValue("user", "persistmatchsettings") == "true" ? g_GameAttributes : {}; | ||||
Engine.WriteJSONFile(g_IsNetworked ? g_MatchSettings_MP : g_MatchSettings_SP, attributes); | Engine.WriteJSONFile(g_IsNetworked ? g_MatchSettings_MP : g_MatchSettings_SP, attributes); | ||||
} | } | ||||
function sanitizePlayerData(playerData) | function sanitizePlayerData(playerData) | ||||
{ | { | ||||
// Remove gaia | // Remove gaia | ||||
if (playerData.length && !playerData[0]) | if (playerData.length && !playerData[0]) | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | function onTick() | ||||
// First tick happens before first render, so don't load yet | // First tick happens before first render, so don't load yet | ||||
if (g_LoadingState == 0) | if (g_LoadingState == 0) | ||||
{ | { | ||||
++g_LoadingState; | ++g_LoadingState; | ||||
} | } | ||||
else if (g_LoadingState == 1) | else if (g_LoadingState == 1) | ||||
{ | { | ||||
Engine.GetGUIObjectByName("loadingWindow").hidden = true; | Engine.GetGUIObjectByName("loadingWindow").hidden = true; | ||||
Engine.GetGUIObjectByName("setupWindow").hidden = false; | Engine.GetGUIObjectByName("setupWindow").hidden = g_IsTutorial; | ||||
Not Done Inline ActionsMaybe we could call it something else (eg autostart, but that does conflict with the autostart we already have), but I guess this doesn't really matter. leper: Maybe we could call it something else (eg autostart, but that does conflict with the autostart… | |||||
initGUIObjects(); | initGUIObjects(); | ||||
++g_LoadingState; | ++g_LoadingState; | ||||
} | } | ||||
else if (g_LoadingState == 2) | else if (g_LoadingState == 2) | ||||
{ | { | ||||
if (g_IsTutorial) | |||||
Not Done Inline ActionsHere the rebased version gamesetup.js.diff2 KBDownload elexis: Here the rebased version {F127218} | |||||
{ | |||||
launchTutorial(); | |||||
Not Done Inline ActionsA possible future extension (depending on those two things) might want to pass the map as a parameter, which might already be useful now if we want more than one tutorial. leper: A possible future extension (depending on those two things) might want to pass the map as a… | |||||
return; | |||||
} | |||||
while (true) | while (true) | ||||
{ | { | ||||
let message = Engine.PollNetworkClient(); | let message = Engine.PollNetworkClient(); | ||||
if (!message) | if (!message) | ||||
break; | break; | ||||
log("Net message: " + uneval(message)); | log("Net message: " + uneval(message)); | ||||
if (g_NetMessageTypes[message.type]) | if (g_NetMessageTypes[message.type]) | ||||
g_NetMessageTypes[message.type](message); | g_NetMessageTypes[message.type](message); | ||||
else | else | ||||
error("Unrecognised net message type " + message.type); | error("Unrecognised net message type " + message.type); | ||||
} | } | ||||
} | } | ||||
Not Done Inline ActionsI guess this blank line is just an artifact and doesn't need to be added. leper: I guess this blank line is just an artifact and doesn't need to be added. | |||||
Not Done Inline Actionsyes mimo: yes | |||||
updateTimers(); | updateTimers(); | ||||
} | } | ||||
/** | /** | ||||
* Called when the map or the number of players changes. | * Called when the map or the number of players changes. | ||||
*/ | */ | ||||
function unassignInvalidPlayers(maxPlayers) | function unassignInvalidPlayers(maxPlayers) | ||||
▲ Show 20 Lines • Show All 244 Lines • ▼ Show 20 Lines | for (let i in g_GameAttributes.settings.PlayerData) | ||||
let assignBox = Engine.GetGUIObjectByName("playerAssignment["+i+"]"); | let assignBox = Engine.GetGUIObjectByName("playerAssignment["+i+"]"); | ||||
if (assignBox.list_data[assignBox.selected] == "local") | if (assignBox.list_data[assignBox.selected] == "local") | ||||
playerID = +i+1; | playerID = +i+1; | ||||
} | } | ||||
Engine.StartGame(g_GameAttributes, playerID); | Engine.StartGame(g_GameAttributes, playerID); | ||||
Engine.SwitchGuiPage("page_loading.xml", { | Engine.SwitchGuiPage("page_loading.xml", { | ||||
"attribs": g_GameAttributes, | "attribs": g_GameAttributes, | ||||
"isNetworked" : g_IsNetworked, | "isNetworked": g_IsNetworked, | ||||
"playerAssignments": g_PlayerAssignments | "playerAssignments": g_PlayerAssignments | ||||
Not Done Inline ActionsAs mentioned below, passing this argument to the session page only to show the tutorial panel should really be avoided elexis: As mentioned below, passing this argument to the session page only to show the tutorial panel… | |||||
}); | }); | ||||
} | } | ||||
} | } | ||||
function launchTutorial() | |||||
{ | |||||
selectMap("maps/tutorials/starting_economy_walkthrough"); | |||||
launchGame(); | |||||
} | |||||
Not Done Inline Actions(Removed thoughts about merging this with D11) elexis: (Removed thoughts about merging this with D11) | |||||
/** | /** | ||||
* Don't set any attributes here, just show the changes in the GUI. | * Don't set any attributes here, just show the changes in the GUI. | ||||
* | * | ||||
* Unless the mapsettings don't specify a property and the user didn't set it in g_GameAttributes previously. | * Unless the mapsettings don't specify a property and the user didn't set it in g_GameAttributes previously. | ||||
*/ | */ | ||||
function updateGUIObjects() | function updateGUIObjects() | ||||
{ | { | ||||
g_IsInGuiUpdate = true; | g_IsInGuiUpdate = true; | ||||
▲ Show 20 Lines • Show All 649 Lines • Show Last 20 Lines |
The comment doesn't tell us anything that the variable name already states.
Instead the reader should be informed how this variable is used, what it recalls, how it affects the behavior of the gamesetup window, how usual gamesetup behavior is distinguished from tutorial gamesetup behavior.