diff --git a/core/src/main/java/com/openeggbert/core/configuration/OpenEggbertDisplayMode.java b/core/src/main/java/com/openeggbert/core/configuration/OpenEggbertDisplayMode.java index 082eb9f..79e5e26 100644 --- a/core/src/main/java/com/openeggbert/core/configuration/OpenEggbertDisplayMode.java +++ b/core/src/main/java/com/openeggbert/core/configuration/OpenEggbertDisplayMode.java @@ -63,7 +63,7 @@ public enum OpenEggbertDisplayMode { } public static OpenEggbertDisplayMode setDisplayMode(OpenEggbertDisplayMode displayMode) { - String result = Pixel.get().graphics().setDisplayMode(displayMode == FULLSCREEN, displayMode == WINDOW); + String result = Pixel.graphics().setDisplayMode(displayMode == FULLSCREEN, displayMode == WINDOW); return result == null ? null : OpenEggbertDisplayMode.valueOf(result); } diff --git a/core/src/main/java/com/openeggbert/core/mod/Mod.java b/core/src/main/java/com/openeggbert/core/mod/Mod.java index 45e3b63..8ef7bc4 100644 --- a/core/src/main/java/com/openeggbert/core/mod/Mod.java +++ b/core/src/main/java/com/openeggbert/core/mod/Mod.java @@ -34,7 +34,7 @@ import lombok.Data; public class Mod { public Mod(String xml) { - XmlElement root = Pixel.get().utils().parseXml(xml); + XmlElement root = Pixel.utils().parseXml(xml); XmlElement parentElement = root.getChildByName("parent"); if (parentElement != null) { parent = new ModIdentification(parentElement); diff --git a/core/src/main/java/com/openeggbert/core/utils/EmbeddedFileHandleFactory.java b/core/src/main/java/com/openeggbert/core/utils/EmbeddedFileHandleFactory.java index acda7d5..f82376a 100644 --- a/core/src/main/java/com/openeggbert/core/utils/EmbeddedFileHandleFactory.java +++ b/core/src/main/java/com/openeggbert/core/utils/EmbeddedFileHandleFactory.java @@ -22,6 +22,7 @@ package com.openeggbert.core.utils; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; import com.pixelgamelibrary.Pixel; +import com.pixelgamelibrary.Platform; /** * @@ -35,7 +36,7 @@ public class EmbeddedFileHandleFactory { public static FileHandle create(String name) { - if (Pixel.get().getPlatform().isAndroid() || Pixel.get().getPlatform().isWeb()) { + if (Pixel.app().isOneOfPlatforms(Platform.ANDROID, Platform.WEB)) { return Gdx.files.internal(name); } else { return Gdx.files.classpath(name); diff --git a/core/src/main/java/com/pixelgamelibrary/Pixel.java b/core/src/main/java/com/pixelgamelibrary/Pixel.java index 03c57e2..62b7791 100644 --- a/core/src/main/java/com/pixelgamelibrary/Pixel.java +++ b/core/src/main/java/com/pixelgamelibrary/Pixel.java @@ -19,7 +19,15 @@ /////////////////////////////////////////////////////////////////////////////////////////////// package com.pixelgamelibrary; +import com.pixelgamelibrary.api.AppI; +import com.pixelgamelibrary.api.AssetI; +import com.pixelgamelibrary.api.AudioI; +import com.pixelgamelibrary.api.GraphicsI; +import com.pixelgamelibrary.api.InputI; +import com.pixelgamelibrary.api.NetI; import com.pixelgamelibrary.api.PixelBackend; +import com.pixelgamelibrary.api.StorageI; +import com.pixelgamelibrary.api.UtilsI; /** * @@ -33,10 +41,44 @@ public class Pixel { //Not meant to be instantiated. } - public static PixelBackend get() { + private static PixelBackend get() { return getBackend(); } + //// + public static AppI app() { + return get().app(); + } + + public static GraphicsI graphics() { + return get().graphics(); + } + + public static AudioI audio() { + return get().audio(); + } + + public static InputI input() { + return get().input(); + } + + public static NetI net() { + return get().net(); + } + + public static AssetI asset() { + return get().asset(); + } + + public static StorageI storage() { + return get().storage(); + } + + public static UtilsI utils() { + return get().utils(); + } + //// + public static void setBackend(PixelBackend pixelBackend) { if (isBackendSet()) { throw new PixelException("Pixel Backend was already set"); @@ -44,7 +86,7 @@ public class Pixel { INSTANCE = pixelBackend; } - public static PixelBackend getBackend() { + private static PixelBackend getBackend() { if (!isBackendSet()) { throw new PixelException("Pixel Backend was not set"); } diff --git a/core/src/main/java/com/pixelgamelibrary/api/AppI.java b/core/src/main/java/com/pixelgamelibrary/api/AppI.java index 2a6fafe..9e5c2cb 100644 --- a/core/src/main/java/com/pixelgamelibrary/api/AppI.java +++ b/core/src/main/java/com/pixelgamelibrary/api/AppI.java @@ -19,11 +19,24 @@ /////////////////////////////////////////////////////////////////////////////////////////////// package com.pixelgamelibrary.api; +import com.pixelgamelibrary.Platform; + /** * * @author robertvokac */ public interface AppI { + Platform getPlatform(); + + default boolean isOneOfPlatforms(Platform ... platforms) { + for(Platform p: platforms) { + if(getPlatform() == p) { + return true; + } + } + return false; + } + void exit(); void log(String msg); void error(String msg); void debug(String msg); diff --git a/core/src/main/java/com/pixelgamelibrary/api/PixelBackend.java b/core/src/main/java/com/pixelgamelibrary/api/PixelBackend.java index d437bf8..abd524a 100644 --- a/core/src/main/java/com/pixelgamelibrary/api/PixelBackend.java +++ b/core/src/main/java/com/pixelgamelibrary/api/PixelBackend.java @@ -28,7 +28,7 @@ import com.pixelgamelibrary.Platform; public interface PixelBackend { - Platform getPlatform(); + AppI app(); GraphicsI graphics(); AudioI audio(); @@ -37,6 +37,5 @@ public interface PixelBackend { AssetI asset(); StorageI storage(); UtilsI utils(); - void exit(); } diff --git a/core/src/main/java/com/pixelgamelibrary/backends/libgdx/AppLibGDXImpl.java b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/AppLibGDXImpl.java index e65ebfb..4e2a840 100644 --- a/core/src/main/java/com/pixelgamelibrary/backends/libgdx/AppLibGDXImpl.java +++ b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/AppLibGDXImpl.java @@ -20,7 +20,12 @@ package com.pixelgamelibrary.backends.libgdx; import com.badlogic.gdx.Application; +import static com.badlogic.gdx.Application.ApplicationType.Android; +import static com.badlogic.gdx.Application.ApplicationType.Desktop; +import static com.badlogic.gdx.Application.ApplicationType.WebGL; import com.badlogic.gdx.Gdx; +import com.pixelgamelibrary.PixelException; +import com.pixelgamelibrary.Platform; import com.pixelgamelibrary.api.AppI; /** @@ -29,6 +34,26 @@ import com.pixelgamelibrary.api.AppI; */ public class AppLibGDXImpl implements AppI { + + @Override + public void exit() { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public Platform getPlatform() { + Application.ApplicationType applicationType = Gdx.app.getType(); + switch (applicationType) { + case Desktop: + return Platform.DESKTOP; + case Android: + return Platform.ANDROID; + case WebGL: + return Platform.WEB; + default: + throw new PixelException("Unsupported platform: " + applicationType); + } + } @Override public void log(String msg) { Application app = Gdx.app; 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 f1db692..c4e339a 100644 --- a/core/src/main/java/com/pixelgamelibrary/backends/libgdx/PixelLibGDXBackend.java +++ b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/PixelLibGDXBackend.java @@ -49,25 +49,6 @@ public class PixelLibGDXBackend implements PixelBackend { private StorageI pixelStorageLibGdxImpl = null; private UtilsI pixelUtilsLibGdxImpl = null; - @Override - public void exit() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody - } - - @Override - public Platform getPlatform() { - Application.ApplicationType applicationType = Gdx.app.getType(); - switch (applicationType) { - case Desktop: - return Platform.DESKTOP; - case Android: - return Platform.ANDROID; - case WebGL: - return Platform.WEB; - default: - throw new PixelException("Unsupported platform: " + applicationType); - } - } @Override public GraphicsI graphics() { diff --git a/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/StorageFactory.java b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/StorageFactory.java index 7d9a9f6..d97e61e 100644 --- a/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/StorageFactory.java +++ b/core/src/main/java/com/pixelgamelibrary/backends/libgdx/storage/StorageFactory.java @@ -37,7 +37,7 @@ public class StorageFactory { private static Storage storage = null; public static Storage getStorage() { - final Platform platform = Pixel.get().getPlatform(); + final Platform platform = Pixel.app().getPlatform(); if (storage == null) { storage = new MemoryStorage(); } 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 aafec40..297745f 100644 --- a/core/src/main/java/com/pixelgamelibrary/storage/map/MapStorage.java +++ b/core/src/main/java/com/pixelgamelibrary/storage/map/MapStorage.java @@ -281,7 +281,7 @@ public class MapStorage implements Storage { return null; } text = text.substring(BINARYFILE.length()); - return Pixel.get().utils().decodeBase64AsByteArray(text); + return Pixel.utils().decodeBase64AsByteArray(text); } private static final String BINARYFILE = "BINARYFILE"; @@ -292,7 +292,7 @@ public class MapStorage implements Storage { @Override public String savebin(String name, byte[] data) { - return savetext(name, BINARYFILE + Pixel.get().utils().encodeToBase64(data)); + return savetext(name, BINARYFILE + Pixel.utils().encodeToBase64(data)); } @Override @@ -338,7 +338,7 @@ public class MapStorage implements Storage { } private void logError(String msg) { - Pixel.get().app().error(msg); + Pixel.app().error(msg); } }