|
4 | 4 | import com.badlogic.gdx.files.FileHandle;
|
5 | 5 | import com.badlogic.gdx.utils.Array;
|
6 | 6 | import com.badlogic.gdx.utils.ArrayMap;
|
| 7 | +import com.badlogic.gdx.utils.ObjectMap; |
7 | 8 | import com.interrupt.api.steam.SteamApi;
|
8 | 9 | import com.interrupt.api.steam.workshop.WorkshopModData;
|
9 | 10 | import com.interrupt.dungeoneer.entities.Door;
|
@@ -82,18 +83,51 @@ public void refresh() {
|
82 | 83 | findMods();
|
83 | 84 | filterMods();
|
84 | 85 | loadExcludesList();
|
| 86 | + |
| 87 | + // Find which path should be the base |
| 88 | + String baseAssetPath = getBaseAssetPath(); |
| 89 | + |
| 90 | + // If the base path is just the prepackaged data, stop here |
| 91 | + if(baseAssetPath.equals(".")) |
| 92 | + return; |
| 93 | + |
| 94 | + // Make sure the new base path is only in once, at the beginning |
| 95 | + modsFound.removeValue(baseAssetPath, false); |
| 96 | + modsFound.set(0, baseAssetPath); |
| 97 | + } |
| 98 | + |
| 99 | + private String getBaseAssetPath() { |
| 100 | + // Check if any of the game data files override the baked in assets. Use the first found. |
| 101 | + ArrayMap<String, GameData> foundGameData = findAllGameData(); |
| 102 | + for(ObjectMap.Entry<String, GameData> mapPair : foundGameData) { |
| 103 | + // Ignore this entry if it is actually the packaged game |
| 104 | + if(mapPair.key.equals(".")) |
| 105 | + continue; |
| 106 | + |
| 107 | + if(mapPair.value.overrideBaseGame) |
| 108 | + return mapPair.key; |
| 109 | + } |
| 110 | + |
| 111 | + // Default to the internally packaged data. |
| 112 | + return "."; |
85 | 113 | }
|
86 | 114 |
|
87 | 115 | private void findMods() {
|
88 | 116 | // reset
|
89 | 117 | allMods.clear();
|
90 | 118 |
|
91 |
| - // add the default search paths |
| 119 | + // add the baked in data path |
92 | 120 | allMods.add(".");
|
93 | 121 |
|
94 | 122 | FileHandle fh = Game.getInternal("mods");
|
95 | 123 | for(FileHandle h : fh.list()) {
|
96 |
| - if(h.isDirectory()) allMods.add("mods/" + h.name()); |
| 124 | + if(h.isDirectory()) { |
| 125 | + String modPath = "mods/" + h.name(); |
| 126 | + |
| 127 | + // Ensure mod paths only get added once |
| 128 | + if(!allMods.contains(modPath, false)) |
| 129 | + allMods.add(modPath); |
| 130 | + } |
97 | 131 | }
|
98 | 132 |
|
99 | 133 | // add any mods subscribed in Steam Workshop
|
@@ -316,19 +350,34 @@ public HashMap<String, LocalizedString> loadLocalizedStrings() {
|
316 | 350 | return combinedLocalizedStrings;
|
317 | 351 | }
|
318 | 352 |
|
319 |
| - public GameData loadGameData() { |
320 |
| - GameData gameData = new GameData(); |
| 353 | + public ArrayMap<String, GameData> findAllGameData() { |
| 354 | + ArrayMap<String, GameData> foundGameData = new ArrayMap<>(); |
321 | 355 |
|
322 | 356 | for(String path : modsFound) {
|
323 | 357 | try {
|
324 | 358 | FileHandle modFile = Game.getInternal(path + "/data/game.dat");
|
325 | 359 | if(modFile.exists() && !pathIsExcluded(path + "/data/game.dat")) {
|
326 | 360 | GameData modData = JsonUtil.fromJson(GameData.class, modFile);
|
327 |
| - gameData.merge(modData); |
| 361 | + foundGameData.put(path, modData); |
328 | 362 | }
|
329 | 363 | }
|
330 | 364 | catch(Exception ex) {
|
331 |
| - Gdx.app.error("Delver", "Error loading mod file " + path + "/data/game.dat"); |
| 365 | + Gdx.app.error("Delver", "Error loading game data file " + path + "/data/game.dat"); |
| 366 | + Logger.logExceptionToFile(ex); |
| 367 | + } |
| 368 | + } |
| 369 | + |
| 370 | + return foundGameData; |
| 371 | + } |
| 372 | + |
| 373 | + public GameData loadGameData() { |
| 374 | + GameData gameData = new GameData(); |
| 375 | + |
| 376 | + for(GameData modData : findAllGameData().values()) { |
| 377 | + try { |
| 378 | + gameData.merge(modData); |
| 379 | + } catch(Exception ex) { |
| 380 | + Gdx.app.error("Delver", ex.getMessage()); |
332 | 381 | Logger.logExceptionToFile(ex);
|
333 | 382 | }
|
334 | 383 | }
|
|
0 commit comments