Skip to content

Conversation

@IllianiBird
Copy link
Collaborator

This PR relates to the conversion of our current SkillType class from a static String plus hash hybrid and into an enum.

This makes it far easier for developers to add new skills and make changes to existing skills. It makes skill storage more reliable and removes the risk that a skill change will result in damage to a players' save.

@IllianiBird IllianiBird self-assigned this Oct 4, 2025
@IllianiBird IllianiBird requested a review from a team as a code owner October 4, 2025 02:09
@IllianiBird IllianiBird added the Legacy Improvement Improves a legacy setup's handling. label Oct 4, 2025
@IllianiBird IllianiBird marked this pull request as draft October 4, 2025 02:10
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

public boolean isRightTechType(String skillType) {
if (getEngine().hasFlag(Engine.TANK_ENGINE)) {
return skillType.equals(SkillType.S_TECH_MECHANIC);
return skillType.equals(SkillTypeNew.S_TECH_MECHANIC.name());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You'll see a lot of SkillTypeNew.SKILL.name() in this PR. The original SkillType format had all skill references using a static String. That means our codebase is set up to accept Strings and not SkillTypes.

One of my goals with this PR was to make as few changes as possible, to reduce the risk of introducing new bugs with this overhaul. While converting the codebase to use SkillTypes wherever possible would be the correct move, it would balloon the size of this PR beyond reasonable levels. It is better, then, to use legacy architecture that can be replaced ad hoc in future PRs.

# Conflicts:
#	MekHQ/src/mekhq/campaign/personnel/Person.java
#	MekHQ/src/mekhq/campaign/personnel/generator/AbstractSkillGenerator.java
#	MekHQ/src/mekhq/campaign/personnel/skills/Skill.java
#	MekHQ/src/mekhq/campaign/personnel/skills/SkillType.java
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request performs a major refactoring to migrate from the legacy SkillType class to a new enum-based SkillTypeNew system. The changes modernize skill type handling by converting from a string-based initialization system to a strongly-typed enum approach.

Key changes:

  • Introduced SkillTypeNew enum with all skill types as enum constants
  • Created SkillUtilities helper class consolidating skill-related static methods
  • Updated all references from SkillType.S_* constants to SkillTypeNew.S_*.name()
  • Removed SkillType.initializeTypes() calls throughout test files
  • Changed from SkillType.getType(String) to SkillTypeNew.getType(String)

Reviewed Changes

Copilot reviewed 140 out of 140 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
SkillTypeNew.java New enum containing all skill type definitions with their properties
SkillUtilities.java New utility class for experience level names, colors, and skill-related helper methods
SkillSubType.java Added getRoleplaySkillSubTypes() helper method
Multiple test files Removed SkillType.initializeTypes() calls and updated skill constant references
Multiple source files Updated skill type references to use new enum system and .name() method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1911 to +1912
public static SkillTypeNew getType(String name) {
return SkillTypeNew.valueOf(name);
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

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

The getType() method lacks null handling and will throw IllegalArgumentException for invalid enum names. Consider adding null checks and graceful error handling with a meaningful return value or logging, especially since this is a public API used throughout the codebase.

Copilot uses AI. Check for mistakes.
import mekhq.campaign.personnel.skills.SkillType;
import mekhq.campaign.personnel.skills.SkillUtilities;
import mekhq.campaign.personnel.skills.enums.SkillTypeNew;
import mekhq.campaign.personnel.skills.SkillUtilities;
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

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

Duplicate import of SkillUtilities on lines 46 and 48. Remove the duplicate import statement.

Copilot uses AI. Check for mistakes.
SkillType skillType = SkillType.getSkillHash().get(skillName);
if (skillType == null) {
try {
SkillTypeNew skillType = SkillTypeNew.valueOf(skillName);
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

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

Variable 'SkillTypeNew skillType' is never read.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For New Dev Cycle Legacy Improvement Improves a legacy setup's handling.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant