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

Only skip giveUnitControl if the value is false or true #8023

Merged
merged 2 commits into from
Nov 1, 2020

Conversation

trevan
Copy link
Contributor

@trevan trevan commented Oct 31, 2020

Fixes #7990

In #1033, @Cernelius said to remove giveUnitControl if its values was a boolean. But he said to leave it alone if the value wasn't a boolean. In #7631, it was just skipped without looking at the value. This changes it to check the value and only skip it if it is a boolean.

I think this breaks all of the world_war_ii_global games as well as several others.

Testing

Played World War 2 Global 1940 2nd to UK_Pacific Place round, placed some units in India, finished the place round and checked that the new units are now British units.

Screens Shots

Additional Notes to Reviewer

Release Note

FIX|World War 2 Global will correctly switch unit ownership of units placed in India from UK_Pacific to British.

@codecov
Copy link

codecov bot commented Oct 31, 2020

Codecov Report

Merging #8023 into master will increase coverage by 0.01%.
The diff coverage is 40.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #8023      +/-   ##
============================================
+ Coverage     24.93%   24.95%   +0.01%     
- Complexity     7328     7332       +4     
============================================
  Files          1259     1259              
  Lines         79267    79333      +66     
  Branches      11162    11159       -3     
============================================
+ Hits          19769    19799      +30     
- Misses        57402    57438      +36     
  Partials       2096     2096              
Impacted Files Coverage Δ Complexity Δ
...y/engine/data/gameparser/LegacyPropertyMapper.java 78.78% <33.33%> (-5.09%) 19.00 <4.00> (+1.00) ⬇️
...es/strategy/engine/data/gameparser/GameParser.java 82.12% <50.00%> (+0.29%) 141.00 <0.00> (ø)
...te/battle/steps/fire/aa/AaFireAndCasualtyStep.java 22.91% <0.00%> (-6.04%) 6.00% <0.00%> (ø%)
.../battle/steps/fire/SelectMainBattleCasualties.java 76.31% <0.00%> (-3.14%) 15.00% <0.00%> (ø%)
...elegate/power/calculator/AaOffenseCombatValue.java 66.66% <0.00%> (-2.30%) 5.00% <0.00%> (ø%)
...elegate/power/calculator/AaDefenseCombatValue.java 65.62% <0.00%> (-2.24%) 5.00% <0.00%> (ø%)
...egate/power/calculator/MainDefenseCombatValue.java 67.56% <0.00%> (-1.45%) 4.00% <0.00%> (+1.00%) ⬇️
...triplea/delegate/power/calculator/CombatValue.java 80.00% <0.00%> (-1.09%) 4.00% <0.00%> (ø%)
...lea/delegate/battle/casualty/CasualtySelector.java 50.73% <0.00%> (-0.40%) 15.00% <0.00%> (ø%)
...gate/power/calculator/TotalPowerAndTotalRolls.java 89.63% <0.00%> (-0.37%) 65.00% <0.00%> (-3.00%)
... and 22 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 50ac15b...5ca0fbf. Read the comment docs.

@Cernelius
Copy link
Contributor

If TripleA 2.3 breaks all of the world_war_ii_global games, I would say 2.4 needs to be released as soon as possible. I guess we don't have many pre-release playtesters on these very popular maps (I never play any of them).

There is also the problem that any documentation on the matter is missing.
https://github.com/triplea-game/triplea/blob/master/docs/map-making/map-features-change-log.md

It used to be present in some old versions (so, this could be fixed by reverting to one of those).
https://github.com/triplea-game/triplea/blob/0f2851209251e7573ed8bcf5c87cc05f11e6ddd9/docs/map-making/upgrading-1-8-maps.md

It was even specifically documented in the bottom line of what I linked (as I foresaw this could have been an easy source of confusion for developers and mapmakers).

While all options named "takeUnitControl" must be deleted, any option named "giveUnitControl" must be deleted only if its value is "true" or "false".

