Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify link localization code #8637

Merged
merged 2 commits into from
Jan 17, 2021
Merged

Conversation

DanVanAtta
Copy link
Member

@DanVanAtta DanVanAtta commented Jan 17, 2021

Main goal of this simplification is to remove 'map name' from resource loader.
One place that is used is in Link Localization. Instead of passing a resource
loader to the link localizer, we can instead pass a file path which in turn
simplifies how link localization can be done.

Additional:

  • removed link localization cache
  • changed link localizatoin behavior to only localize links that are not already
    absolute. Previously links in single quotes would be localized and links in
    double quotes would be left as-is. The localization of fully qualified links
    would parse the link path, get the file name and localize the file name path.
    This is removed as it is difficult to understand and is much easier if
    we localize any relative links but keep absolute links as they are (regardless
    of quoting).

Testing

  • Downloaded a variety of maps and check that their images still loaded in the game selection window.
  • Launched Civil War to do some smoke testing for missing images

Screens Shots

Additional Notes to Reviewer

Release Note

UPDATE|Map making - clarified how image links in HTML is made localized. If the link is absolute, it will now always remain absolute (eg: https://path-to-my-image/my-image.png). Otherwise if the image path is relative (eg: "img src=someImage.png"), the path will be made relative to the maps folder 'doc/images/'.

@codecov
Copy link

codecov bot commented Jan 17, 2021

Codecov Report

Merging #8637 (a3e092c) into master (7e1bc61) will decrease coverage by 0.01%.
The diff coverage is 14.28%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #8637      +/-   ##
============================================
- Coverage     24.88%   24.86%   -0.02%     
+ Complexity     7366     7363       -3     
============================================
  Files          1291     1291              
  Lines         80365    80376      +11     
  Branches      11012    11011       -1     
============================================
- Hits          19998    19989       -9     
- Misses        58295    58312      +17     
- Partials       2072     2075       +3     
Impacted Files Coverage Δ Complexity Δ
...amework/map/file/system/loader/DownloadedMaps.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...ames/strategy/engine/framework/ui/GameChooser.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...es/strategy/triplea/delegate/EndRoundDelegate.java 1.50% <0.00%> (-0.02%) 1.00 <0.00> (ø)
...ain/java/games/strategy/triplea/ui/NotesPanel.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...a/games/strategy/triplea/ui/TooltipProperties.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...n/java/games/strategy/triplea/ui/TripleAFrame.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...extras/src/main/java/org/triplea/io/FileUtils.java 33.33% <0.00%> (-41.67%) 2.00 <0.00> (ø)
...e/src/main/java/org/triplea/util/LocalizeHtml.java 77.27% <71.42%> (-0.86%) 7.00 <5.00> (-2.00)
...lea/ai/flowfield/influence/InfluenceTerritory.java 96.96% <0.00%> (-3.04%) 13.00% <0.00%> (-1.00%)
.../java/games/strategy/triplea/delegate/Matches.java 45.12% <0.00%> (-0.11%) 370.00% <0.00%> (-1.00%)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7e1bc61...a3e092c. Read the comment docs.

Main goal of this simplification is to remove 'map name' from resource loader.
One place that is used is in Link Localization. Instead of passing a resource
loader to the link localizer, we can instead pass a file path which in turn
simplifies how link localization can be done.

Additional:
- removed link localization cache
- changed link localizatoin behavior to only localize links that are not already
  absolute. Previously links in single quotes would be localized and links in
  double quotes would be left as-is. The localization of fully qualified links
  would parse the link path, get the file name and localize the file name path.
  This is removed as it is difficult to understand and is much easier if
  we localize any relative links but keep absolute links as they are (regardless
  of quoting).
@DanVanAtta DanVanAtta force-pushed the resource-loader-with-file-input branch from 4da2283 to 39c4e8d Compare January 17, 2021 02:57

if (replacementUrl == null) {
log.error(String.format("Could not find: %s/%s", loader.getMapName(), firstOption));
final String secondFallback = ASSET_IMAGE_FOLDER + ASSET_IMAGE_NOT_FOUND;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the fallback image never used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's never used, the file 'notFound.png' is not part of the game engine. A map could have it, but none do.


@VisibleForTesting
static String localizeImgLinksInHtml(final String htmlText, final ResourceLoader loader) {
public static String localizeImgLinksInHtml(final String htmlText, final File mapContentFolder) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in case the resource does not exist we will no longer notice at this point, right?
And because the HTML is not really handled by us, this will result in a silent error, just like it would in a normal web browser

Copy link
Member Author

@DanVanAtta DanVanAtta Jan 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resource loader was only used to get the map folder location, it was not actually loading the image or validating that it was there. Hence, that data was being used to localize the path only, everything was and is done as String operations, so we were not noticing it either way.

@DanVanAtta DanVanAtta merged commit 3efd42f into master Jan 17, 2021
@DanVanAtta DanVanAtta deleted the resource-loader-with-file-input branch January 17, 2021 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants