Fixed loading the background image
This commit is contained in:
parent
5132d09953
commit
f940e42518
@ -40,6 +40,7 @@ import com.openeggbert.screens.InitScreen;
|
|||||||
import com.openeggbert.gdx.storage.Storage;
|
import com.openeggbert.gdx.storage.Storage;
|
||||||
import com.openeggbert.gdx.storage.StorageImplementationLoader;
|
import com.openeggbert.gdx.storage.StorageImplementationLoader;
|
||||||
import com.openeggbert.utils.OpenEggbertDisplayMode;
|
import com.openeggbert.utils.OpenEggbertDisplayMode;
|
||||||
|
import com.openeggbert.utils.OpenEggbertUtils;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -156,7 +157,7 @@ public class OpenEggbertGame extends Game {
|
|||||||
|
|
||||||
public void loadImageTexture(FileHandle fileHandle) {
|
public void loadImageTexture(FileHandle fileHandle) {
|
||||||
Texture texture = new Texture(fileHandle);
|
Texture texture = new Texture(fileHandle);
|
||||||
imageTextures.put(fileHandle.name().toUpperCase(), texture);
|
imageTextures.put(OpenEggbertUtils.getFileNameWithoutExtension(fileHandle.name().toUpperCase()), texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean existsImageTexture(String key) {
|
public boolean existsImageTexture(String key) {
|
||||||
|
@ -26,9 +26,12 @@ import com.badlogic.gdx.ScreenAdapter;
|
|||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
import com.openeggbert.entity.common.GameFileType;
|
||||||
import com.openeggbert.entity.common.OpenEggbertException;
|
import com.openeggbert.entity.common.OpenEggbertException;
|
||||||
import com.openeggbert.entity.common.OpenEggbertScreenType;
|
import com.openeggbert.entity.common.OpenEggbertScreenType;
|
||||||
import com.openeggbert.main.OpenEggbertGame;
|
import com.openeggbert.main.OpenEggbertGame;
|
||||||
|
import com.openeggbert.utils.OpenEggbertUtils;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,54 +66,49 @@ public abstract class AbstractOpenEggbertScreen extends ScreenAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadBackgroundTextureIfNeeded() {
|
private void loadBackgroundTextureIfNeeded() {
|
||||||
if(true) return;//todo
|
//if(true) return;//todo
|
||||||
if (getBackgroundFileName().isEmpty()) {
|
if (getBackgroundFileName().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String fileName = getBackgroundFileName();
|
String fileName = getBackgroundFileName();
|
||||||
if (!game.existsImageTexture(fileName)) {
|
List<String> possibleFileNames = OpenEggbertUtils.createPossibleFileNames(GameFileType.IMAGE8, fileName);
|
||||||
String nameUpperCase = game.getGameSpace().getImage08Directory() + "/" + fileName;
|
for(String possibleFileName: possibleFileNames) {
|
||||||
String nameLowerCase = game.getGameSpace().getImage08Directory() + "/" + fileName.toLowerCase();
|
if (!game.existsImageTexture(possibleFileName)) {
|
||||||
|
String name = game.getGameSpace().getImage08Directory() + "/" + possibleFileName;
|
||||||
|
|
||||||
Gdx.app.setLogLevel(LOG_INFO);
|
Gdx.app.setLogLevel(LOG_INFO);
|
||||||
Gdx.app.log("screen","nameUpperCase=" + nameUpperCase);
|
Gdx.app.log("screen","name=" + name);
|
||||||
Gdx.app.log("screen","nameLowerCase=" + nameLowerCase);
|
FileHandle fileHandle = null;
|
||||||
FileHandle fileHandleUpperCase = null;
|
|
||||||
FileHandle fileHandleLowerCase = null;
|
|
||||||
if (game.getGameSpace().isEmbeddedAssets()) {
|
if (game.getGameSpace().isEmbeddedAssets()) {
|
||||||
|
|
||||||
if (Gdx.app.getType() == Application.ApplicationType.Android || Gdx.app.getType() == Application.ApplicationType.WebGL) {
|
if (Gdx.app.getType() == Application.ApplicationType.Android || Gdx.app.getType() == Application.ApplicationType.WebGL) {
|
||||||
Gdx.app.log("screen","loading from internal");
|
Gdx.app.log("screen","loading from internal");
|
||||||
fileHandleUpperCase = Gdx.files.internal(nameUpperCase);
|
fileHandle = Gdx.files.internal(name);
|
||||||
fileHandleLowerCase = Gdx.files.internal(nameLowerCase);
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Gdx.app.log("screen","loading from classpath");
|
Gdx.app.log("screen","loading from classpath");
|
||||||
fileHandleUpperCase = Gdx.files.classpath(nameUpperCase);
|
fileHandle = Gdx.files.classpath(name);
|
||||||
fileHandleLowerCase = Gdx.files.classpath(nameLowerCase);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Gdx.app.log("screen","loading from absolute");
|
Gdx.app.log("screen","loading from absolute");
|
||||||
|
|
||||||
fileHandleUpperCase = Gdx.files.absolute(nameUpperCase);
|
fileHandle = Gdx.files.absolute(name);
|
||||||
fileHandleLowerCase = Gdx.files.absolute(nameLowerCase);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gdx.app.log("screen", "fileHandleUpperCase.exists()=" + fileHandleUpperCase.exists());
|
Gdx.app.log("screen", "fileHandleUpperCase.exists()=" + fileHandle.exists());
|
||||||
Gdx.app.log("screen", "fileHandleLowerCase.exists()=" + fileHandleLowerCase.exists());
|
|
||||||
|
|
||||||
if (fileHandleUpperCase.exists()) {
|
if (fileHandle.exists()) {
|
||||||
game.loadImageTexture(fileHandleUpperCase);
|
game.loadImageTexture(fileHandle);
|
||||||
} else {
|
break;
|
||||||
if (fileHandleLowerCase.exists()) {
|
}
|
||||||
game.loadImageTexture(fileHandleLowerCase);
|
// else {
|
||||||
} else {
|
// throw new OpenEggbertException("Could not load file: " + fileName);
|
||||||
throw new OpenEggbertException("Could not load file: " + fileName);
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ public class GameSpaceListScreen extends AbstractOpenEggbertScreen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderOpenEggbertScreen(float delta) {
|
public void renderOpenEggbertScreen(float delta) {
|
||||||
Gdx.app.log(getClass().getName(), game.getStorage().debug());
|
//Gdx.app.log(getClass().getName(), game.getStorage().debug());
|
||||||
|
|
||||||
timeSeconds += Gdx.graphics.getRawDeltaTime();
|
timeSeconds += Gdx.graphics.getRawDeltaTime();
|
||||||
if (timeSeconds > 60) {
|
if (timeSeconds > 60) {
|
||||||
|
@ -101,6 +101,9 @@ public class OpenEggbertUtils {
|
|||||||
private static final String IMAGE = "IMAGE";
|
private static final String IMAGE = "IMAGE";
|
||||||
|
|
||||||
public static String getFileNameWithoutExtension(String fileName) {
|
public static String getFileNameWithoutExtension(String fileName) {
|
||||||
|
if(!fileName.contains(".")) {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
int dotIndex = -1;
|
int dotIndex = -1;
|
||||||
for (int i = fileName.length() - 1; i >= 0; i--) {
|
for (int i = fileName.length() - 1; i >= 0; i--) {
|
||||||
char ch = fileName.charAt(i);
|
char ch = fileName.charAt(i);
|
||||||
|
Reference in New Issue
Block a user