Page MenuHomeWildfire Games

Remove redundant JS VFS functions from gui/common/functions_utility.js and simplify related code
ClosedPublic

Authored by elexis on Dec 5 2017, 1:33 AM.

Details

Summary

gui/common/functions_utility.js is a mess and removing the redundant functions will be a great improvement.
The loading screen tips code can become shortened and easier to read.
Not happy about the listFiles being in Templates.js, see P97 for where it should be located eventually.

Test Plan

Notice that the code does the same as before.

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

elexis created this revision.Dec 5 2017, 1:33 AM
Vulcan added a subscriber: Vulcan.Dec 5 2017, 1:40 AM

Build failure - The Moirai have given mortals hearts that can endure.

Vulcan added a comment.Dec 5 2017, 1:42 AM
Executing section Default...
Executing section Source...
Executing section JS...

binaries/data/mods/public/gui/loading/loading.js
|  17| »   »   »   Engine.GetGUIObjectByName("tipText").caption·=·tipText.join("\n")
|    | [NORMAL] JSHintBear:
|    | Missing semicolon.

binaries/data/mods/public/globalscripts/Templates.js
|  99| »   »   ····················||·(c[0]·!=·"!"·&&·classes.indexOf(c)·!=·-1)))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '||'; readers may interpret this as an expression boundary.
bb accepted this revision.Dec 23 2017, 10:57 PM
bb added a subscriber: bb.

Have a look at that inline and it should be ok

other occurrences of listDirectoryFiles are correct

binaries/data/mods/public/gui/loading/loading.js
15–17 ↗(On Diff #4551)

so we split shift and join => looks like inefficient. Can't we look for the first index of "\n" and splice the part before?

35 ↗(On Diff #4551)

why care if there are no tips => good

56 ↗(On Diff #4551)

seems like modding support => good

This revision is now accepted and ready to land.Dec 23 2017, 10:57 PM
elexis added inline comments.Dec 23 2017, 11:32 PM
binaries/data/mods/public/globalscripts/Templates.js
7 ↗(On Diff #4551)

Still not happy about this function being here. Probably better in gui/common/ and letting the DataTemplateManager use it's own copy of this line.
(It can be only one call if the duplication would be removed similar to D1108.)

binaries/data/mods/public/gui/common/functions_utility.js
27 ↗(On Diff #4551)

than hiding it here in a function that according to it's name should also be usable for non-map XML files.

binaries/data/mods/public/gui/gamesetup/gamesetup.js
1449 ↗(On Diff #4551)

Maps starting with underscore are hidden in the gameseutp. I didn't know that. It's only used for the atlas _default map. The feature should be more visible this way.

binaries/data/mods/public/gui/loading/loading.js
15–17 ↗(On Diff #4551)

inefficient -> The microseconds on init are irrelevant.
first index -> That's what the code in the let side does. This is the shortest code I could find that still works with an empty string iirc

35 ↗(On Diff #4551)

Perhaps because there would be a an empty graphics. Don't see the benefit making this an error message exceeding the benefit of not having it however. Especially since mods might want to nuke the graphics without introducing a modified copy of this file.

56 ↗(On Diff #4551)

mostly removed it because the GUI would break on all ends from front to back if there is a different maptype used, so the error string doesn't add anything but code

bb added inline comments.Dec 23 2017, 11:47 PM
binaries/data/mods/public/globalscripts/Templates.js
7 ↗(On Diff #4551)

Isn't the reason we have globalscripts that they can be used everywhere, maybe just place it in globalscripts/utility.js since there is a extension fucntion already

binaries/data/mods/public/gui/loading/loading.js
15–17 ↗(On Diff #4551)

It is sad we can't splice strings...

This function_utilities.js is one of the worst mess in this folder, so readers will benefit from the removal of unrelated code there.
Thanks for the review.

binaries/data/mods/public/globalscripts/Templates.js
7 ↗(On Diff #4551)

utility.js is much better.
Perhaps we want to split it into VFS.js and ArraysOperation.js or something eventually.

binaries/data/mods/public/gui/loading/loading.js
35 ↗(On Diff #4551)

Having the warning means that a modder is informed of the cause without having to lookup the code and the disadvantage to the reader doesn't seem to outweigh that (as long as having no tooltips is considered a defect and not a feature, which it should since the graphics look crap then). (On the other hand mods might want to hide the graphics externally and would then run into the error. Meh)

This revision was automatically updated to reflect the committed changes.
Owners added a subscriber: Restricted Owners Package.Dec 26 2017, 11:44 PM