diff --git a/core/src/main/java/com/openeggbert/core/main/OpenEggbertGame.java b/core/src/main/java/com/openeggbert/core/main/OpenEggbertGame.java
index 313b0e0..81f350f 100644
--- a/core/src/main/java/com/openeggbert/core/main/OpenEggbertGame.java
+++ b/core/src/main/java/com/openeggbert/core/main/OpenEggbertGame.java
@@ -37,7 +37,7 @@ import com.openeggbert.core.mod.ModIdentification;
import com.openeggbert.core.screen.GameSpaceListScreen;
import com.openeggbert.core.screen.InitScreen;
import com.pixelgamelibrary.storage.Storage;
-import com.pixelgamelibrary.storage.StorageImplementationLoader;
+import com.pixelgamelibrary.backends.libgdx.storage.StorageFactory;
import com.openeggbert.core.configuration.OpenEggbertDisplayMode;
import com.pixelgamelibrary.Game;
import com.openeggbert.core.utils.OpenEggbertUtils;
@@ -90,7 +90,7 @@ public class OpenEggbertGame extends Game {
public Storage getStorage() {
if(storage == null) {
- this.storage = StorageImplementationLoader.getStorage();
+ this.storage = StorageFactory.getStorage();
}
return storage;
}
diff --git a/core/src/main/java/com/pixelgamelibrary/storage/GdxStorageUtils.java b/core/src/main/java/com/pixelgamelibrary/api/AppI.java
similarity index 59%
rename from core/src/main/java/com/pixelgamelibrary/storage/GdxStorageUtils.java
rename to core/src/main/java/com/pixelgamelibrary/api/AppI.java
index d0a7956..2a6fafe 100644
--- a/core/src/main/java/com/pixelgamelibrary/storage/GdxStorageUtils.java
+++ b/core/src/main/java/com/pixelgamelibrary/api/AppI.java
@@ -13,38 +13,19 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
-// along with this program. If not, see
+// along with this program. If not, see
// or write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
-package com.pixelgamelibrary.storage;
-
-import com.badlogic.gdx.utils.Base64Coder;
+package com.pixelgamelibrary.api;
/**
*
* @author robertvokac
*/
-public class GdxStorageUtils {
+public interface AppI {
+ void log(String msg);
+ void error(String msg);
+ void debug(String msg);
- private GdxStorageUtils() {
- //Not meant to be instantiated.
- }
-
- public static String decodeBase64AsString(String string) {
- return new String(decodeBase64AsByteArray(string));
- }
-
- public static byte[] decodeBase64AsByteArray(String string) {
- return Base64Coder.decode(string);
- }
-
- public static String encodeToBase64(String string) {
- return encodeToBase64(string.getBytes());
- }
-
- public static String encodeToBase64(byte[] data) {
- return String.valueOf(Base64Coder.encode(data));
- }
-
}
diff --git a/core/src/main/java/com/pixelgamelibrary/api/PixelBackend.java b/core/src/main/java/com/pixelgamelibrary/api/PixelBackend.java
index a4c40a1..d437bf8 100644
--- a/core/src/main/java/com/pixelgamelibrary/api/PixelBackend.java
+++ b/core/src/main/java/com/pixelgamelibrary/api/PixelBackend.java
@@ -27,8 +27,9 @@ import com.pixelgamelibrary.Platform;
*/
public interface PixelBackend {
- void exit();
+
Platform getPlatform();
+ AppI app();
GraphicsI graphics();
AudioI audio();
InputI input();
@@ -36,5 +37,6 @@ public interface PixelBackend {
AssetI asset();
StorageI storage();
UtilsI utils();
+ void exit();
}
diff --git a/core/src/main/java/com/pixelgamelibrary/api/UtilsI.java b/core/src/main/java/com/pixelgamelibrary/api/UtilsI.java
index 0813175..6a31226 100644
--- a/core/src/main/java/com/pixelgamelibrary/api/UtilsI.java
+++ b/core/src/main/java/com/pixelgamelibrary/api/UtilsI.java
@@ -19,10 +19,23 @@
///////////////////////////////////////////////////////////////////////////////////////////////
package com.pixelgamelibrary.api;
+import com.badlogic.gdx.utils.Base64Coder;
+
/**
*
* @author robertvokac
*/
public interface UtilsI {
XmlElement parseXml(String xmlString);
+ default String decodeBase64AsString(String string) {
+ return new String(decodeBase64AsByteArray(string));
+ }
+
+ byte[] decodeBase64AsByteArray(String string);
+
+ default String encodeToBase64(String string) {
+ return encodeToBase64(string.getBytes());
+ }
+
+ String encodeToBase64(byte[] data);
}
diff --git a/core/src/main/java/com/pixelgamelibrary/backends/libgdx/AppLibGDXImpl.java b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/AppLibGDXImpl.java
new file mode 100644
index 0000000..e65ebfb
--- /dev/null
+++ b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/AppLibGDXImpl.java
@@ -0,0 +1,57 @@
+///////////////////////////////////////////////////////////////////////////////////////////////
+// Pixel: Game library.
+// Copyright (C) 2024 the original author or authors.
+//
+// This program is free software: you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation, either version 3
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see
+// or write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+///////////////////////////////////////////////////////////////////////////////////////////////
+package com.pixelgamelibrary.backends.libgdx;
+
+import com.badlogic.gdx.Application;
+import com.badlogic.gdx.Gdx;
+import com.pixelgamelibrary.api.AppI;
+
+/**
+ *
+ * @author robertvokac
+ */
+public class AppLibGDXImpl implements AppI {
+
+ @Override
+ public void log(String msg) {
+ Application app = Gdx.app;
+ if (app != null) {
+ Gdx.app.log(getClass().getName(), msg);
+ }
+ }
+
+ @Override
+ public void error(String msg) {
+
+ Application app = Gdx.app;
+ if (app != null) {
+ Gdx.app.error(getClass().getName(), msg);
+ }
+ }
+
+ @Override
+ public void debug(String msg) {
+ Application app = Gdx.app;
+ if (app != null) {
+ Gdx.app.debug(getClass().getName(), msg);
+ }
+ }
+
+}
diff --git a/core/src/main/java/com/pixelgamelibrary/backends/libgdx/PixelLibGDXBackend.java b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/PixelLibGDXBackend.java
index 767a428..f1db692 100644
--- a/core/src/main/java/com/pixelgamelibrary/backends/libgdx/PixelLibGDXBackend.java
+++ b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/PixelLibGDXBackend.java
@@ -24,6 +24,7 @@ import static com.badlogic.gdx.Application.ApplicationType.Desktop;
import com.badlogic.gdx.Gdx;
import com.pixelgamelibrary.PixelException;
import com.pixelgamelibrary.Platform;
+import com.pixelgamelibrary.api.AppI;
import com.pixelgamelibrary.api.AssetI;
import com.pixelgamelibrary.api.AudioI;
import com.pixelgamelibrary.api.GraphicsI;
@@ -39,6 +40,7 @@ import com.pixelgamelibrary.api.PixelBackend;
*/
public class PixelLibGDXBackend implements PixelBackend {
+ private AppI pixelAppLibGdxImpl = null;
private GraphicsI pixelGraphicsLibGdxImpl = null;
private AudioI pixelAudioLibGdxImpl = null;
private InputI pixelInputLibGdxImpl = null;
@@ -128,4 +130,11 @@ public class PixelLibGDXBackend implements PixelBackend {
}
return pixelUtilsLibGdxImpl; }
+ @Override
+ public AppI app() {
+ if (pixelAppLibGdxImpl == null) {
+ pixelAppLibGdxImpl = new AppLibGDXImpl();
+ }
+ return pixelAppLibGdxImpl; }
+
}
diff --git a/core/src/main/java/com/pixelgamelibrary/backends/libgdx/UtilsLibGDXImpl.java b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/UtilsLibGDXImpl.java
index e7f521b..c9cd715 100644
--- a/core/src/main/java/com/pixelgamelibrary/backends/libgdx/UtilsLibGDXImpl.java
+++ b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/UtilsLibGDXImpl.java
@@ -19,6 +19,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////
package com.pixelgamelibrary.backends.libgdx;
+import com.badlogic.gdx.utils.Base64Coder;
import com.badlogic.gdx.utils.XmlReader;
import com.pixelgamelibrary.api.XmlElement;
import com.pixelgamelibrary.api.UtilsI;
@@ -36,6 +37,13 @@ public class UtilsLibGDXImpl implements UtilsI {
}
+ public byte[] decodeBase64AsByteArray(String string) {
+ return Base64Coder.decode(string);
+ }
+
+ public String encodeToBase64(byte[] data) {
+ return String.valueOf(Base64Coder.encode(data));
+ }
}
diff --git a/core/src/main/java/com/pixelgamelibrary/storage/filesystem/AndroidStorage.java b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/AndroidStorage.java
similarity index 95%
rename from core/src/main/java/com/pixelgamelibrary/storage/filesystem/AndroidStorage.java
rename to core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/AndroidStorage.java
index f2fe3eb..ea3673c 100644
--- a/core/src/main/java/com/pixelgamelibrary/storage/filesystem/AndroidStorage.java
+++ b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/AndroidStorage.java
@@ -17,7 +17,7 @@
// or write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
-package com.pixelgamelibrary.storage.filesystem;
+package com.pixelgamelibrary.backends.libgdx.storage;
import com.pixelgamelibrary.Platform;
diff --git a/core/src/main/java/com/pixelgamelibrary/storage/filesystem/DesktopAndroidStorage.java b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/DesktopAndroidStorage.java
similarity index 99%
rename from core/src/main/java/com/pixelgamelibrary/storage/filesystem/DesktopAndroidStorage.java
rename to core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/DesktopAndroidStorage.java
index 72995f4..6a18417 100644
--- a/core/src/main/java/com/pixelgamelibrary/storage/filesystem/DesktopAndroidStorage.java
+++ b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/DesktopAndroidStorage.java
@@ -17,7 +17,7 @@
// or write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
-package com.pixelgamelibrary.storage.filesystem;
+package com.pixelgamelibrary.backends.libgdx.storage;
import com.pixelgamelibrary.Platform;
import com.pixelgamelibrary.storage.Storage;
diff --git a/core/src/main/java/com/pixelgamelibrary/storage/filesystem/DesktopStorage.java b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/DesktopStorage.java
similarity index 95%
rename from core/src/main/java/com/pixelgamelibrary/storage/filesystem/DesktopStorage.java
rename to core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/DesktopStorage.java
index 5f5d448..9db1bd9 100644
--- a/core/src/main/java/com/pixelgamelibrary/storage/filesystem/DesktopStorage.java
+++ b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/DesktopStorage.java
@@ -17,7 +17,7 @@
// or write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
-package com.pixelgamelibrary.storage.filesystem;
+package com.pixelgamelibrary.backends.libgdx.storage;
import com.pixelgamelibrary.Platform;
diff --git a/core/src/main/java/com/pixelgamelibrary/storage/map/SimpleLocalStorageMap.java b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/SimpleLocalStorageMap.java
similarity index 96%
rename from core/src/main/java/com/pixelgamelibrary/storage/map/SimpleLocalStorageMap.java
rename to core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/SimpleLocalStorageMap.java
index 499fbac..3aa10ce 100644
--- a/core/src/main/java/com/pixelgamelibrary/storage/map/SimpleLocalStorageMap.java
+++ b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/SimpleLocalStorageMap.java
@@ -17,9 +17,10 @@
// or write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
-package com.pixelgamelibrary.storage.map;
+package com.pixelgamelibrary.backends.libgdx.storage;
import com.badlogic.gdx.Preferences;
+import com.pixelgamelibrary.storage.map.SimpleMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
diff --git a/core/src/main/java/com/pixelgamelibrary/storage/StorageImplementationLoader.java b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/StorageFactory.java
similarity index 82%
rename from core/src/main/java/com/pixelgamelibrary/storage/StorageImplementationLoader.java
rename to core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/StorageFactory.java
index 7a35616..7d9a9f6 100644
--- a/core/src/main/java/com/pixelgamelibrary/storage/StorageImplementationLoader.java
+++ b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/StorageFactory.java
@@ -17,22 +17,21 @@
// or write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
-package com.pixelgamelibrary.storage;
+package com.pixelgamelibrary.backends.libgdx.storage;
-import com.pixelgamelibrary.storage.map.WebGLStorage;
import com.pixelgamelibrary.storage.map.MemoryStorage;
-import com.pixelgamelibrary.storage.filesystem.AndroidStorage;
-import com.pixelgamelibrary.storage.filesystem.DesktopStorage;
import com.pixelgamelibrary.Pixel;
import com.pixelgamelibrary.Platform;
+import com.pixelgamelibrary.storage.Storage;
+import com.pixelgamelibrary.storage.StorageException;
/**
*
* @author robertvokac
*/
-public class StorageImplementationLoader {
+public class StorageFactory {
- private StorageImplementationLoader() {
+ private StorageFactory() {
//Not meant to be instantiated.
}
private static Storage storage = null;
@@ -55,7 +54,7 @@ public class StorageImplementationLoader {
}
}
if (storage == null) {
- throw new GdxStorageException("Platform is not supported: " + platform);
+ throw new StorageException("Platform is not supported: " + platform);
}
return storage;
}
diff --git a/core/src/main/java/com/pixelgamelibrary/storage/map/WebGLStorage.java b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/WebGLStorage.java
similarity index 87%
rename from core/src/main/java/com/pixelgamelibrary/storage/map/WebGLStorage.java
rename to core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/WebGLStorage.java
index 67fe162..f86895e 100644
--- a/core/src/main/java/com/pixelgamelibrary/storage/map/WebGLStorage.java
+++ b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/WebGLStorage.java
@@ -17,27 +17,32 @@
// or write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
-package com.pixelgamelibrary.storage.map;
+package com.pixelgamelibrary.backends.libgdx.storage;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.pixelgamelibrary.Platform;
+import com.pixelgamelibrary.storage.map.MapStorage;
/**
*
* @author robertvokac
*/
public class WebGLStorage extends MapStorage {
+
public Platform getPlatform() {
return Platform.WEB;
}
+
public WebGLStorage() {
- this("open-eggbert.webGL.Local-Storage");
+ this("pixel.libgdx.webGL.Local-Storage");
}
+
public WebGLStorage(String preferencesName) {
this(Gdx.app.getPreferences(preferencesName));
}
- public WebGLStorage(Preferences preferences) {
+
+ public WebGLStorage(Preferences preferences) {
super(new SimpleLocalStorageMap(preferences));
}
diff --git a/core/src/main/java/com/pixelgamelibrary/storage/GdxStorageException.java b/core/src/main/java/com/pixelgamelibrary/storage/StorageException.java
similarity index 88%
rename from core/src/main/java/com/pixelgamelibrary/storage/GdxStorageException.java
rename to core/src/main/java/com/pixelgamelibrary/storage/StorageException.java
index 75f094f..c24f9d9 100644
--- a/core/src/main/java/com/pixelgamelibrary/storage/GdxStorageException.java
+++ b/core/src/main/java/com/pixelgamelibrary/storage/StorageException.java
@@ -19,13 +19,15 @@
///////////////////////////////////////////////////////////////////////////////////////////////
package com.pixelgamelibrary.storage;
+import com.pixelgamelibrary.PixelException;
+
/**
*
* @author robertvokac
*/
-public class GdxStorageException extends RuntimeException {
+public class StorageException extends PixelException {
- public GdxStorageException(String string) {
+ public StorageException(String string) {
super(string);
}
diff --git a/core/src/main/java/com/pixelgamelibrary/storage/map/MapFileType.java b/core/src/main/java/com/pixelgamelibrary/storage/map/MapFileType.java
index debd12b..38f36bb 100644
--- a/core/src/main/java/com/pixelgamelibrary/storage/map/MapFileType.java
+++ b/core/src/main/java/com/pixelgamelibrary/storage/map/MapFileType.java
@@ -19,7 +19,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////
package com.pixelgamelibrary.storage.map;
-import com.pixelgamelibrary.storage.GdxStorageException;
+import com.pixelgamelibrary.storage.StorageException;
/**
@@ -31,7 +31,7 @@ public enum MapFileType {
public static MapFileType ofKey(String key, SimpleMap map) {
if (!map.contains(key)) {
- throw new GdxStorageException("Map does not contain key: " + key);
+ throw new StorageException("Map does not contain key: " + key);
}
String value = map.getString(key);
if (value.startsWith(FILE.name())) {
@@ -40,7 +40,7 @@ public enum MapFileType {
if (value.startsWith(DIRECTORY.name())) {
return DIRECTORY;
}
- throw new GdxStorageException("Unsupported MapFileType for key in the map: " + key);
+ throw new StorageException("Unsupported MapFileType for key in the map: " + key);
}
diff --git a/core/src/main/java/com/pixelgamelibrary/storage/map/MapStorage.java b/core/src/main/java/com/pixelgamelibrary/storage/map/MapStorage.java
index 979b169..aafec40 100644
--- a/core/src/main/java/com/pixelgamelibrary/storage/map/MapStorage.java
+++ b/core/src/main/java/com/pixelgamelibrary/storage/map/MapStorage.java
@@ -19,11 +19,10 @@
///////////////////////////////////////////////////////////////////////////////////////////////
package com.pixelgamelibrary.storage.map;
-import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
+import com.pixelgamelibrary.Pixel;
import com.pixelgamelibrary.Platform;
-import com.pixelgamelibrary.storage.GdxStorageException;
-import com.pixelgamelibrary.storage.GdxStorageUtils;
+import com.pixelgamelibrary.storage.StorageException;
import com.pixelgamelibrary.storage.Storage;
import java.util.List;
import java.util.stream.Collectors;
@@ -83,13 +82,7 @@ public class MapStorage implements Storage {
workingDirectory = absolutePath;
return "";
}
- private static final String SLASH = "/";
-
- private void logError(String msg) {
- Application app = Gdx.app;
- if(app != null) Gdx.app.error(getClass().getName(), msg);
- }
-
+ private static final String SLASH = "/";
@Override
public String mkdir(String path) {
@@ -125,10 +118,10 @@ public class MapStorage implements Storage {
private static String getParentPath(String path) {
// System.out.println("getParentPath()");
if (path == null) {
- throw new GdxStorageException("Path is null");
+ throw new StorageException("Path is null");
}
if (path.trim().isEmpty()) {
- throw new GdxStorageException("Path is empty");
+ throw new StorageException("Path is empty");
}
if (path.equals("/")) {
@@ -219,10 +212,10 @@ public class MapStorage implements Storage {
private String moveOrCp(String source, String target, boolean move, boolean cp) {
if (move && cp) {
- throw new GdxStorageException("move == true && cp == true");
+ throw new StorageException("move == true && cp == true");
}
if (!move && !cp) {
- throw new GdxStorageException("move != true && cp != true");
+ throw new StorageException("move != true && cp != true");
}
String absolutePathSource = convertToAbsolutePathIfNeeded(source);
String absolutePathTarget = convertToAbsolutePathIfNeeded(target);
@@ -288,7 +281,7 @@ public class MapStorage implements Storage {
return null;
}
text = text.substring(BINARYFILE.length());
- return GdxStorageUtils.decodeBase64AsByteArray(text);
+ return Pixel.get().utils().decodeBase64AsByteArray(text);
}
private static final String BINARYFILE = "BINARYFILE";
@@ -299,7 +292,7 @@ public class MapStorage implements Storage {
@Override
public String savebin(String name, byte[] data) {
- return savetext(name, BINARYFILE + GdxStorageUtils.encodeToBase64(data));
+ return savetext(name, BINARYFILE + Pixel.get().utils().encodeToBase64(data));
}
@Override
@@ -344,4 +337,8 @@ public class MapStorage implements Storage {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
+ private void logError(String msg) {
+ Pixel.get().app().error(msg);
+ }
+
}