this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

AssetManager.listDirectory: upgrade AssetHandle to subclasses

+23 -7
+17
src/main/java/assets/AssetHandle.java
··· 2 2 3 3 import java.io.File; 4 4 5 + import assets.ui.BackgroundAsset; 6 + import assets.ui.MapAsset; 7 + import assets.ui.TexturesAsset; 8 + 5 9 public class AssetHandle extends File 6 10 { 7 11 public final File assetDir; ··· 30 34 } 31 35 32 36 public String getAssetDescription() { 37 + return null; 38 + } 39 + 40 + /** 41 + * Upgrades a plain AssetHandle to a typed subclass based on file extension. 42 + * Returns null if the file doesn't match any known asset type. 43 + */ 44 + public static AssetHandle upgrade(AssetHandle handle) 45 + { 46 + String name = handle.getAssetName(); 47 + if (name.endsWith(".xml")) return new MapAsset(handle); 48 + if (name.endsWith(".png")) return new BackgroundAsset(handle); 49 + if (name.endsWith(".json")) return new TexturesAsset(handle); 33 50 return null; 34 51 } 35 52 }
+6 -7
src/main/java/assets/AssetManager.java
··· 267 267 for (Path entry : stream) { 268 268 String name = entry.getFileName().toString(); 269 269 270 - if (Files.isDirectory(entry)) { 270 + String relPath = relativePath + name; 271 + AssetHandle ah = new AssetHandle(stackDir, relPath); 272 + AssetHandle upgraded = AssetHandle.upgrade(ah); 273 + if (upgraded != null) 274 + fileMap.putIfAbsent(name, upgraded); 275 + else if (Files.isDirectory(entry)) 271 276 subdirSet.add(name); 272 - } 273 - else { 274 - String relPath = relativePath + name; 275 - AssetHandle ah = new AssetHandle(stackDir, relPath); 276 - fileMap.putIfAbsent(name, ah); 277 - } 278 277 } 279 278 } 280 279 catch (IOException e) {