Page MenuHomeWildfire Games

Move the view player list initialization in session.js to a separate function
ClosedPublic

Authored by temple on Dec 7 2017, 8:33 PM.

Details

Summary

Move the view player list initialization in session.js to a separate function.
In D754 we'll need to call this function when changing player colors.

Test Plan

I kept the viewPlayer name, but maybe it could be changed to viewedPlayerDropdown or something, I don't have a strong opinion.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

temple created this revision.Dec 7 2017, 8:33 PM
Owners added a subscriber: Restricted Owners Package.Dec 7 2017, 8:33 PM
temple added inline comments.Dec 7 2017, 8:34 PM
binaries/data/mods/public/gui/session/session.js
449–450 ↗(On Diff #4634)

swap the order since names before id in the other two places

Vulcan added a subscriber: Vulcan.Dec 7 2017, 9:21 PM

Successful build - Chance fights ever on the side of the prudent.

Updating workspaces...
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (308 tests)....................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (308 tests)....................................................................................................................................................................................................................................................................................................................OK!
Checking XML files...
temple retitled this revision from Move the view player list setup in Session.js to a separate function to Move the view player list initialization in session.js to a separate function.Dec 8 2017, 5:39 AM
temple edited the summary of this revision. (Show Details)

Thanks for splitting it

binaries/data/mods/public/gui/session/session.js
456 ↗(On Diff #4634)

Could we end up with 3 statements by using [-1].concat(g_Players.map(player, playerID) => calls like we do in modmod.js?

temple updated this revision to Diff 4654.Dec 8 2017, 6:10 PM

elexis's suggestion

Vulcan added a comment.Dec 8 2017, 6:12 PM

Successful build - Chance fights ever on the side of the prudent.

Updating workspaces...
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (308 tests)....................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (308 tests)....................................................................................................................................................................................................................................................................................................................OK!
Checking XML files...
elexis accepted this revision.Dec 8 2017, 6:36 PM

Will commit after testing in case you agree with the 2 renames

binaries/data/mods/public/gui/session/session.js
293 ↗(On Diff #4654)

viewedPlayer might not have been the best name choice at the time, given that it is about a player different from g_ViewedPlayer, nor a playerID. player should do.

(That + 1 is a "hardcoded" / "magic number". We could use Engine.GetGUIObjectByName("viewPlayer").list_data.indexOf(Engine.GetPlayerID()).
But seems to add more pain than gain.)

443 ↗(On Diff #4654)

updateViewedPlayerDropdown or updateViewedPlayerControl to make it slightly more clear which list is meant.

(Was wondering if it fits better to menu.js (near the gamespeed choices). Seems like the place might use some sorting. But the rest of the viewed-player logic is in session.js, so we can keep it there).

446 ↗(On Diff #4654)

(Array(g_MaxPlayers).fill(0).map((v, i) => i + 1) wouldn't be any better either, as seen in gamesetup.js g_NumPlayersList, nor any use of prepareForDropdown)

This revision is now accepted and ready to land.Dec 8 2017, 6:36 PM
temple added a comment.Dec 8 2017, 7:05 PM
In D1126#45130, @elexis wrote:

Will commit after testing in case you agree with the 2 renames

Renames are fine.

This revision was automatically updated to reflect the committed changes.