@DanVanAtta
Copy link
Member

@trevan by

I think this breaks all of the world_war_ii_global games as well as several others.

Is this, this PR, or are you referring to the 1.8 maps PR: #7631

@@ -895,16 +895,16 @@ private Attachable findAttachment(
}
// decapitalize the property name for backwards compatibility
final String name = LegacyPropertyMapper.mapLegacyOptionName(decapitalize(option.getName()));
if (LegacyPropertyMapper.ignoreOptionName(name)) {
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind explaining why this if block is moved down @trevan ?

If we are going to ignore an option, why should we execute option.getValue() or option.getCount(), wouldn't those just be dead stores?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved it because I needed access to option.getValue() and I thought it would make more sense to use the local variable value that was going to be created vs passing in option.getValue(). But I can move it back up and pass in option.getValue().

Copy link
Member

Choose a reason for hiding this comment

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

The local variable IMO is legacy, it's an unnecessary intermediate variable. This class in general followed a C++ pattern (if not older actually, maybe a C pattern or even Pascal) to declar all local variables at the beginning of a method. IMO all usages of 'value' probably should just get inlined.

I did not spot you were using the value variable. That answers my question.

static boolean ignoreOptionName(final String name, final String value) {
return name.equalsIgnoreCase("takeUnitControl")
|| (name.equalsIgnoreCase("giveUnitControl")
&& (value.equals("false") || value.equals("true")));
Copy link
Member

Choose a reason for hiding this comment

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

Are you positive that value could never be null here? I don't remember if we translate empty values to empty strings or null values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

value is never checked for null in the caller before using (see line 908 in GameParser) so I don't think it would ever be null.

Copy link
Member

Choose a reason for hiding this comment

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

Considering we just had a NPE in GameParser, I would not presume it to be already correct. Another consideration, the 'value' is very context dependent, a DTD previously would have enforced values being provided, that is not necessarily guaranteed now.

I wonder if there is any type of test coverage around this at all that could/should be updated.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I may be wrong about the DTD previously requiring a specific value, I'm not sure if it can constrain attribute values vs just requiring them being there. Regardless, it is context dependent if we can expect a value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point on the NPE. It will now skip giveUnitControl if the value is null as well as true or false.

There is some test coverage but it requires creating a brand new xml with these attributes in it. I'm looking at if there is a way to be able to create the xml in memory instead of committing the xml as a resource.

Copy link
Member

Choose a reason for hiding this comment

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

If we can get away from XMLs for testing, that would be excellent.

The decoupling of XML parsing from the semantic data parsing into GameData was meant to help with this.

One should be able to set up a org.triplea.map.data.elements.Game object and then pass that to GameParser and avoid having to set up an XML. The former is well tested for a variety of XML snippets, so we can be pretty sure how that works. It should have some existing tests that might be interesting to know if we null out empty values. Beyond that, sending GameParser a defined Game object hopefully can do the trick. GameParser is still very rough, so it might take some plumbing work to accept a Game object here. Let me know if that turns out to be the case, for now a manual verification is enough or you can go the extra mile if you feel it's worthwhile given the context acquisition cost you will have payed.

@trevan
Copy link
Contributor Author

trevan commented Nov 1, 2020

@trevan by

I think this breaks all of the world_war_ii_global games as well as several others.

Is this, this PR, or are you referring to the 1.8 maps PR: #7631

The 1.8 maps PR.

@trevan trevan removed their assignment Nov 1, 2020
@trevan
Copy link
Contributor Author

trevan commented Nov 1, 2020

@DanVanAtta , I responded to your comments

@DanVanAtta DanVanAtta merged commit a3335ff into triplea-game:master Nov 1, 2020
@trevan trevan deleted the fix-giveUnitControl branch November 5, 2020 03:28
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.

Units placed in the India territory not recognised.
3 participants