From dbc5d5558b998b38c88cb6889bff0596eca25963 Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Sat, 12 Oct 2024 11:54:46 +0200 Subject: [PATCH] Bug 18: Separated SpriteBatch and BitmapFont and Texture --- .../libgdx/files/AssetsLibGDXFileSystem.java | 20 ++++ .../libgdx/graphics/LibGdxBitmapFont.java | 88 ++++++++++++++ .../graphics/LibGdxBitmapFontFactory.java | 54 +++++++++ .../libgdx/graphics/LibGdxSpriteBatch.java | 76 +++++++++++++ .../graphics/LibGdxSpriteBatchFactory.java | 36 ++++++ .../libgdx/graphics/LibGdxTexture.java | 107 ++++++++++++++++++ .../libgdx/graphics/LibGdxTextureFactory.java | 54 +++++++++ .../{ => interfaces}/AppLibGDXImpl.java | 28 ++++- .../{ => interfaces}/AudioLibGDXImpl.java | 2 +- .../{ => interfaces}/ElementLibGDXImpl.java | 2 +- .../{ => interfaces}/FilesLibGDXImpl.java | 2 +- .../{ => interfaces}/GraphicsLibGDXImpl.java | 11 +- .../{ => interfaces}/InputLibGDXImpl.java | 2 +- .../{ => interfaces}/InternalLibGDXImpl.java | 2 +- .../{ => interfaces}/NetLibGDXImpl.java | 2 +- .../{ => interfaces}/PixelBackendLibGDX.java | 2 +- .../{ => interfaces}/UtilsLibGDXImpl.java | 2 +- .../libgdx/utils/LibGdxBackendUtils.java | 70 ++++++++++++ 18 files changed, 546 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxBitmapFont.java create mode 100644 src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxBitmapFontFactory.java create mode 100644 src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxSpriteBatch.java create mode 100644 src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxSpriteBatchFactory.java create mode 100644 src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxTexture.java create mode 100644 src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxTextureFactory.java rename src/main/java/com/pixelgamelibrary/backend/libgdx/{ => interfaces}/AppLibGDXImpl.java (86%) rename src/main/java/com/pixelgamelibrary/backend/libgdx/{ => interfaces}/AudioLibGDXImpl.java (96%) rename src/main/java/com/pixelgamelibrary/backend/libgdx/{ => interfaces}/ElementLibGDXImpl.java (97%) rename src/main/java/com/pixelgamelibrary/backend/libgdx/{ => interfaces}/FilesLibGDXImpl.java (98%) rename src/main/java/com/pixelgamelibrary/backend/libgdx/{ => interfaces}/GraphicsLibGDXImpl.java (87%) rename src/main/java/com/pixelgamelibrary/backend/libgdx/{ => interfaces}/InputLibGDXImpl.java (99%) rename src/main/java/com/pixelgamelibrary/backend/libgdx/{ => interfaces}/InternalLibGDXImpl.java (95%) rename src/main/java/com/pixelgamelibrary/backend/libgdx/{ => interfaces}/NetLibGDXImpl.java (98%) rename src/main/java/com/pixelgamelibrary/backend/libgdx/{ => interfaces}/PixelBackendLibGDX.java (98%) rename src/main/java/com/pixelgamelibrary/backend/libgdx/{ => interfaces}/UtilsLibGDXImpl.java (98%) create mode 100644 src/main/java/com/pixelgamelibrary/backend/libgdx/utils/LibGdxBackendUtils.java diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/files/AssetsLibGDXFileSystem.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/files/AssetsLibGDXFileSystem.java index f7baf4d..c8ab845 100644 --- a/src/main/java/com/pixelgamelibrary/backend/libgdx/files/AssetsLibGDXFileSystem.java +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/files/AssetsLibGDXFileSystem.java @@ -1,3 +1,23 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: LibGDX Backend. +// 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.backend.libgdx.files; import com.pixelgamelibrary.api.utils.AssetsTxt; diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxBitmapFont.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxBitmapFont.java new file mode 100644 index 0000000..2cb7ad0 --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxBitmapFont.java @@ -0,0 +1,88 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: LibGDX Backend. +// 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.backend.libgdx.graphics; + +import com.badlogic.gdx.graphics.Pixmap.Format; +import com.pixelgamelibrary.api.files.File; +import com.pixelgamelibrary.api.graphics.Color; +import com.pixelgamelibrary.api.graphics.SpriteBatch; +import com.pixelgamelibrary.api.graphics.TextureRegion; +import com.pixelgamelibrary.backend.libgdx.utils.LibGdxBackendUtils; + +/** + * + * @author robertvokac + */ +public class LibGdxBitmapFont implements com.pixelgamelibrary.api.graphics.BitmapFont { + + private com.badlogic.gdx.graphics.g2d.BitmapFont internalBitmapFont; + private boolean disposed = false; + + public LibGdxBitmapFont(boolean flip) { + this.internalBitmapFont = new com.badlogic.gdx.graphics.g2d.BitmapFont(flip); + } + + public LibGdxBitmapFont(File fontFile, TextureRegion region, boolean flip) { + throw new UnsupportedOperationException(); + + } + + public LibGdxBitmapFont(File fontFile, boolean flip) { + this.internalBitmapFont = new com.badlogic.gdx.graphics.g2d.BitmapFont(LibGdxBackendUtils.convertToLibGdxFileHandle(fontFile), flip); + } + + public LibGdxBitmapFont(File fontFile, File imageFile, boolean flip) { + this.internalBitmapFont = new com.badlogic.gdx.graphics.g2d.BitmapFont( + LibGdxBackendUtils.convertToLibGdxFileHandle(fontFile), + LibGdxBackendUtils.convertToLibGdxFileHandle(imageFile), + flip); + } + + com.badlogic.gdx.graphics.g2d.BitmapFont getInternalBitmapFont() { + return this.internalBitmapFont; + } + + @Override + public boolean isDisposed() { + return this.disposed; + } + + @Override + public void setScale(float f) { + this.internalBitmapFont.getData().setScale(f); + } + + @Override + public void setColor(Color color) { + this.internalBitmapFont.setColor(LibGdxBackendUtils.convertToLibGdxColor(color)); + } + + @Override + public void draw(SpriteBatch batch, String text, float x, float y) { + LibGdxSpriteBatch libGdxSpriteBatch = (LibGdxSpriteBatch) batch; + this.internalBitmapFont.draw(libGdxSpriteBatch.getInternalBatch(), text, x, y); + } + + @Override + public void dispose() { + this.internalBitmapFont.dispose(); + } + +} diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxBitmapFontFactory.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxBitmapFontFactory.java new file mode 100644 index 0000000..b51912e --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxBitmapFontFactory.java @@ -0,0 +1,54 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: LibGDX Backend. +// 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.backend.libgdx.graphics; + +import com.pixelgamelibrary.api.files.File; +import com.pixelgamelibrary.api.graphics.BitmapFont; +import com.pixelgamelibrary.api.graphics.BitmapFontFactory; +import com.pixelgamelibrary.api.graphics.TextureRegion; + + +/** + * + * @author robertvokac + */ +public class LibGdxBitmapFontFactory implements BitmapFontFactory{ + + @Override + public BitmapFont create(boolean flip) { + return new LibGdxBitmapFont(flip); + } + + @Override + public BitmapFont create(File fontFile, TextureRegion region, boolean flip) { + return new LibGdxBitmapFont(fontFile, region, flip); + } + + @Override + public BitmapFont create(File fontFile, boolean flip) { + return new LibGdxBitmapFont(fontFile, flip); + } + + @Override + public BitmapFont create(File fontFile, File imageFile, boolean flip) { + return new LibGdxBitmapFont(fontFile, imageFile, flip); + } + +} diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxSpriteBatch.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxSpriteBatch.java new file mode 100644 index 0000000..53bcb6c --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxSpriteBatch.java @@ -0,0 +1,76 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: LibGDX Backend. +// 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.backend.libgdx.graphics; + +/** + * + * @author robertvokac + */ +public class LibGdxSpriteBatch implements com.pixelgamelibrary.api.graphics.SpriteBatch { + + private com.badlogic.gdx.graphics.g2d.SpriteBatch internalBatch; + private boolean disposed = false; + + public LibGdxSpriteBatch() { + this(new com.badlogic.gdx.graphics.g2d.SpriteBatch()); + } + + public LibGdxSpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch libGdxG2dSpriteBatchIn) { + this.internalBatch = libGdxG2dSpriteBatchIn; + } + com.badlogic.gdx.graphics.g2d.SpriteBatch getInternalBatch() { + return this.internalBatch; + } + + @Override + public void begin() { + this.internalBatch.begin(); + } + + @Override + public void end() { + this.internalBatch.end(); + } + + @Override + public void draw(com.pixelgamelibrary.api.graphics.Texture texture, int x, int y, int width, int height) { + LibGdxTexture libGdxTexture = (LibGdxTexture) texture; + this.internalBatch.draw(libGdxTexture.getInternalTexture(), x, y, width, height); + } + + @Override + public void draw(com.pixelgamelibrary.api.graphics.Texture texture, int x, int y) { + LibGdxTexture libGdxTexture = (LibGdxTexture) texture; + this.internalBatch.draw(libGdxTexture.getInternalTexture(), x, y); + } + + + @Override + public boolean isDisposed() { + return this.disposed; + } + + @Override + public void dispose() { + this.disposed = true; + this.internalBatch.dispose(); + } + +} diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxSpriteBatchFactory.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxSpriteBatchFactory.java new file mode 100644 index 0000000..cdf318d --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxSpriteBatchFactory.java @@ -0,0 +1,36 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: LibGDX Backend. +// 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.backend.libgdx.graphics; + +import com.pixelgamelibrary.api.graphics.SpriteBatch; +import com.pixelgamelibrary.api.graphics.SpriteBatchFactory; + +/** + * + * @author robertvokac + */ +public class LibGdxSpriteBatchFactory implements SpriteBatchFactory{ + + @Override + public SpriteBatch create() { + return new LibGdxSpriteBatch(); + } + +} diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxTexture.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxTexture.java new file mode 100644 index 0000000..62ec24f --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxTexture.java @@ -0,0 +1,107 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: LibGDX Backend. +// 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.backend.libgdx.graphics; + +import com.badlogic.gdx.graphics.Pixmap.Format; +import com.pixelgamelibrary.api.files.File; +import com.pixelgamelibrary.api.graphics.ColorMode; +import com.pixelgamelibrary.api.graphics.Pixmap; +import com.pixelgamelibrary.backend.libgdx.utils.LibGdxBackendUtils; + +/** + * + * @author robertvokac + */ +public class LibGdxTexture implements com.pixelgamelibrary.api.graphics.Texture { + + private com.badlogic.gdx.graphics.Texture internalTexture; + private boolean disposed = false; + + public LibGdxTexture(com.badlogic.gdx.graphics.Texture internalTextureIn) { + this.internalTexture = internalTextureIn; + } + + public LibGdxTexture(String assetPath) { + this(new com.badlogic.gdx.graphics.Texture(assetPath)); + } + + public LibGdxTexture(File file) { + this(new com.badlogic.gdx.graphics.Texture(LibGdxBackendUtils.convertToLibGdxFileHandle(file))); + } + + public LibGdxTexture(Pixmap pixmap) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + public LibGdxTexture(int width, int height) { + this(new com.badlogic.gdx.graphics.Texture(width, height, Format.RGBA8888)); + } + + com.badlogic.gdx.graphics.Texture getInternalTexture() { + return this.internalTexture; + } + + @Override + public void dispose() { + this.disposed = true; + this.internalTexture.dispose(); + } + + @Override + public void draw(Pixmap pixmap, int x, int y) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public int getWidth() { + return this.internalTexture.getWidth(); + } + + @Override + public int getHeight() { + return this.internalTexture.getHeight(); + } + + @Override + public int getDepth() { + return this.internalTexture.getDepth(); + } + + @Override + public void makeColorTransparent(int r, int g, int b) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public void scale(double d) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public void setColorMode(ColorMode colorMode, int bitCount) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public boolean isDisposed() { + return this.disposed; + } + +} diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxTextureFactory.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxTextureFactory.java new file mode 100644 index 0000000..deaf060 --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/graphics/LibGdxTextureFactory.java @@ -0,0 +1,54 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: LibGDX Backend. +// 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.backend.libgdx.graphics; + +import com.pixelgamelibrary.api.files.File; +import com.pixelgamelibrary.api.graphics.Pixmap; +import com.pixelgamelibrary.api.graphics.Texture; +import com.pixelgamelibrary.api.graphics.TextureFactory; + +/** + * + * @author robertvokac + */ +public class LibGdxTextureFactory implements TextureFactory{ + + + @Override + public Texture create(String assetPath) { + return new LibGdxTexture(assetPath); + } + + @Override + public Texture create(File file) { + return new LibGdxTexture(file); + } + + @Override + public Texture create(Pixmap pixmap) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + + @Override + public Texture create(int width, int height) { + return new LibGdxTexture(width, height); + } + +} diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/AppLibGDXImpl.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/AppLibGDXImpl.java similarity index 86% rename from src/main/java/com/pixelgamelibrary/backend/libgdx/AppLibGDXImpl.java rename to src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/AppLibGDXImpl.java index 9c1cbcb..894c05b 100644 --- a/src/main/java/com/pixelgamelibrary/backend/libgdx/AppLibGDXImpl.java +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/AppLibGDXImpl.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.backend.libgdx; +package com.pixelgamelibrary.backend.libgdx.interfaces; import com.badlogic.gdx.Application; import static com.badlogic.gdx.Application.ApplicationType.Android; @@ -137,7 +137,31 @@ public class AppLibGDXImpl implements App { @Override public void setLogLevel(LogLevel logLevel) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + +// public static final int LOG_NONE = 0; +// public static final int LOG_DEBUG = 3; +// public static final int LOG_INFO = 2; +// public static final int LOG_ERROR = 1; + switch (logLevel) { + case NONE: + Gdx.app.setLogLevel(Gdx.app.LOG_NONE); + break; + case FATAL: + case ERROR: + Gdx.app.setLogLevel(Gdx.app.LOG_ERROR); + break; + case INFO: + case WARN: + Gdx.app.setLogLevel(Gdx.app.LOG_INFO); + break; + case DEBUG: + case TRACE: + Gdx.app.setLogLevel(Gdx.app.LOG_DEBUG); + break; + default: + throw new UnsupportedOperationException("This LogLevel is not supported: " + logLevel); + } + } @Override diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/AudioLibGDXImpl.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/AudioLibGDXImpl.java similarity index 96% rename from src/main/java/com/pixelgamelibrary/backend/libgdx/AudioLibGDXImpl.java rename to src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/AudioLibGDXImpl.java index 2ed553a..e551902 100644 --- a/src/main/java/com/pixelgamelibrary/backend/libgdx/AudioLibGDXImpl.java +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/AudioLibGDXImpl.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.backend.libgdx; +package com.pixelgamelibrary.backend.libgdx.interfaces; import com.pixelgamelibrary.api.audio.Music; import com.pixelgamelibrary.api.audio.Sound; diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/ElementLibGDXImpl.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/ElementLibGDXImpl.java similarity index 97% rename from src/main/java/com/pixelgamelibrary/backend/libgdx/ElementLibGDXImpl.java rename to src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/ElementLibGDXImpl.java index 4f7bde3..d9e28ec 100644 --- a/src/main/java/com/pixelgamelibrary/backend/libgdx/ElementLibGDXImpl.java +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/ElementLibGDXImpl.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.backend.libgdx; +package com.pixelgamelibrary.backend.libgdx.interfaces; import com.badlogic.gdx.utils.XmlReader; import com.pixelgamelibrary.api.interfaces.XmlElement; diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/FilesLibGDXImpl.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/FilesLibGDXImpl.java similarity index 98% rename from src/main/java/com/pixelgamelibrary/backend/libgdx/FilesLibGDXImpl.java rename to src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/FilesLibGDXImpl.java index 6afb772..ab0884a 100644 --- a/src/main/java/com/pixelgamelibrary/backend/libgdx/FilesLibGDXImpl.java +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/FilesLibGDXImpl.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.backend.libgdx; +package com.pixelgamelibrary.backend.libgdx.interfaces; import com.pixelgamelibrary.backend.libgdx.files.FileSystemFactory; import com.pixelgamelibrary.api.interfaces.Files; diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/GraphicsLibGDXImpl.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/GraphicsLibGDXImpl.java similarity index 87% rename from src/main/java/com/pixelgamelibrary/backend/libgdx/GraphicsLibGDXImpl.java rename to src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/GraphicsLibGDXImpl.java index 46c1d0c..b499404 100644 --- a/src/main/java/com/pixelgamelibrary/backend/libgdx/GraphicsLibGDXImpl.java +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/GraphicsLibGDXImpl.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.backend.libgdx; +package com.pixelgamelibrary.backend.libgdx.interfaces; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Graphics; @@ -28,7 +28,10 @@ import com.pixelgamelibrary.api.graphics.Monitor; import com.pixelgamelibrary.api.graphics.Pixmap; import com.pixelgamelibrary.api.graphics.SpriteBatchFactory; import com.pixelgamelibrary.api.graphics.TextureFactory; +import com.pixelgamelibrary.backend.libgdx.graphics.LibGdxBitmapFontFactory; import com.pixelgamelibrary.backend.libgdx.graphics.LibGdxMonitor; +import com.pixelgamelibrary.backend.libgdx.graphics.LibGdxSpriteBatchFactory; +import com.pixelgamelibrary.backend.libgdx.graphics.LibGdxTextureFactory; import java.util.ArrayList; import java.util.List; @@ -98,17 +101,17 @@ public class GraphicsLibGDXImpl implements com.pixelgamelibrary.api.interfaces.G @Override public TextureFactory getTextureFactory() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + return new LibGdxTextureFactory(); } @Override public SpriteBatchFactory newSpriteBatchFactory() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + return new LibGdxSpriteBatchFactory(); } @Override public BitmapFontFactory newBitmapFontFactory() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + return new LibGdxBitmapFontFactory(); } } diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/InputLibGDXImpl.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/InputLibGDXImpl.java similarity index 99% rename from src/main/java/com/pixelgamelibrary/backend/libgdx/InputLibGDXImpl.java rename to src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/InputLibGDXImpl.java index e288446..7a7af3e 100644 --- a/src/main/java/com/pixelgamelibrary/backend/libgdx/InputLibGDXImpl.java +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/InputLibGDXImpl.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.backend.libgdx; +package com.pixelgamelibrary.backend.libgdx.interfaces; import com.pixelgamelibrary.api.input.DeviceOrientation; import com.pixelgamelibrary.api.input.InputProcessor; diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/InternalLibGDXImpl.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/InternalLibGDXImpl.java similarity index 95% rename from src/main/java/com/pixelgamelibrary/backend/libgdx/InternalLibGDXImpl.java rename to src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/InternalLibGDXImpl.java index a63551b..ccc0ec9 100644 --- a/src/main/java/com/pixelgamelibrary/backend/libgdx/InternalLibGDXImpl.java +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/InternalLibGDXImpl.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.backend.libgdx; +package com.pixelgamelibrary.backend.libgdx.interfaces; import com.pixelgamelibrary.api.interfaces.Internal; diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/NetLibGDXImpl.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/NetLibGDXImpl.java similarity index 98% rename from src/main/java/com/pixelgamelibrary/backend/libgdx/NetLibGDXImpl.java rename to src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/NetLibGDXImpl.java index 4552196..1fd5e96 100644 --- a/src/main/java/com/pixelgamelibrary/backend/libgdx/NetLibGDXImpl.java +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/NetLibGDXImpl.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.backend.libgdx; +package com.pixelgamelibrary.backend.libgdx.interfaces; import com.pixelgamelibrary.api.interfaces.Net; import com.pixelgamelibrary.api.net.http.HttpRequest; diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/PixelBackendLibGDX.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/PixelBackendLibGDX.java similarity index 98% rename from src/main/java/com/pixelgamelibrary/backend/libgdx/PixelBackendLibGDX.java rename to src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/PixelBackendLibGDX.java index 56b5191..cb04a2d 100644 --- a/src/main/java/com/pixelgamelibrary/backend/libgdx/PixelBackendLibGDX.java +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/PixelBackendLibGDX.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.backend.libgdx; +package com.pixelgamelibrary.backend.libgdx.interfaces; import com.pixelgamelibrary.api.interfaces.PixelBackend; import com.pixelgamelibrary.api.interfaces.Files; diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/UtilsLibGDXImpl.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/UtilsLibGDXImpl.java similarity index 98% rename from src/main/java/com/pixelgamelibrary/backend/libgdx/UtilsLibGDXImpl.java rename to src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/UtilsLibGDXImpl.java index d11f1e4..47a1c09 100644 --- a/src/main/java/com/pixelgamelibrary/backend/libgdx/UtilsLibGDXImpl.java +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/interfaces/UtilsLibGDXImpl.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.backend.libgdx; +package com.pixelgamelibrary.backend.libgdx.interfaces; import com.badlogic.gdx.utils.Base64Coder; import com.badlogic.gdx.utils.XmlReader; diff --git a/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/LibGdxBackendUtils.java b/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/LibGdxBackendUtils.java new file mode 100644 index 0000000..3f51923 --- /dev/null +++ b/src/main/java/com/pixelgamelibrary/backend/libgdx/utils/LibGdxBackendUtils.java @@ -0,0 +1,70 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// Pixel: LibGDX Backend. +// 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.backend.libgdx.utils; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.files.FileHandle; +import com.pixelgamelibrary.api.Pixel; +import com.pixelgamelibrary.api.files.File; +import com.pixelgamelibrary.api.files.FileException; +import com.pixelgamelibrary.api.files.FileSystemType; + +/** + * + * @author robertvokac + */ +public class LibGdxBackendUtils { + + private LibGdxBackendUtils() { + //Not meant to be instantiated. + } + + public static FileHandle convertToLibGdxFileHandle(File file) { + boolean android = Pixel.app().getPlatform().isAndroid(); + boolean web = Pixel.app().getPlatform().isWeb(); + + FileSystemType fileSystemType = file.getFileSystem().getFileSystemType(); + switch (fileSystemType) { + case ASSETS: + return android || web ? Gdx.files.internal(file.path()) : Gdx.files.classpath(file.path().startsWith("/") ? file.path().substring(1) : file.path()); + case LOCAL: + return Gdx.files.local(file.path()); + case EXTERNAL: + return Gdx.files.external(file.path()); + case RELATIVE: + return Gdx.files.local(file.path()); + case ABSOLUTE: + return Gdx.files.absolute(file.path()); + case TMP: + throw new FileException("Unsupported FileSystemType: " + fileSystemType); + case UNDEFINED: + throw new FileException("Unsupported FileSystemType: " + fileSystemType); + default: + throw new FileException("Unsupported FileSystemType: " + fileSystemType); + } + + } + public static com.badlogic.gdx.graphics.Color convertToLibGdxColor(com.pixelgamelibrary.api.graphics.Color color) { + return new com.badlogic.gdx.graphics.Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); + } + public static com.pixelgamelibrary.api.graphics.Color convertToPixelColor(com.badlogic.gdx.graphics.Color color) { + return new com.pixelgamelibrary.api.graphics.Color(color.r, color.g, color.b, color.a); + } +}