diff --git a/megamek/src/megamek/common/enums/SkillLevel.java b/megamek/src/megamek/common/enums/SkillLevel.java index d6eac78ceb0..c1a840006e6 100644 --- a/megamek/src/megamek/common/enums/SkillLevel.java +++ b/megamek/src/megamek/common/enums/SkillLevel.java @@ -18,14 +18,14 @@ */ package megamek.common.enums; +import megamek.MegaMek; +import megamek.logging.MMLogger; + import java.util.List; import java.util.ResourceBundle; import java.util.stream.Collectors; import java.util.stream.Stream; -import megamek.MegaMek; -import megamek.logging.MMLogger; - public enum SkillLevel { // region Enum Declarations NONE("SkillLevel.NONE.text", "SkillLevel.NONE.toolTipText"), @@ -190,6 +190,29 @@ public static SkillLevel parseFromString(final String text) { return REGULAR; } + + /** + * Parses an integer value to a {@link SkillLevel} enumeration. + * + * @param value the integer value to parse + * @return the {@link SkillLevel} enum corresponding to the given integer value + * @throws IllegalStateException if the integer value does not match any {@link SkillLevel} enum + * value + */ + public static SkillLevel parseFromInteger(final int value) { + return switch (value) { + case 0 -> NONE; + case 1 -> ULTRA_GREEN; + case 2 -> GREEN; + case 3 -> REGULAR; + case 4 -> VETERAN; + case 5 -> ELITE; + case 6 -> HEROIC; + case 7 -> LEGENDARY; + default -> throw new IllegalStateException( + "Unexpected value in megamek/common/enums/SkillLevel.java: " + value); + }; + } // endregion File I/O @Override