Bug 18: Refactor and separate Pixel Api and LibGDX and Open Eggbert Core

This commit is contained in:
Robert Vokac 2024-09-20 17:44:15 +02:00
parent 9c0dd4cff9
commit 0b885bc84a
No known key found for this signature in database
GPG Key ID: C459E1E4B4A986BB
13 changed files with 104 additions and 40 deletions

BIN
assets/BASIC/BASIC.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

View File

@ -21,7 +21,7 @@ package com.openeggbert.core.configuration;
import com.pixelgamelibrary.api.Pixel;
import com.openeggbert.core.main.OpenEggbertException;
import com.pixelgamelibrary.api.DisplayMode;
import com.pixelgamelibrary.api.ViewMode;
/**
*
@ -34,19 +34,21 @@ public enum OpenEggbertDisplayMode {
if (configDef == null) {
return OpenEggbertDisplayMode.WINDOW;
}
return setDisplayMode(fromConfigDef(configDef));
final OpenEggbertDisplayMode fromConfigDef = fromConfigDef(configDef);
setDisplayMode(fromConfigDef);
return fromConfigDef;
}
public static OpenEggbertDisplayMode fromConfigDef(ConfigDef configDef) {
return configDef.isFullscreen() ? FULLSCREEN : WINDOW;
}
public static OpenEggbertDisplayMode setDisplayModeToFullscreen() {
return setDisplayMode(FULLSCREEN);
public static void setDisplayModeToFullscreen() {
setDisplayMode(FULLSCREEN);
}
public static OpenEggbertDisplayMode setDisplayModeToWindow() {
return setDisplayMode(WINDOW);
public static void setDisplayModeToWindow() {
setDisplayMode(WINDOW);
}
public static OpenEggbertDisplayMode find(boolean fullscreen, boolean window) {
@ -63,10 +65,8 @@ public enum OpenEggbertDisplayMode {
}
}
public static OpenEggbertDisplayMode setDisplayMode(OpenEggbertDisplayMode displayMode) {
DisplayMode result = Pixel.graphics().setDisplayMode(displayMode == FULLSCREEN, displayMode == WINDOW);
return result == null ? null : OpenEggbertDisplayMode.valueOf(result.name());
public static void setDisplayMode(OpenEggbertDisplayMode displayMode) {
Pixel.graphics().getMonitor().setViewMode(displayMode == FULLSCREEN ? ViewMode.FULLSCREEN : ViewMode.WINDOW);
}
public OpenEggbertDisplayMode flip() {

View File

@ -27,7 +27,7 @@ import lombok.Getter;
*
* @author robertvokac
*/
public enum ScreenResolution implements IsThisFeatureEnabledForStrictMode {
public enum VirtualScreenResolution implements IsThisFeatureEnabledForStrictMode {
VGA(640,480,true),
QUAD_VGA(1280, 960, false),
CURRENT(0, 0, false);
@ -37,7 +37,7 @@ public enum ScreenResolution implements IsThisFeatureEnabledForStrictMode {
private int width;
@Getter
private int height;
ScreenResolution(int width, int height, boolean enabledInCaseOfStrictMode) {
VirtualScreenResolution(int width, int height, boolean enabledInCaseOfStrictMode) {
this.width = width;
this.height = height;
this.enabledInCaseOfStrictMode = enabledInCaseOfStrictMode;

View File

@ -136,6 +136,9 @@ public class OpenEggbertGame extends GameAdapter {
public void loadImageTexture(com.badlogic.gdx.files.FileHandle fileHandle) {
Texture texture = new Texture(fileHandle);
if(!fileHandle.exists()) {
throw new OpenEggbertException("File does not exist: " + fileHandle.path());
}
imageTextures.put(OpenEggbertUtils.getFileNameWithoutExtension(fileHandle.name().toUpperCase()), texture);
}

View File

@ -0,0 +1,34 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Open Eggbert: Free recreation of the computer game Speedy Eggbert.
// 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
// <https://www.gnu.org/licenses/> or write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
package com.openeggbert.core.screen;
import com.openeggbert.core.main.OpenEggbertGame;
/**
*
* @author robertvokac
*/
public abstract class AbstractBasicScreen extends OpenEggbertScreen {
public AbstractBasicScreen(OpenEggbertGame openEggbertGame) {
super(openEggbertGame);
}
}

View File

@ -38,6 +38,7 @@ public class DemoScreen extends OpenEggbertScreen {
}
@Override
protected final Optional<ScreenType> getScreenType() {
return Optional.of(ScreenType.DEMO);
}

View File

@ -27,7 +27,6 @@ import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.utils.ScreenUtils;
import com.openeggbert.core.gamespace.GameSpace;
import com.openeggbert.core.main.OpenEggbertGame;
import com.openeggbert.core.mod.Mod;
@ -35,6 +34,7 @@ import com.openeggbert.core.mod.ModType;
import com.pixelgamelibrary.api.Pixel;
import com.pixelgamelibrary.api.storage.Storage;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
@ -44,7 +44,7 @@ import lombok.ToString;
*
* @author robertvokac
*/
public class GameSpaceListScreen extends OpenEggbertScreen {
public class GameSpaceListScreen extends AbstractBasicScreen {
private int pageNumber = 1;
private final int pageSize = 5;
@ -65,7 +65,6 @@ public class GameSpaceListScreen extends OpenEggbertScreen {
public GameSpaceListScreen(OpenEggbertGame openEggbertGame) {
super(openEggbertGame);
this.fullEmbeddedMods = openEggbertGame.getEmbeddedMods().stream().filter(m -> m.getModType() == ModType.FULL).collect(Collectors.toList());
if (Gdx.app.getType() == Application.ApplicationType.Android) {
game.setHeightInPixels(Gdx.app.getGraphics().getHeight());
@ -79,16 +78,18 @@ public class GameSpaceListScreen extends OpenEggbertScreen {
storage.createDirectory("gameSpaces");
System.out.println(storage.debug());
//storage.file("modes").child("text.txt").writeString("textabc");
storage.flush();
}
@Override
protected final Optional<ScreenType> getScreenType() {
return Optional.of(ScreenType.GAME_SPACE_LIST);
}
@Override
public void show() {
System.out.println("Calling : GameSpaceListScreen : show");
try{
throw new RuntimeException();
} catch (Exception e) {e.printStackTrace();}
System.out.println("Calling : GameSpaceListScreen : show");
Gdx.input.setInputProcessor(new InputAdapter() {
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
@ -141,14 +142,14 @@ throw new RuntimeException();
System.out.println(buttons[i].toString());
}
y = Gdx.graphics.getHeight() - y;
for (int i = 0; i < 5; i++) {
if (buttons[i] == null) {
break;
}
if (x > buttons[i].x && x < (buttons[i].x + buttons[i].width)
&& y > buttons[i].y && y < (buttons[i].y + buttons[i].height)) {
activateButton(i);
}
@ -196,10 +197,11 @@ throw new RuntimeException();
activateButton(0);
}
ScreenUtils.clear(1f, 1f, 0.6f, 0.5f);
//ScreenUtils.clear(1f, 1f, 0.6f, 0.5f);
int buttonHeight = (int) (game.getHeightInPixels() * 0.1f);
batch.begin();
drawBackgroundIfAvailable();
BitmapFont font;
font = game.getFont();

View File

@ -132,10 +132,9 @@ public class InitScreen extends OpenEggbertScreen {
if (game.getConfigDef() != null && Gdx.app.getType() == Application.ApplicationType.Desktop && !game.getConfigDef().isStrictCompatibility() && keyCode == Input.Keys.F) {
OpenEggbertDisplayMode currentDisplayMode = game.getOpenEggbertDisplayMode();
OpenEggbertDisplayMode newDisplayMode = currentDisplayMode.flip();
boolean success = OpenEggbertDisplayMode.setDisplayMode(newDisplayMode) != null;
if (success) {
game.setOpenEggbertDisplayMode(newDisplayMode);
}
OpenEggbertDisplayMode.setDisplayMode(newDisplayMode);
game.setOpenEggbertDisplayMode(newDisplayMode);
}
return true;

View File

@ -71,6 +71,21 @@ public abstract class OpenEggbertScreen extends ScreenAdapter {
String fileName = getBackgroundFileName();
if(getScreenType().isPresent() && getScreenType().get().isBasic()) {
if (!game.existsImageTexture("BASIC")) {
FileHandle fileHandle;
if (Gdx.app.getType() == Application.ApplicationType.Android || Gdx.app.getType() == Application.ApplicationType.WebGL) {
Gdx.app.log("screen","loading from internal");
fileHandle = Gdx.files.internal("BASIC/BASIC.PNG");
} else {
Gdx.app.log("screen","loading from classpath");
fileHandle = Gdx.files.classpath("BASIC/BASIC.PNG");
}
game.loadImageTexture(fileHandle);
}
return;
}
List<String> possibleFileNames = OpenEggbertUtils.createPossibleFileNames(GameFileType.IMAGE8, fileName);
for(String possibleFileName: possibleFileNames) {
if (!game.existsImageTexture(possibleFileName)) {
@ -111,6 +126,10 @@ public abstract class OpenEggbertScreen extends ScreenAdapter {
}
protected void drawBackgroundIfAvailable() {
if(getScreenType().isPresent() && getScreenType().get().isBasic()) {
batch.draw(game.getImageTexture("BASIC").get(), 0, 0, 640,480);
return;
}
if (getBackgroundTexture().isPresent()) {
batch.draw(getBackgroundTexture().get(), 0, 0);
}

View File

@ -29,16 +29,19 @@ import lombok.Getter;
*/
public enum ScreenType {
MAIN,
GAME_SPACE_LIST,
GAME_SPACE_CREATE,
GAME_SPACE_READ,
GAME_SPACE_UPDATE,
GAME_SPACE_DELETE,
GAME_SPACE_LIST("BASIC"),
GAME_SPACE_CREATE("BASIC"),
GAME_SPACE_RENAME("BASIC"),
GAME_SPACE_DELETE("BASIC"),
GAME_SPACE_RESET("BASIC"),
GAME_SPACE_EDIT("BASIC"),
GAME_SPACE_CONFIGURE("BASIC"),
GAME_SPACE_CONFIGURE_ENTRY("BASIC"),
GAME_SPACE_SELECT_MODE("BASIC"),
//
MOD_LIST,
MOD_CREATE,
MOD_READ,
MOD_UPDATE,
MOD_DELETE,
MOD_VIEW,
//
INIT("INIT"),
GAMER("GAMER"),
MAIN_HUB(""),
@ -58,5 +61,8 @@ public enum ScreenType {
ScreenType(String fileName) {
this.fileNameWithoutExtension = fileName;
}
public boolean isBasic() {
return name().startsWith("GAME_SPACE") || name().startsWith("MOD");
}
}

View File

@ -3,7 +3,7 @@ package com.openeggbert.gwt;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.backends.gwt.GwtApplication;
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
import com.openeggbert.core.configuration.ScreenResolution;
import com.openeggbert.core.configuration.VirtualScreenResolution;
import com.openeggbert.core.main.OpenEggbertApplication;
import com.pixelgamelibrary.api.Pixel;
import com.pixelgamelibrary.backend.libgdx.PixelBackendLibGDX;
@ -21,7 +21,7 @@ public class GwtLauncher extends GwtApplication {
// If you want a fixed size application, comment out the above resizable section,
// and uncomment below:
return new GwtApplicationConfiguration(ScreenResolution.VGA.getWidth(), ScreenResolution.VGA.getHeight());
return new GwtApplicationConfiguration(VirtualScreenResolution.VGA.getWidth(), VirtualScreenResolution.VGA.getHeight());
}
@Override

View File

@ -22,7 +22,7 @@ package com.openeggbert.lwjgl3;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.openeggbert.core.configuration.ScreenResolution;
import com.openeggbert.core.configuration.VirtualScreenResolution;
import com.openeggbert.core.main.OpenEggbertApplication;
import com.openeggbert.core.gamespace.GameSpace;
import com.pixelgamelibrary.api.Pixel;
@ -64,7 +64,7 @@ public class Lwjgl3Launcher {
//// If you remove the above line and set Vsync to false, you can get unlimited FPS, which can be
//// useful for testing performance, but can also be very stressful to some hardware.
//// You may also need to configure GPU drivers to fully disable Vsync; this can cause screen tearing.
configuration.setWindowedMode(ScreenResolution.VGA.getWidth(), ScreenResolution.VGA.getHeight());
configuration.setWindowedMode(VirtualScreenResolution.VGA.getWidth(), VirtualScreenResolution.VGA.getHeight());
configuration.setWindowIcon("libgdx128.png", "libgdx64.png", "libgdx32.png", "libgdx16.png");
return configuration;
}