Pārlūkot izejas kodu

[libgdx] SkeletonViewer, even better handling of atlas file look up.

Nathan Sweet 5 gadi atpakaļ
vecāks
revīzija
30e7812d1f

+ 25 - 17
spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java

@@ -93,7 +93,9 @@ public class SkeletonViewer extends ApplicationAdapter {
 	static final float checkModifiedInterval = 0.250f;
 	static final float checkModifiedInterval = 0.250f;
 	static final float reloadDelay = 1;
 	static final float reloadDelay = 1;
 	static float uiScale = 1;
 	static float uiScale = 1;
-	static String[] atlasSuffixes = {".atlas", ".atlas.txt", "-pro.atlas", "-pro.atlas.txt", "-ess.atlas", "-ess.atlas.txt"};
+	static String[] dataSuffixes = {".json", ".skel"};
+	static String[] atlasSuffixes = {".atlas", "-pro.atlas", "-ess.atlas"};
+	static String[] extraSuffixes = {"", ".txt", ".bytes"};
 	static String[] args;
 	static String[] args;
 
 
 	UI ui;
 	UI ui;
@@ -141,22 +143,27 @@ public class SkeletonViewer extends ApplicationAdapter {
 	}
 	}
 
 
 	FileHandle atlasFile (FileHandle skeletonFile) {
 	FileHandle atlasFile (FileHandle skeletonFile) {
-		String atlasFileName = skeletonFile.nameWithoutExtension();
-		if (atlasFileName.endsWith(".bytes")) atlasFileName = atlasFileName.substring(0, atlasFileName.length() - 6);
-		if (atlasFileName.endsWith(".json") || atlasFileName.endsWith(".skel"))
-			atlasFileName = atlasFileName.substring(0, atlasFileName.length() - 5);
-		if (atlasFileName.endsWith(".bytes")) atlasFileName = atlasFileName.substring(0, atlasFileName.length() - 6);
-		FileHandle atlasFile = skeletonFile.sibling(atlasFileName + ".atlas");
-		if (atlasFile.exists()) atlasFile = skeletonFile.sibling(atlasFileName + ".atlas.txt");
-		if (!atlasFile.exists()) {
-			if (atlasFileName.endsWith("-pro") || atlasFileName.endsWith("-ess"))
-				atlasFileName = atlasFileName.substring(0, atlasFileName.length() - 4);
+		String baseName = skeletonFile.name();
+		for (String extraSuffix : extraSuffixes) {
+			for (String dataSuffix : dataSuffixes) {
+				String suffix = dataSuffix + extraSuffix;
+				if (baseName.endsWith(suffix)) {
+					FileHandle file = atlasFile(skeletonFile, baseName.substring(0, baseName.length() - suffix.length()));
+					if (file != null) return file;
+				}
+			}
+		}
+		return atlasFile(skeletonFile, baseName);
+	}
+
+	private FileHandle atlasFile (FileHandle skeletonFile, String baseName) {
+		for (String extraSuffix : extraSuffixes) {
 			for (String suffix : atlasSuffixes) {
 			for (String suffix : atlasSuffixes) {
-				atlasFile = skeletonFile.sibling(atlasFileName + suffix);
-				if (atlasFile.exists()) break;
+				FileHandle file = skeletonFile.sibling(baseName + suffix + extraSuffix);
+				if (file.exists()) return file;
 			}
 			}
 		}
 		}
-		return atlasFile;
+		return null;
 	}
 	}
 
 
 	void loadSkeleton (final FileHandle skeletonFile) {
 	void loadSkeleton (final FileHandle skeletonFile) {
@@ -172,7 +179,7 @@ public class SkeletonViewer extends ApplicationAdapter {
 			pixmap.dispose();
 			pixmap.dispose();
 
 
 			TextureAtlasData atlasData = null;
 			TextureAtlasData atlasData = null;
-			if (atlasFile.exists()) {
+			if (atlasFile != null) {
 				atlasData = new TextureAtlasData(atlasFile, atlasFile.parent(), false);
 				atlasData = new TextureAtlasData(atlasFile, atlasFile.parent(), false);
 				boolean linear = true;
 				boolean linear = true;
 				for (int i = 0, n = atlasData.getPages().size; i < n; i++) {
 				for (int i = 0, n = atlasData.getPages().size; i < n; i++) {
@@ -237,7 +244,7 @@ public class SkeletonViewer extends ApplicationAdapter {
 
 
 		this.skeletonFile = skeletonFile;
 		this.skeletonFile = skeletonFile;
 		skeletonModified = skeletonFile.lastModified();
 		skeletonModified = skeletonFile.lastModified();
-		atlasModified = atlasFile.lastModified();
+		atlasModified = atlasFile == null ? 0 : atlasFile.lastModified();
 		lastModifiedCheck = checkModifiedInterval;
 		lastModifiedCheck = checkModifiedInterval;
 		prefs.putString("lastFile", skeletonFile.path());
 		prefs.putString("lastFile", skeletonFile.path());
 		prefs.flush();
 		prefs.flush();
@@ -312,7 +319,8 @@ public class SkeletonViewer extends ApplicationAdapter {
 					lastModifiedCheck = checkModifiedInterval;
 					lastModifiedCheck = checkModifiedInterval;
 					long time = skeletonFile.lastModified();
 					long time = skeletonFile.lastModified();
 					if (time != 0 && skeletonModified != time) reloadTimer = reloadDelay;
 					if (time != 0 && skeletonModified != time) reloadTimer = reloadDelay;
-					time = atlasFile(skeletonFile).lastModified();
+					FileHandle atlasFile = atlasFile(skeletonFile);
+					time = atlasFile == null ? 0 : atlasFile.lastModified();
 					if (time != 0 && atlasModified != time) reloadTimer = reloadDelay;
 					if (time != 0 && atlasModified != time) reloadTimer = reloadDelay;
 				}
 				}
 			} else {
 			} else {