|
| 1 | +/* |
| 2 | + * Copyright (C) 2025 The MegaMek Team. All Rights Reserved. |
| 3 | + * |
| 4 | + * This file is part of MekHQ. |
| 5 | + * |
| 6 | + * MekHQ is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License (GPL), |
| 8 | + * version 3 or (at your option) any later version, |
| 9 | + * as published by the Free Software Foundation. |
| 10 | + * |
| 11 | + * MekHQ is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty |
| 13 | + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 14 | + * See the GNU General Public License for more details. |
| 15 | + * |
| 16 | + * A copy of the GPL should have been included with this project; |
| 17 | + * if not, see <https://www.gnu.org/licenses/>. |
| 18 | + * |
| 19 | + * NOTICE: The MegaMek organization is a non-profit group of volunteers |
| 20 | + * creating free software for the BattleTech community. |
| 21 | + * |
| 22 | + * MechWarrior, BattleMech, `Mech and AeroTech are registered trademarks |
| 23 | + * of The Topps Company, Inc. All Rights Reserved. |
| 24 | + * |
| 25 | + * Catalyst Game Labs and the Catalyst Game Labs logo are trademarks of |
| 26 | + * InMediaRes Productions, LLC. |
| 27 | + * |
| 28 | + * MechWarrior Copyright Microsoft Corporation. MekHQ was created under |
| 29 | + * Microsoft's "Game Content Usage Rules" |
| 30 | + * <https://www.xbox.com/en-US/developers/rules> and it is not endorsed by or |
| 31 | + * affiliated with Microsoft. |
| 32 | + */ |
| 33 | +package mekhq.campaign.utilities.glossary; |
| 34 | + |
| 35 | +import static mekhq.utilities.MHQInternationalization.getTextAt; |
| 36 | + |
| 37 | +import java.util.List; |
| 38 | + |
| 39 | +/** |
| 40 | + * The {@code DocumentationEntry} enum represents individual entries in the documentation glossary. |
| 41 | + * |
| 42 | + * <p>Each enum constant is associated with a lookup name used to fetch localized strings.</p> |
| 43 | + * |
| 44 | + * <p>This class provides methods to retrieve localized titles, sort entries, and look up entries by name.</p> |
| 45 | + * |
| 46 | + * @author Illiani |
| 47 | + * @since 0.50.07 |
| 48 | + */ |
| 49 | +public enum DocumentationEntry { |
| 50 | + AGING_EFFECTS("AGING_EFFECTS", "Personnel Modules/Aging Effects"), |
| 51 | + AWARDS_MODULE("AWARDS_MODULE", "Personnel Modules/Awards Module"), |
| 52 | + EDUCATION_MODULE("EDUCATION_MODULE", "Personnel Modules/Education Module"), |
| 53 | + RANDOM_DEATH("RANDOM_DEATH", "Personnel Modules/Random Death in MekHQ"), |
| 54 | + RANDOM_DEPENDENTS("RANDOM_DEPENDENTS", "Personnel Modules/Random Dependents"), |
| 55 | + RANDOM_PERSONALITIES("RANDOM_PERSONALITIES", "Personnel Modules/Random Personalities"), |
| 56 | + STARTING_ATTRIBUTE_SCORES("STARTING_ATTRIBUTE_SCORES", "Personnel Modules/Starting Attribute Scores"), |
| 57 | + TURNOVER_AND_RETENTION("TURNOVER_AND_RETENTION", "Personnel Modules/Turnover & Retention Module (feat. Fatigue)"), |
| 58 | + PRISONERS_OF_WAR("PRISONERS_OF_WAR", "Random Events/Prisoners of War & Abstracted Search and Rescue"), |
| 59 | + ACAR("ACAR", "StratCon/ACAR-Abstract Combat Auto-Resolve documentation"), |
| 60 | + ADMIN_SKILLS("ADMIN_SKILLS", "StratCon/Admin Skills"), |
| 61 | + COMBAT_TEAMS("COMBAT_TEAMS", "StratCon/Combat Teams, Roles, Training & Reinforcements"), |
| 62 | + MORALE("MORALE", "StratCon/MekHQ Morale"), |
| 63 | + RESUPPLY_AND_CONVOYS("RESUPPLY_AND_CONVOYS", "StratCon/Resupply & Convoys"), |
| 64 | + UNIT_MARKETS("UNIT_MARKETS", "StratCon/Unit Markets"), |
| 65 | + CHAOS_CAMPAIGNS("CHAOS_CAMPAIGNS", "MegaMek -MekHQ Chaos Campaign Guide"), |
| 66 | + COOP_CAMPAIGNS("COOP_CAMPAIGNS", "MekHQ Co-Op Campaign Guide v1"), |
| 67 | + NEW_PLAYER_GUIDE("NEW_PLAYER_GUIDE", "0_MHQ New Player Guide"); |
| 68 | + |
| 69 | + private static final String RESOURCE_BUNDLE = "mekhq.resources.DocumentationEntry"; |
| 70 | + |
| 71 | + private final String DIRECTORY = "docs/"; |
| 72 | + private final String FILE_EXTENSION = ".pdf"; |
| 73 | + |
| 74 | + private final String lookUpName; |
| 75 | + private final String fileAddress; |
| 76 | + |
| 77 | + /** |
| 78 | + * Constructs a {@code DocumentationEntry} with the specified lookup name. |
| 79 | + * |
| 80 | + * @param lookUpName the resource key used to look up this entry's localized strings |
| 81 | + * @param fileAddress the document address |
| 82 | + * |
| 83 | + * @author Illiani |
| 84 | + * @since 0.50.07 |
| 85 | + */ |
| 86 | + DocumentationEntry(String lookUpName, String fileAddress) { |
| 87 | + this.lookUpName = lookUpName; |
| 88 | + this.fileAddress = fileAddress; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Returns the localized title for this documentation entry. |
| 93 | + * |
| 94 | + * @return the title string for this entry |
| 95 | + * |
| 96 | + * @author Illiani |
| 97 | + * @since 0.50.07 |
| 98 | + */ |
| 99 | + public String getTitle() { |
| 100 | + return getTextAt(RESOURCE_BUNDLE, lookUpName + ".title"); |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Returns the full file address for this object by concatenating the directory path, the stored file address, and |
| 105 | + * the file extension constants. |
| 106 | + * |
| 107 | + * @return the complete file address as a String |
| 108 | + * |
| 109 | + * @author Illiani |
| 110 | + * @since 0.50.07 |
| 111 | + */ |
| 112 | + public String getFileAddress() { |
| 113 | + return DIRECTORY + fileAddress + FILE_EXTENSION; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Returns a list of all lookup names, sorted by their corresponding localized titles in ascending order. |
| 118 | + * |
| 119 | + * @return a list of lookup names sorted by title |
| 120 | + * |
| 121 | + * @author Illiani |
| 122 | + * @since 0.50.07 |
| 123 | + */ |
| 124 | + public static List<String> getLookUpNamesSortedByTitle() { |
| 125 | + return java.util.Arrays.stream(DocumentationEntry.values()) |
| 126 | + .sorted(java.util.Comparator.comparing(DocumentationEntry::getTitle)) |
| 127 | + .map(entry -> entry.lookUpName) |
| 128 | + .toList(); |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Returns the {@code DocumentationEntry} associated with the given lookup name, or {@code null} if not found. |
| 133 | + * |
| 134 | + * @param lookUpName the lookup name to search for |
| 135 | + * |
| 136 | + * @return the corresponding {@code DocumentationEntry} if found; {@code null} otherwise |
| 137 | + * |
| 138 | + * @author Illiani |
| 139 | + * @since 0.50.07 |
| 140 | + */ |
| 141 | + public static DocumentationEntry getDocumentationEntryFromLookUpName(String lookUpName) { |
| 142 | + for (DocumentationEntry entry : DocumentationEntry.values()) { |
| 143 | + if (entry.lookUpName.equals(lookUpName)) { |
| 144 | + return entry; |
| 145 | + } |
| 146 | + } |
| 147 | + return null; |
| 148 | + } |
| 149 | +} |
0 commit comments