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

Extract AtB Event Types to enum #5824

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Algebro7
Copy link
Collaborator

This simply moves the hardcoded ATB Event Type constants from static variables to an enum. This supports further refactoring work on AtBContract by reducing the number of public variables that other classes need to call, therefore simplifying the public interface. My understanding was also that there was an initiative to try and use enums instead of static ints throughout the codebase.

Copy link
Collaborator

@IllianiCBT IllianiCBT left a comment

Choose a reason for hiding this comment

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

Do we want to pull the event logic and enum into their own class? So that rather than living in AtBContract.java we just include a call to AtBContractEvent.java and have all the event logic handled there? The enum could be contained within AtBContractEvent.java, too. Keep it all together.

@codecov-commenter
Copy link

codecov-commenter commented Jan 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 10.28%. Comparing base (4b2b18b) to head (6cd5c3f).
Report is 242 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5824      +/-   ##
============================================
- Coverage     10.28%   10.28%   -0.01%     
- Complexity     6123     6124       +1     
============================================
  Files          1039     1040       +1     
  Lines        139328   139362      +34     
  Branches      20632    20636       +4     
============================================
- Hits          14331    14327       -4     
- Misses       123589   123612      +23     
- Partials       1408     1423      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Algebro7
Copy link
Collaborator Author

Good thought--I'll look more into that this weekend when I have some time

@Algebro7
Copy link
Collaborator Author

So looking at it a bit more, the event logic in AtBContract.checkEvents() reaches into the contract-specific details a fair bit (e.g., manipulating parts availability numbers, morale, etc) which I'm concerned will increase the coupling with ATBContract rather than decrease it. AtBContract will have less code in it, but other contract types won't necessarily be able to use the event types in AtBContractEvent because AtBContractEvent is designed to work with AtBContract.

Sorry for the long-winded and confusing explanation...in short, I'm concerned about splitting the logic into a different class while having it remain tightly coupled to the class we extracted it from. As a side note, I am trying different strategies for the CamOps Contract Market and one may actually involve just extending the AtBContract class after all, and having AtBContract just represent the base class for any campaign against the computer rather than a specific game type. If I go that route then your idea may be less of a concern, so maybe we can explore that then?

Comment on lines +354 to 355
public AtBEventType generateStratConEvent() {
final int roll = Compute.randomInt(20) + 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this really should be a static map or something like it.

Copy link
Collaborator Author

@Algebro7 Algebro7 Jan 25, 2025

Choose a reason for hiding this comment

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

Thanks, that probably does make sense. I'm guessing we'd need to simplify the rolls to avoid a bunch of duplicate values (e.g., for keys 10-13 and 14-15), right?

By the way, with the current direction I'm heading with the Contract classes, this PR isn't as useful as it was, so I'm also OK closing it unless we want to take an opportunity to clean up those roll tables like @Scoppio suggested.

Copy link
Collaborator

@rjhancock rjhancock left a comment

Choose a reason for hiding this comment

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

Looks like a straight forward change but requesting some readability improvements.

Comment on lines -240 to 255
return AtBContract.EVT_BONUSROLL;
return AtBEventType.BONUSROLL;
} else if (roll < 14) {
return AtBContract.EVT_SPECIAL_SCENARIO;
return AtBEventType.SPECIAL_SCENARIO;
} else if (roll < 16) {
return AtBContract.EVT_BETRAYAL;
return AtBEventType.BETRAYAL;
} else if (roll < 17) {
return AtBContract.EVT_TREACHERY;
return AtBEventType.TREACHERY;
} else if (roll < 18) {
return AtBContract.EVT_LOGISTICSFAILURE;
return AtBEventType.LOGISTICSFAILURE;
} else if (roll < 19) {
return AtBContract.EVT_REINFORCEMENTS;
return AtBEventType.REINFORCEMENTS;
} else if (roll < 20) {
return AtBContract.EVT_SPECIALEVENTS;
return AtBEventType.SPECIALEVENTS;
} else {
return AtBContract.EVT_BIGBATTLE;
return AtBEventType.BIGBATTLE;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

These, and all following if/else chains, can be simplified using switch/case with fall through.

Start at 20 and work down.

It'll increase readability for most.

@HammerGS
Copy link
Member

HammerGS commented Feb 6, 2025

I have no clue if this is ready to go. Leaving it till it gets approved by a coder.

@Algebro7
Copy link
Collaborator Author

Algebro7 commented Feb 6, 2025

Sorry @HammerGS , don't merge yet. I mentioned in a separate comment thread that this change could be more trouble than it's worth since I had to change direction on the Contract refactoring, but I'm also happy to implement the reviewers' suggestions if they think there is value in moving those static ints to an enum stored outside the class.

Just let me know and I can either finish it or close it. Thanks!

@HammerGS
Copy link
Member

HammerGS commented Feb 6, 2025

I'll flip it to a draft till things get sorted.

@HammerGS HammerGS marked this pull request as draft February 6, 2025 02:09
@HammerGS HammerGS added the Draft Work in Progress label Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Draft Work in Progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants