Minor Skeleton Viewer improvements.

This commit is contained in:
Nathan Sweet 2021-03-01 17:51:42 +01:00
parent 688d855006
commit 8f7a9254f4
2 changed files with 9 additions and 10 deletions

View File

@ -116,9 +116,11 @@ public class SkeletonViewer extends ApplicationAdapter {
} }
} }
void loadSkeleton (final @Null FileHandle skeletonFile) { boolean loadSkeleton (final @Null FileHandle skeletonFile) {
if (skeletonFile == null) return; if (skeletonFile == null) return false;
FileHandle oldSkeletonFile = this.skeletonFile;
this.skeletonFile = skeletonFile; this.skeletonFile = skeletonFile;
reloadTimer = 0;
try { try {
atlas = new SkeletonViewAtlas(this, skeletonFile); atlas = new SkeletonViewAtlas(this, skeletonFile);
@ -137,9 +139,8 @@ public class SkeletonViewer extends ApplicationAdapter {
System.out.println("Error loading skeleton: " + skeletonFile.file().getAbsolutePath()); System.out.println("Error loading skeleton: " + skeletonFile.file().getAbsolutePath());
ex.printStackTrace(); ex.printStackTrace();
ui.toast("Error loading skeleton: " + skeletonFile.name()); ui.toast("Error loading skeleton: " + skeletonFile.name());
lastModifiedCheck = 5; this.skeletonFile = oldSkeletonFile;
this.skeletonFile = null; return false;
return;
} }
skeleton = new Skeleton(skeletonData); skeleton = new Skeleton(skeletonData);
@ -150,7 +151,6 @@ public class SkeletonViewer extends ApplicationAdapter {
state = new AnimationState(new AnimationStateData(skeletonData)); state = new AnimationState(new AnimationStateData(skeletonData));
state.addListener(new AnimationStateAdapter() { state.addListener(new AnimationStateAdapter() {
public void event (TrackEntry entry, Event event) { public void event (TrackEntry entry, Event event) {
ui.toast(event.getData().getName()); ui.toast(event.getData().getName());
} }
@ -166,7 +166,6 @@ public class SkeletonViewer extends ApplicationAdapter {
ui.window.getTitleLabel().setText(skeletonFile.name()); ui.window.getTitleLabel().setText(skeletonFile.name());
{ {
Array<String> items = new Array(); Array<String> items = new Array();
for (Skin skin : skeletonData.getSkins()) for (Skin skin : skeletonData.getSkins())
items.add(skin.getName()); items.add(skin.getName());
@ -184,6 +183,7 @@ public class SkeletonViewer extends ApplicationAdapter {
if (ui.skinList.getSelected() != null) skeleton.setSkin(ui.skinList.getSelected()); if (ui.skinList.getSelected() != null) skeleton.setSkin(ui.skinList.getSelected());
setAnimation(); setAnimation();
return true;
} }
void setAnimation () { void setAnimation () {
@ -232,7 +232,7 @@ public class SkeletonViewer extends ApplicationAdapter {
long time = skeletonFile.lastModified(); long time = skeletonFile.lastModified();
if (time != 0 && skeletonModified != time) reloadTimer = reloadDelay; if (time != 0 && skeletonModified != time) reloadTimer = reloadDelay;
time = atlas.lastModified(); time = atlas.lastModified();
if (time != 0 && atlasModified != time) reloadTimer = reloadDelay; if (time != 0 && atlasModified != 0 && atlasModified != time) reloadTimer = reloadDelay;
} }
} else { } else {
reloadTimer -= delta; reloadTimer -= delta;

View File

@ -331,8 +331,7 @@ class SkeletonViewerUI {
String name = fileDialog.getFile(); String name = fileDialog.getFile();
String dir = fileDialog.getDirectory(); String dir = fileDialog.getDirectory();
if (name == null || dir == null) return; if (name == null || dir == null) return;
viewer.loadSkeleton(new FileHandle(new File(dir, name).getAbsolutePath())); if (viewer.loadSkeleton(new FileHandle(new File(dir, name).getAbsolutePath()))) toast("Loaded.");
toast("Loaded.");
} }
}); });