mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[libgdx] SkeletonViewer, reload if the atlas file changes.
This commit is contained in:
parent
07cf3f1f2c
commit
d5f5ff004f
@ -111,7 +111,7 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
Skeleton skeleton;
|
Skeleton skeleton;
|
||||||
AnimationState state;
|
AnimationState state;
|
||||||
FileHandle skeletonFile;
|
FileHandle skeletonFile;
|
||||||
long lastModified;
|
long skeletonModified, atlasModified;
|
||||||
float lastModifiedCheck, reloadTimer;
|
float lastModifiedCheck, reloadTimer;
|
||||||
StringBuilder status = new StringBuilder();
|
StringBuilder status = new StringBuilder();
|
||||||
Preferences prefs;
|
Preferences prefs;
|
||||||
@ -144,9 +144,26 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
ui.prefsLoaded = true;
|
ui.prefsLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileHandle atlasFile (FileHandle skeletonFile) {
|
||||||
|
String atlasFileName = skeletonFile.nameWithoutExtension();
|
||||||
|
if (atlasFileName.endsWith(".json") || atlasFileName.endsWith(".skel"))
|
||||||
|
atlasFileName = atlasFileName.substring(0, atlasFileName.length() - 5);
|
||||||
|
FileHandle atlasFile = skeletonFile.sibling(atlasFileName + ".atlas");
|
||||||
|
if (!atlasFile.exists()) {
|
||||||
|
if (atlasFileName.endsWith("-pro") || atlasFileName.endsWith("-ess"))
|
||||||
|
atlasFileName = atlasFileName.substring(0, atlasFileName.length() - 4);
|
||||||
|
for (String suffix : atlasSuffixes) {
|
||||||
|
atlasFile = skeletonFile.sibling(atlasFileName + suffix);
|
||||||
|
if (atlasFile.exists()) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return atlasFile;
|
||||||
|
}
|
||||||
|
|
||||||
void loadSkeleton (final FileHandle skeletonFile) {
|
void loadSkeleton (final FileHandle skeletonFile) {
|
||||||
if (skeletonFile == null) return;
|
if (skeletonFile == null) return;
|
||||||
|
|
||||||
|
FileHandle atlasFile = atlasFile(skeletonFile);
|
||||||
try {
|
try {
|
||||||
// Setup a texture atlas that uses a white image for images not found in the atlas.
|
// Setup a texture atlas that uses a white image for images not found in the atlas.
|
||||||
Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888);
|
Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888);
|
||||||
@ -155,24 +172,12 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
final AtlasRegion fake = new AtlasRegion(new Texture(pixmap), 0, 0, 32, 32);
|
final AtlasRegion fake = new AtlasRegion(new Texture(pixmap), 0, 0, 32, 32);
|
||||||
pixmap.dispose();
|
pixmap.dispose();
|
||||||
|
|
||||||
String atlasFileName = skeletonFile.nameWithoutExtension();
|
TextureAtlasData atlasData = null;
|
||||||
if (atlasFileName.endsWith(".json") || atlasFileName.endsWith(".skel"))
|
if (atlasFile.exists()) {
|
||||||
atlasFileName = atlasFileName.substring(0, atlasFileName.length() - 5);
|
atlasData = new TextureAtlasData(atlasFile, atlasFile.parent(), false);
|
||||||
FileHandle atlasFile = skeletonFile.sibling(atlasFileName + ".atlas");
|
|
||||||
if (!atlasFile.exists()) {
|
|
||||||
if (atlasFileName.endsWith("-pro") || atlasFileName.endsWith("-ess"))
|
|
||||||
atlasFileName = atlasFileName.substring(0, atlasFileName.length() - 4);
|
|
||||||
for (String suffix : atlasSuffixes) {
|
|
||||||
atlasFile = skeletonFile.sibling(atlasFileName + suffix);
|
|
||||||
if (atlasFile.exists()) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TextureAtlasData data = !atlasFile.exists() ? null : new TextureAtlasData(atlasFile, atlasFile.parent(), false);
|
|
||||||
|
|
||||||
if (data != null) {
|
|
||||||
boolean linear = true;
|
boolean linear = true;
|
||||||
for (int i = 0, n = data.getPages().size; i < n; i++) {
|
for (int i = 0, n = atlasData.getPages().size; i < n; i++) {
|
||||||
Page page = data.getPages().get(i);
|
Page page = atlasData.getPages().get(i);
|
||||||
if (page.minFilter != TextureFilter.Linear || page.magFilter != TextureFilter.Linear) {
|
if (page.minFilter != TextureFilter.Linear || page.magFilter != TextureFilter.Linear) {
|
||||||
linear = false;
|
linear = false;
|
||||||
break;
|
break;
|
||||||
@ -181,7 +186,7 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
ui.linearCheckbox.setChecked(linear);
|
ui.linearCheckbox.setChecked(linear);
|
||||||
}
|
}
|
||||||
|
|
||||||
atlas = new TextureAtlas(data) {
|
atlas = new TextureAtlas(atlasData) {
|
||||||
public AtlasRegion findRegion (String name) {
|
public AtlasRegion findRegion (String name) {
|
||||||
AtlasRegion region = super.findRegion(name);
|
AtlasRegion region = super.findRegion(name);
|
||||||
if (region == null) {
|
if (region == null) {
|
||||||
@ -232,10 +237,11 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.skeletonFile = skeletonFile;
|
this.skeletonFile = skeletonFile;
|
||||||
|
skeletonModified = skeletonFile.lastModified();
|
||||||
|
atlasModified = atlasFile.lastModified();
|
||||||
|
lastModifiedCheck = checkModifiedInterval;
|
||||||
prefs.putString("lastFile", skeletonFile.path());
|
prefs.putString("lastFile", skeletonFile.path());
|
||||||
prefs.flush();
|
prefs.flush();
|
||||||
lastModified = skeletonFile.lastModified();
|
|
||||||
lastModifiedCheck = checkModifiedInterval;
|
|
||||||
|
|
||||||
// Populate UI.
|
// Populate UI.
|
||||||
|
|
||||||
@ -306,7 +312,9 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
if (lastModifiedCheck < 0) {
|
if (lastModifiedCheck < 0) {
|
||||||
lastModifiedCheck = checkModifiedInterval;
|
lastModifiedCheck = checkModifiedInterval;
|
||||||
long time = skeletonFile.lastModified();
|
long time = skeletonFile.lastModified();
|
||||||
if (time != 0 && lastModified != time) reloadTimer = reloadDelay;
|
if (time != 0 && skeletonModified != time) reloadTimer = reloadDelay;
|
||||||
|
time = atlasFile(skeletonFile).lastModified();
|
||||||
|
if (time != 0 && atlasModified != time) reloadTimer = reloadDelay;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reloadTimer -= delta;
|
reloadTimer -= delta;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user