Defer item inv file finish loading to future frame

This commit is contained in:
Collin Smith 2020-01-01 03:20:44 -08:00
parent ff7a27d334
commit a1bca12d62
2 changed files with 13 additions and 4 deletions

View File

@ -384,9 +384,7 @@ public class Item extends Actor implements Disposable {
if (invFileDescriptor != null) return;
invFileDescriptor = new AssetDescriptor<>("data\\global\\items\\" + getInvFileName() + '.' + DC6.EXT, DC6.class);
Riiablo.assets.load(invFileDescriptor);
Riiablo.assets.finishLoadingAsset(invFileDescriptor);
invFile = Riiablo.assets.get(invFileDescriptor);
resize();
checkLoaded();
invColormap = Riiablo.colormaps.get(base.InvTrans);
String invColor = getInvColor();
@ -399,6 +397,16 @@ public class Item extends Actor implements Disposable {
// TODO: load the images of socketed items
}
public boolean checkLoaded() {
boolean b = Riiablo.assets.isLoaded(invFileDescriptor);
if (b && invFile == null) {
invFile = Riiablo.assets.get(invFileDescriptor);
resize();
}
return b;
}
@Override
public void dispose() {
Riiablo.assets.unload(invFileDescriptor.fileName);
@ -806,6 +814,7 @@ public class Item extends Actor implements Disposable {
@Override
public void draw(Batch batch, float a) {
if (invFile == null && !checkLoaded()) return;
PaletteIndexedBatch b = (PaletteIndexedBatch) batch;
boolean ethereal = (flags & ETHEREAL) == ETHEREAL;
if (ethereal) b.setAlpha(ETHEREAL_ALPHA);

View File

@ -386,7 +386,7 @@ public class InventoryPanel extends WidgetGroup implements Disposable {
}
// FIXME: Alt images on weapons are slightly off by maybe a pixel or so (rounding?) -- backgrounds fine
if (item != null) {
if (item != null && item.checkLoaded()) {
BBox box = item.invFile.getBox();
item.setPosition(
getX() + getWidth() / 2 - box.width / 2f + x,