-
Notifications
You must be signed in to change notification settings - Fork 178
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
Warnings on Campaign Load #5757
Conversation
Added logic to block campaign updates if active contracts exist, ensuring users complete them before proceeding. Displayed an error dialog to inform users of the issue and maintain version integrity.
Extracted the logic for displaying a warning for active or future contracts into a dedicated method, improving readability and maintainability. Updated corresponding code to use the new method for better encapsulation and reduced duplication.
Reorganized the active contract logic to directly use `getActiveAtBContracts()` for clarity and efficiency. Moved the contracts list retrieval to conditional logic to avoid redundant calls.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5757 +/- ##
============================================
- Coverage 10.33% 10.33% -0.01%
- Complexity 6124 6127 +3
============================================
Files 1036 1037 +1
Lines 138533 138592 +59
Branches 20482 20495 +13
============================================
- Hits 14321 14318 -3
- Misses 122824 122884 +60
- Partials 1388 1390 +2 ☔ View full report in Codecov by Sentry. |
Refactored logic to display a warning for active or future contracts into a new `ActiveContractWarning` class. Integrated the new warning mechanism into `CampaignXmlParser` and revised resource properties to include localized messages. Removed redundant code handling contract warnings directly in `CampaignXmlParser`.
|
if (MHQConstants.VERSION.isHigherThan(version)) { | ||
if (retVal.hasActiveAtBContract(true)) { | ||
new ActiveContractWarning(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion would be something like the following, but inside the CampaignFactory file, with the CampaignXMLParser returning a container with the campaign and the relevant diagnostics:
Somewhere add this:
// Somewhere
public enum CampaignProblemType {
NONE,
ACTIVE_CONTRACT,
ACTIVE_FUTURE_CONTRACT,
CANT_LOAD_FROM_VERSION,
CANT_PARSE_FILE,
}
public record ParsedCampaign(Campaign campaign, String currentMekHQVersion, String fileMekHQVersion, CampaignProblemType problem, String diagnostics) {
public boolean hasProblems() {
return problem != null;
}
}
In the CampaignFactory
public ParsedCampaign createCampaign(InputStream is)
throws CampaignXmlParseException, IOException, NullEntityException {
if (!is.markSupported()) {
is = new BufferedInputStream(is);
}
byte[] header = readHeader(is);
// Check if the first two bytes are the GZIP magic bytes...
if ((header.length >= 2) && (header[0] == (byte) 0x1f) && (header[1] == (byte) 0x8b)) {
is = new GZIPInputStream(is);
}
// ...otherwise, assume we're an XML file.
CampaignXmlParser parser = new CampaignXmlParser(is, this.app);
ParsedCampaign parsedCampaign = parser.parse();
return parsedCampaign;
}
This way, the place that receives the file will be able to handle it accordingly.
DataLoadingDialog.java
// And then load the campaign object from it.
try (FileInputStream fis = new FileInputStream(getCampaignFile())) {
ParsedCampaign parsedCampaign = CampaignFactory.newInstance(getApplication()).createCampaign(fis);
if (parsedCampaign.hasProblems()) {
// TODO: CALL ERROR HANDLING FUNCTION FOR EACH POSSIBLE PROBLEM
}
campaign.restore();
campaign.cleanUp();
}
// endregion Progress 6
Otherwise we keep with the problem where we have being imported stuff inserted inside a parser class.
Sorry for not being clear the first time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "parse()" and the diagnostics can run in two different steps, this way not disrupting any tests or old files and just adding new functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I had to wait until my brain had the cycles to process this, but now that it does what you're saying makes perfect sense and will be super maintainable. I would have never thought to use Enums like this. Thanks for the feedback! :)
Replaced ActiveContractWarning with a more robust version compatibility check during campaign loading. Unified dialog functionality into CampaignHasProblemOnLoad to handle load issues more effectively. Refactored redundant code, such as getSpeakerIcon, into a common utility to improve maintainability.
Updated error dialogs to adapt button options based on problem type, added detailed handling for unsupported version issues, and refactored code for cleaner logic. This improves user guidance and streamlines the campaign loading process.
|
Updated copyright headers across multiple files to extend coverage to 2025. This change ensures compliance with proper attribution and copyright practices for the MegaMek and MekHQ project files.
Requires: MegaMek/megamek#6414