From d224787c99d7e6adb90ea021abf8393d5b637aa4 Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Sun, 4 Aug 2024 19:57:54 +0200 Subject: [PATCH] Many changes --- android/proguard-rules.pro | 3 + .../openeggbert/android/AndroidLauncher.java | 4 +- assets/open-eggbert-legacy-assets | 1 - .../com/openeggbert/OpenEggbertMainClass.java | 96 --------- .../compatibility/ResolutionMode.java | 2 +- .../entity/common/OpenEggbertScreenType.java | 38 ++++ .../OpenEggbertGame.gwt.xml} | 0 .../com/openeggbert/main/OpenEggbertGame.java | 159 +++++++++++++++ .../main/java/com/openeggbert/mods/Mod.java | 85 ++++++++ .../openeggbert/mods/ModIdentification.java | 50 +++++ .../ModPackaging.java} | 8 +- .../java/com/openeggbert/mods/ModType.java | 29 +++ .../main/java/com/openeggbert/mods/Store.java | 40 ++++ .../screens/AbstractOpenEggbertScreen.java | 80 ++++++++ .../screens/GameSpaceListScreen.java | 188 ++++++++++++++++++ .../com/openeggbert/screens/InitScreen.java | 73 +++++++ .../com/openeggbert/screens/TestScreen.java | 90 +++++++++ .../com/openeggbert/GdxDefinition.gwt.xml | 2 +- .../java/com/openeggbert/gwt/GwtLauncher.java | 4 +- .../com/openeggbert/lwjgl3/DesktopUtils.java | 5 + .../openeggbert/lwjgl3/Lwjgl3Launcher.java | 10 +- 21 files changed, 855 insertions(+), 112 deletions(-) delete mode 160000 assets/open-eggbert-legacy-assets delete mode 100644 core/src/main/java/com/openeggbert/OpenEggbertMainClass.java create mode 100644 core/src/main/java/com/openeggbert/entity/common/OpenEggbertScreenType.java rename core/src/main/java/com/openeggbert/{OpenEggbertMainClass.gwt.xml => main/OpenEggbertGame.gwt.xml} (100%) create mode 100644 core/src/main/java/com/openeggbert/main/OpenEggbertGame.java create mode 100644 core/src/main/java/com/openeggbert/mods/Mod.java create mode 100644 core/src/main/java/com/openeggbert/mods/ModIdentification.java rename core/src/main/java/com/openeggbert/{entity/common/OpenEggbertScreen.java => mods/ModPackaging.java} (92%) create mode 100644 core/src/main/java/com/openeggbert/mods/ModType.java create mode 100644 core/src/main/java/com/openeggbert/mods/Store.java create mode 100644 core/src/main/java/com/openeggbert/screens/AbstractOpenEggbertScreen.java create mode 100644 core/src/main/java/com/openeggbert/screens/GameSpaceListScreen.java create mode 100644 core/src/main/java/com/openeggbert/screens/InitScreen.java create mode 100644 core/src/main/java/com/openeggbert/screens/TestScreen.java diff --git a/android/proguard-rules.pro b/android/proguard-rules.pro index 35b7942..66d3723 100644 --- a/android/proguard-rules.pro +++ b/android/proguard-rules.pro @@ -49,3 +49,6 @@ # These two lines are used with mapping files; see https://developer.android.com/build/shrink-code#retracing -keepattributes LineNumberTable,SourceFile -renamesourcefileattribute SourceFile + +#Lombok +-dontwarn lombok.Generated diff --git a/android/src/main/java/com/openeggbert/android/AndroidLauncher.java b/android/src/main/java/com/openeggbert/android/AndroidLauncher.java index a69eaa4..edf4509 100644 --- a/android/src/main/java/com/openeggbert/android/AndroidLauncher.java +++ b/android/src/main/java/com/openeggbert/android/AndroidLauncher.java @@ -4,7 +4,7 @@ import android.os.Bundle; import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; -import com.openeggbert.OpenEggbertMainClass; +import com.openeggbert.main.OpenEggbertGame; /** Launches the Android application. */ public class AndroidLauncher extends AndroidApplication { @@ -13,6 +13,6 @@ public class AndroidLauncher extends AndroidApplication { super.onCreate(savedInstanceState); AndroidApplicationConfiguration configuration = new AndroidApplicationConfiguration(); configuration.useImmersiveMode = true; // Recommended, but not required. - initialize(new OpenEggbertMainClass(), configuration); + initialize(new OpenEggbertGame(), configuration); } } \ No newline at end of file diff --git a/assets/open-eggbert-legacy-assets b/assets/open-eggbert-legacy-assets deleted file mode 160000 index 1263d70..0000000 --- a/assets/open-eggbert-legacy-assets +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1263d7036ff848afd546b644c91dd80ca9f94b59 diff --git a/core/src/main/java/com/openeggbert/OpenEggbertMainClass.java b/core/src/main/java/com/openeggbert/OpenEggbertMainClass.java deleted file mode 100644 index 17ed6fd..0000000 --- a/core/src/main/java/com/openeggbert/OpenEggbertMainClass.java +++ /dev/null @@ -1,96 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////////////////// -// 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 -// or write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -/////////////////////////////////////////////////////////////////////////////////////////////// -package com.openeggbert; - -import com.badlogic.gdx.Application; -import com.badlogic.gdx.ApplicationAdapter; -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.GL20; -import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.BitmapFont; -import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.utils.ScreenUtils; -import com.openeggbert.entity.common.GameSpace; -import java.util.function.Function; - -/** - * {@link com.badlogic.gdx.ApplicationListener} implementation shared by all - * platforms. - */ -public class OpenEggbertMainClass extends ApplicationAdapter { - - private SpriteBatch batch; - private Texture image; - private GameSpace gameSpace = null; - private String currentDirectory; - - public OpenEggbertMainClass() { - - } - - public OpenEggbertMainClass(GameSpace gameSpace, String currentDirectory) { - this.gameSpace = gameSpace; - this.currentDirectory = currentDirectory; - } - - public OpenEggbertMainClass(String currentDirectory) { - this.gameSpace = null; - this.currentDirectory = currentDirectory; - } - - @Override - public void create() { - batch = new SpriteBatch(); - image = new Texture("libgdx.png"); - } - - @Override - public void render() { - ScreenUtils.clear(0.15f, 0.15f, 0.2f, 1f); - batch.begin(); - Function removeCurrentDir = i -> i == null ? null : i.replace(currentDirectory + "/", ""); - if (Gdx.app.getType() == Application.ApplicationType.Desktop && gameSpace != null) { - BitmapFont font; - font = new BitmapFont(); - int x = 140; - font.draw(batch, "getFeatureLevel=" + gameSpace.getFeatureLevel(), 40, x);x+=25; - font.draw(batch, "getDataDirectory=" + removeCurrentDir.apply(gameSpace.getDataDirectory()), 40, x);x+=25; - font.draw(batch, "getImage08Directory=" + removeCurrentDir.apply(gameSpace.getImage08Directory()), 40, x);x+=25; - font.draw(batch, "getImage16Directory=" + removeCurrentDir.apply(gameSpace.getImage16Directory()), 40, x);x+=25; - font.draw(batch, "getImage24Directory=" + removeCurrentDir.apply(gameSpace.getImage24Directory()), 40, x);x+=25; - font.draw(batch, "getImage24x2Directory=" + removeCurrentDir.apply(gameSpace.getImage24x2Directory()), 40, x);x+=25; - font.draw(batch, "getSoundDirectory=" + removeCurrentDir.apply(gameSpace.getSoundDirectory()), 40, x);x+=25; - } - - if (currentDirectory != null) { - BitmapFont font; - font = new BitmapFont(); - font.draw(batch, currentDirectory, 40, 340); - } - //batch.draw(image, 140, 210); - batch.end(); - } - - @Override - public void dispose() { - batch.dispose(); - image.dispose(); - } -} diff --git a/core/src/main/java/com/openeggbert/compatibility/ResolutionMode.java b/core/src/main/java/com/openeggbert/compatibility/ResolutionMode.java index 55e540f..36a67fe 100644 --- a/core/src/main/java/com/openeggbert/compatibility/ResolutionMode.java +++ b/core/src/main/java/com/openeggbert/compatibility/ResolutionMode.java @@ -29,5 +29,5 @@ public enum ResolutionMode { RESOLUTION_640_480, RESOLUTION_1280_960, RESOLUTION_SCALED, - RESOLUTION_KEEP; + RESOLUTION_CURRENT; } diff --git a/core/src/main/java/com/openeggbert/entity/common/OpenEggbertScreenType.java b/core/src/main/java/com/openeggbert/entity/common/OpenEggbertScreenType.java new file mode 100644 index 0000000..ba33e8f --- /dev/null +++ b/core/src/main/java/com/openeggbert/entity/common/OpenEggbertScreenType.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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 +// or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// + + +package com.openeggbert.entity.common; + +import lombok.Getter; + +/** + * + * @author robertvokac + */ +public enum OpenEggbertScreenType { + INIT("INIT.BLP"); + @Getter + private String fileName; + OpenEggbertScreenType(String fileName) { + this.fileName = fileName; + } + +} diff --git a/core/src/main/java/com/openeggbert/OpenEggbertMainClass.gwt.xml b/core/src/main/java/com/openeggbert/main/OpenEggbertGame.gwt.xml similarity index 100% rename from core/src/main/java/com/openeggbert/OpenEggbertMainClass.gwt.xml rename to core/src/main/java/com/openeggbert/main/OpenEggbertGame.gwt.xml diff --git a/core/src/main/java/com/openeggbert/main/OpenEggbertGame.java b/core/src/main/java/com/openeggbert/main/OpenEggbertGame.java new file mode 100644 index 0000000..59dfabb --- /dev/null +++ b/core/src/main/java/com/openeggbert/main/OpenEggbertGame.java @@ -0,0 +1,159 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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 +// or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.openeggbert.main; + +import com.badlogic.gdx.Game; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.utils.ObjectMap; +import com.openeggbert.entity.common.GameSpace; +import com.openeggbert.mods.Mod; +import com.openeggbert.screens.GameSpaceListScreen; +import com.openeggbert.screens.InitScreen; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import lombok.Data; + +/** + * {@link com.badlogic.gdx.ApplicationListener} implementation shared by all + * platforms. + */ +@Data +public class OpenEggbertGame extends Game { + + private Texture image; + private GameSpace gameSpace = null; + private String currentDirectory; + + private SpriteBatch batch; + private ShapeRenderer shapeRenderer; + private BitmapFont font; + private ObjectMap imageTextures = new ObjectMap<>(); + private List embeddedMods = new ArrayList<>(); + private int heightInPixels = 480; + private int widthInPixels = 640; + + public OpenEggbertGame() { + this(null, null); + } + + public OpenEggbertGame(String currentDirectory) { + this(null, currentDirectory); + } + + public OpenEggbertGame(GameSpace gameSpace, String currentDirectory) { + this.gameSpace = gameSpace; + this.currentDirectory = currentDirectory; + + } + + @Override + public void create() { + System.out.println("Searching mods"); + + FileHandle embeddedModsDirectory = Gdx.files.internal("embedded_mods"); + System.out.println("embeddedModsDirectory.list().length=" + embeddedModsDirectory.list().length); + for (FileHandle embeddedModGroup : embeddedModsDirectory.list()) { + if (!embeddedModGroup.isDirectory()) { + System.out.println("embedded_mods directory is missing"); + continue; + } + System.out.println("Found group " + embeddedModGroup.name()); + for (FileHandle embeddedMod : embeddedModGroup.list()) { + System.out.println("Found mod " + embeddedMod.name()); + + FileHandle modXml = null; + for(FileHandle file: embeddedMod.list()) { + if(file.name().equals("mod.xml")) { + modXml = file; + } + } + + if (modXml == null) { + continue; + } + System.out.println("Found mod: " + embeddedMod.name()); + Mod mod = new Mod(modXml.readString()); + embeddedMods.add(mod); + System.out.println("embeddedMods.size(): " + embeddedMods.size()); + for (int i = 0; i < 42; i++) { + embeddedMods.add(mod);//for testing purposes + } + } + + } + //// + batch = new SpriteBatch(); + image = new Texture("libgdx.png"); + shapeRenderer = new ShapeRenderer(); + font = new BitmapFont(); + setScreen(gameSpace == null ? new GameSpaceListScreen(this) : new InitScreen(this)); + } + + @Override + public void dispose() { + batch.dispose(); + image.dispose(); + + shapeRenderer.dispose(); + font.dispose(); + for (String key : imageTextures.keys()) { + imageTextures.get(key).dispose(); + } + } + + public void loadImageTexture(FileHandle fileHandle) { + Texture texture = new Texture(fileHandle); + imageTextures.put(fileHandle.name().toUpperCase(), texture); + } + + public boolean existsImageTexture(String key) { + return imageTextures.containsKey(key); + } + + public void disposeImageTexture(String key) { + if (imageTextures.containsKey(key)) { + imageTextures.get(key).dispose(); + imageTextures.remove(key); + } + } + + public void disposeImageTextures() { + for (String key : imageTextures.keys()) { + imageTextures.get(key).dispose(); + imageTextures.remove(key); + } + } + + public Optional getImageTexture(String key) { + if (imageTextures.containsKey(key)) { + return Optional.of(imageTextures.get(key)); + } else { + return Optional.empty(); + } + } + +} diff --git a/core/src/main/java/com/openeggbert/mods/Mod.java b/core/src/main/java/com/openeggbert/mods/Mod.java new file mode 100644 index 0000000..7fc6aaf --- /dev/null +++ b/core/src/main/java/com/openeggbert/mods/Mod.java @@ -0,0 +1,85 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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 +// or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.openeggbert.mods; + +import com.badlogic.gdx.utils.XmlReader; +import com.badlogic.gdx.utils.XmlReader.Element; +import com.openeggbert.compatibility.FeatureLevel; +import java.util.ArrayList; +import java.util.List; +import lombok.Data; + +/** + * + * @author robertvokac + */ +@Data +public class Mod { + + public Mod(String xml) { + Element root = new XmlReader().parse(xml); + Element parentElement = root.getChildByName("parent"); + if (parentElement != null) { + parent = new ModIdentification(parentElement); + } + identification = new ModIdentification( + root.get("groupId"), + root.get("modId"), + root.get("version")); + modPackaging = ModPackaging.valueOf(root.get("packaging")); + modType = ModType.valueOf(root.get("type")); + featureLevel = FeatureLevel.valueOf(root.get("featureLevel")); + name = root.get("name"); + description = root.get("description"); + Element imports = root.getChildByName("imports"); + if (imports != null) { + for (int i = 0; i < imports.getChildCount(); i++) { + Element import_ = imports.getChild(i); + importedMods.add(new ModIdentification(import_)); + } + } + Element files_ = root.getChildByName("files"); + if (files_ != null) { + for (int i = 0; i < files_.getChildCount(); i++) { + Element file = files_.getChild(i); + files.add(file.getText()); + } + } + + Element stores_ = root.getChildByName("stores"); + if (stores_ != null) { + for (int i = 0; i < stores_.getChildCount(); i++) { + Element store = stores_.getChild(i); + stores.add(new Store(store)); + } + } + + } + private ModIdentification parent; + private ModIdentification identification; + private ModPackaging modPackaging; + private ModType modType; + private FeatureLevel featureLevel; + private String name; + private String description; + private List importedMods = new ArrayList<>(); + private List files = new ArrayList<>(); + private List stores = new ArrayList<>(); +} diff --git a/core/src/main/java/com/openeggbert/mods/ModIdentification.java b/core/src/main/java/com/openeggbert/mods/ModIdentification.java new file mode 100644 index 0000000..7cb78df --- /dev/null +++ b/core/src/main/java/com/openeggbert/mods/ModIdentification.java @@ -0,0 +1,50 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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 +// or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.openeggbert.mods; + +import com.badlogic.gdx.utils.XmlReader.Element; +import lombok.AllArgsConstructor; +import lombok.Data; + +/** + * + * @author robertvokac + */ +@Data +@AllArgsConstructor +public class ModIdentification { + + private final String groupId; + private final String modId; + private final String version; + + public ModIdentification(Element element) { + groupId = element.get("groupId"); + modId = element.get("modId"); + version = element.get("version"); + } + + public String asString() { + + return groupId + DOT + modId + DOT + version; + } + private static final String DOT = "."; + +} diff --git a/core/src/main/java/com/openeggbert/entity/common/OpenEggbertScreen.java b/core/src/main/java/com/openeggbert/mods/ModPackaging.java similarity index 92% rename from core/src/main/java/com/openeggbert/entity/common/OpenEggbertScreen.java rename to core/src/main/java/com/openeggbert/mods/ModPackaging.java index 5fd2a95..a61b749 100644 --- a/core/src/main/java/com/openeggbert/entity/common/OpenEggbertScreen.java +++ b/core/src/main/java/com/openeggbert/mods/ModPackaging.java @@ -18,14 +18,12 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. /////////////////////////////////////////////////////////////////////////////////////////////// - -package com.openeggbert.entity.common; +package com.openeggbert.mods; /** * * @author robertvokac */ -public enum OpenEggbertScreen { - MAIN - +public enum ModPackaging { + EGM, XML; } diff --git a/core/src/main/java/com/openeggbert/mods/ModType.java b/core/src/main/java/com/openeggbert/mods/ModType.java new file mode 100644 index 0000000..503440c --- /dev/null +++ b/core/src/main/java/com/openeggbert/mods/ModType.java @@ -0,0 +1,29 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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 +// or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// + +package com.openeggbert.mods; + +/** + * + * @author robertvokac + */ +public enum ModType { + FULL, LEVEL, SOUND, MUSIC, IMAGE08, IMAGE16, IMAGE24,IMAGE24X2, PARTIAL; +} diff --git a/core/src/main/java/com/openeggbert/mods/Store.java b/core/src/main/java/com/openeggbert/mods/Store.java new file mode 100644 index 0000000..ca3a3de --- /dev/null +++ b/core/src/main/java/com/openeggbert/mods/Store.java @@ -0,0 +1,40 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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 +// or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.openeggbert.mods; + +import com.badlogic.gdx.utils.XmlReader; + +/** + * + * @author robertvokac + */ +public class Store { + + String id; + String name; + String url; + + Store(XmlReader.Element store) { + id = store.get("id"); + name = store.get("name"); + url = store.get("url"); + } + +} diff --git a/core/src/main/java/com/openeggbert/screens/AbstractOpenEggbertScreen.java b/core/src/main/java/com/openeggbert/screens/AbstractOpenEggbertScreen.java new file mode 100644 index 0000000..b2fcb75 --- /dev/null +++ b/core/src/main/java/com/openeggbert/screens/AbstractOpenEggbertScreen.java @@ -0,0 +1,80 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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 +// or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.openeggbert.screens; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.ScreenAdapter; +import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.openeggbert.entity.common.OpenEggbertException; +import com.openeggbert.entity.common.OpenEggbertScreenType; +import com.openeggbert.main.OpenEggbertGame; +import java.util.Optional; + +/** + * + * @author robertvokac + */ +public abstract class AbstractOpenEggbertScreen extends ScreenAdapter { + + protected OpenEggbertGame game; + protected SpriteBatch batch; + + public AbstractOpenEggbertScreen(OpenEggbertGame openEggbertGame) { + this.game = openEggbertGame; + this.batch = openEggbertGame.getBatch(); + loadBackgroundTextureIfNeeded(); + } + + private final String getBackgroundFileName() { + return getScreenType().isPresent() ? getScreenType().get().getFileName() : ""; + } + + protected Optional getScreenType() { + return Optional.empty(); + } + protected Optional getBackgroundTexture() { + if (getBackgroundFileName().isEmpty()) { + return Optional.empty(); + } + return game.getImageTexture(getBackgroundFileName()); + } + + private void loadBackgroundTextureIfNeeded() { + if (getBackgroundFileName().isEmpty()) { + return; + } + String fileName = getBackgroundFileName(); + if (!game.existsImageTexture(fileName)) { + FileHandle fileHandleUpperCase = Gdx.files.absolute(game.getGameSpace().getImage08Directory() + "/" + fileName); + FileHandle fileHandleLowerCase = Gdx.files.absolute(game.getGameSpace().getImage08Directory() + "/" + fileName.toLowerCase()); + if (fileHandleUpperCase.exists()) { + game.loadImageTexture(fileHandleUpperCase); + } else { + if (!fileHandleLowerCase.exists()) { + throw new OpenEggbertException("Could not load file: " + fileName); + } + game.loadImageTexture(fileHandleLowerCase); + } + } + } + +} diff --git a/core/src/main/java/com/openeggbert/screens/GameSpaceListScreen.java b/core/src/main/java/com/openeggbert/screens/GameSpaceListScreen.java new file mode 100644 index 0000000..c94b5d8 --- /dev/null +++ b/core/src/main/java/com/openeggbert/screens/GameSpaceListScreen.java @@ -0,0 +1,188 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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 +// or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.openeggbert.screens; + +import com.badlogic.gdx.Application; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; +import com.badlogic.gdx.InputAdapter; +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.main.OpenEggbertGame; +import com.openeggbert.mods.Mod; +import com.openeggbert.mods.ModType; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import lombok.ToString; + +/** + * + * @author robertvokac + */ +public class GameSpaceListScreen extends AbstractOpenEggbertScreen { + + private int pageNumber = 1; + private final int pageSize = 5; + private final List fullEmbeddedMods; + @ToString + class Four { + float x,y,width, height; + } + Four[] fourArray = new Four[5]; + + public GameSpaceListScreen(OpenEggbertGame openEggbertGame) { + super(openEggbertGame); + this.fullEmbeddedMods = openEggbertGame.getEmbeddedMods().stream().filter(m -> m.getModType() == ModType.FULL).collect(Collectors.toList()); + Gdx.app.log("fullEmbeddedMods: ", String.valueOf(fullEmbeddedMods.size())); + Gdx.app.log("openEggbertGame.getEmbeddedMods(): ", String.valueOf(openEggbertGame.getEmbeddedMods().size())); + + if (Gdx.app.getType() == Application.ApplicationType.Android) { + game.setHeightInPixels(Gdx.app.getGraphics().getHeight()); + game.setWidthInPixels(Gdx.app.getGraphics().getWidth()); + } + } + + @Override + public void show() { + Gdx.input.setInputProcessor(new InputAdapter() { + @Override + public boolean keyDown(int keyCode) { + if (keyCode == Input.Keys.SPACE) { + game.setScreen(new TestScreen(game)); + } + return true; + } + + @Override + public boolean touchDown(int x, int y, int pointer, int button) { + Gdx.app.log("touchDown: ", "x=" + x + " " + "y=" + y); + if (x <= game.getWidthInPixels() / 3f && y >= (game.getHeightInPixels() * 0.92f) && pageNumber > 1) { + pageNumber--; + } + if (x >= game.getWidthInPixels() * 2f / 3f && y >= (game.getHeightInPixels() * 0.92f) && (pageNumber * pageSize) < fullEmbeddedMods.size()) { + pageNumber++; + } + for(int i = 0;i<5;i++) { + System.out.println(fourArray[i].toString()); + } + for(int i = 0;i<5;i++) { + if( + x > fourArray[i].x && x < (fourArray[i].x + fourArray[i].width) + && + y > fourArray[i].y && y < (fourArray[i].y + fourArray[i].height) + ) { + System.out.println("button " + i); + } + } + return true; + } + }); + + } + + @Override + public void render(float delta) { + ScreenUtils.clear(1f, 1f, 0.6f, 0.5f); + batch.begin(); + + BitmapFont font; + font = new BitmapFont(); + font.getData().setScale(4.0f); + font.setColor(Color.BLACK); + int x = (int) (game.getWidthInPixels() * 0.1875f); + int y = (int) (game.getHeightInPixels() * 0.9f); + font.draw(batch, "Open Eggbert", x, y); + List modsForPage = fullEmbeddedMods.stream().skip(pageSize * (pageNumber - 1)).limit(5).collect(Collectors.toList()); + + y = (int) (game.getHeightInPixels() * 0.75f); + font.getData().setScale(2.0f); + List yS = new ArrayList<>(); + for (int i = 0; i < modsForPage.size(); i++) { + yS.add(y); + + y = y - 60; + } + + float margin = 0.0625f * game.getWidthInPixels(); + batch.end(); + + final boolean isLastPage = !(pageNumber * pageSize < fullEmbeddedMods.size()); + + int buttonHeight = (int) (game.getHeightInPixels() * 0.1f); + final ShapeRenderer shapeRenderer = game.getShapeRenderer(); + shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); + shapeRenderer.setColor(1f, 1f, 0.8f, 0.5f); + int z = 0; + for (int e : yS) { + Four four = new Four(); + four.x = margin; + four.y = e-margin; + four.width = game.getWidthInPixels() * 0.9f; + four.height = buttonHeight; + fourArray[z] = four; + shapeRenderer.rect(four.x, four.y, four.width, four.height); + z++; + } + if (pageNumber > 1) { + shapeRenderer.rect(margin, margin / 4f, game.getWidthInPixels() * 0.3f, buttonHeight); + } + if (!isLastPage) { + shapeRenderer.rect(game.getWidthInPixels() * 0.66f, margin / 4f, game.getWidthInPixels() * 0.3f, buttonHeight); + } + shapeRenderer.end(); + batch.begin(); + font.setColor(0f, 0f, 1f, 1f); + + for (int i = 0; i < modsForPage.size(); i++) { + Mod mod = modsForPage.get(i); + String name = mod.getName() == null || mod.getName().isEmpty() ? mod.getIdentification().asString() : mod.getName(); + name = "#" + ((pageNumber - 1) * pageSize + (i + 1)) + " " + name; + font.draw(batch, name, 40, yS.get(i)); + } + font.getData().setScale(1.5f); + font.setColor(0f, 0f, 1f, 1f); + + float lastRowHeight = game.getHeightInPixels() * 0.08f; + if (pageNumber > 1) { + font.draw(batch, "Previous page", margin, lastRowHeight); + } + + if (!isLastPage) { + font.draw(batch, "Next page", game.getWidthInPixels() * 0.765625f, lastRowHeight); + } + font.setColor(0f, 0f, 0f, 1f); + int pageCount = fullEmbeddedMods.size() / 5; + if (fullEmbeddedMods.size() > pageCount * pageSize) { + pageCount++; + } + font.draw(batch, "Page " + pageNumber + " from " + pageCount, game.getWidthInPixels() / 2 - 80, lastRowHeight); + + batch.end(); + + } + + @Override + public void hide() { + Gdx.input.setInputProcessor(null); + } +} diff --git a/core/src/main/java/com/openeggbert/screens/InitScreen.java b/core/src/main/java/com/openeggbert/screens/InitScreen.java new file mode 100644 index 0000000..e8000f4 --- /dev/null +++ b/core/src/main/java/com/openeggbert/screens/InitScreen.java @@ -0,0 +1,73 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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 +// or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.openeggbert.screens; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; +import com.badlogic.gdx.InputAdapter; +import com.badlogic.gdx.utils.ScreenUtils; +import com.openeggbert.entity.common.OpenEggbertScreenType; +import com.openeggbert.main.OpenEggbertGame; +import java.util.Optional; + +/** + * + * @author robertvokac + */ +public class InitScreen extends AbstractOpenEggbertScreen { + + public InitScreen(OpenEggbertGame openEggbertGame) { + super(openEggbertGame); + + } + + protected final Optional getScreenType() { + return Optional.of(OpenEggbertScreenType.INIT); + } + + @Override + public void show() { + Gdx.input.setInputProcessor(new InputAdapter() { + @Override + public boolean keyDown(int keyCode) { + if (keyCode == Input.Keys.SPACE) { + game.setScreen(new GameSpaceListScreen(game)); + } + return true; + } + }); + } + + @Override + public void render(float delta) { + ScreenUtils.clear(0f, 0f, 0f, 1f); + batch.begin(); + if (getBackgroundTexture().isPresent()) { + batch.draw(getBackgroundTexture().get(), 0, 0); + } + + batch.end(); + } + + @Override + public void hide() { + Gdx.input.setInputProcessor(null); + } +} diff --git a/core/src/main/java/com/openeggbert/screens/TestScreen.java b/core/src/main/java/com/openeggbert/screens/TestScreen.java new file mode 100644 index 0000000..9f6b0dd --- /dev/null +++ b/core/src/main/java/com/openeggbert/screens/TestScreen.java @@ -0,0 +1,90 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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 +// or write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/////////////////////////////////////////////////////////////////////////////////////////////// +package com.openeggbert.screens; + +import com.badlogic.gdx.Application; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; +import com.badlogic.gdx.InputAdapter; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.utils.ScreenUtils; +import com.openeggbert.main.OpenEggbertGame; +import java.util.function.Function; + +/** + * + * @author robertvokac + */ +public class TestScreen extends AbstractOpenEggbertScreen { + + public TestScreen(OpenEggbertGame openEggbertGame) { + super(openEggbertGame); + } + + @Override + public void show() { + Gdx.input.setInputProcessor(new InputAdapter() { + @Override + public boolean keyDown(int keyCode) { + if (keyCode == Input.Keys.SPACE) { + game.setScreen(new GameSpaceListScreen(game)); + } + return true; + } + }); + } + + @Override + public void render(float delta) { + ScreenUtils.clear(0.15f, 0.15f, 0.2f, 1f); + game.getBatch().begin(); + Function removeCurrentDir = i -> i == null ? null : i.replace(game.getCurrentDirectory() + "/", ""); + if (Gdx.app.getType() == Application.ApplicationType.Desktop && game.getGameSpace() != null) { + BitmapFont font; + font = new BitmapFont(); + int x = 140; + font.draw(game.getBatch(), "getFeatureLevel=" + game.getGameSpace().getFeatureLevel(), 40, x); + x += 25; + font.draw(game.getBatch(), "getDataDirectory=" + removeCurrentDir.apply(game.getGameSpace().getDataDirectory()), 40, x); + x += 25; + font.draw(game.getBatch(), "getImage08Directory=" + removeCurrentDir.apply(game.getGameSpace().getImage08Directory()), 40, x); + x += 25; + font.draw(game.getBatch(), "getImage16Directory=" + removeCurrentDir.apply(game.getGameSpace().getImage16Directory()), 40, x); + x += 25; + font.draw(game.getBatch(), "getImage24Directory=" + removeCurrentDir.apply(game.getGameSpace().getImage24Directory()), 40, x); + x += 25; + font.draw(game.getBatch(), "getImage24x2Directory=" + removeCurrentDir.apply(game.getGameSpace().getImage24x2Directory()), 40, x); + x += 25; + font.draw(game.getBatch(), "getSoundDirectory=" + removeCurrentDir.apply(game.getGameSpace().getSoundDirectory()), 40, x); + } + + if (game.getCurrentDirectory() != null) { + BitmapFont font; + font = new BitmapFont(); + font.draw(game.getBatch(), game.getCurrentDirectory(), 40, 340); + } + game.getBatch().end(); + } + + @Override + public void hide() { + Gdx.input.setInputProcessor(null); + } +} diff --git a/html/src/main/java/com/openeggbert/GdxDefinition.gwt.xml b/html/src/main/java/com/openeggbert/GdxDefinition.gwt.xml index 17feee0..a8ed1a1 100644 --- a/html/src/main/java/com/openeggbert/GdxDefinition.gwt.xml +++ b/html/src/main/java/com/openeggbert/GdxDefinition.gwt.xml @@ -22,7 +22,7 @@ - + diff --git a/html/src/main/java/com/openeggbert/gwt/GwtLauncher.java b/html/src/main/java/com/openeggbert/gwt/GwtLauncher.java index e4e4851..844a848 100644 --- a/html/src/main/java/com/openeggbert/gwt/GwtLauncher.java +++ b/html/src/main/java/com/openeggbert/gwt/GwtLauncher.java @@ -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.OpenEggbertMainClass; +import com.openeggbert.main.OpenEggbertGame; /** Launches the GWT application. */ public class GwtLauncher extends GwtApplication { @@ -21,6 +21,6 @@ public class GwtLauncher extends GwtApplication { @Override public ApplicationListener createApplicationListener () { - return new OpenEggbertMainClass(); + return new OpenEggbertGame(); } } diff --git a/lwjgl3/src/main/java/com/openeggbert/lwjgl3/DesktopUtils.java b/lwjgl3/src/main/java/com/openeggbert/lwjgl3/DesktopUtils.java index 494e206..88872b9 100644 --- a/lwjgl3/src/main/java/com/openeggbert/lwjgl3/DesktopUtils.java +++ b/lwjgl3/src/main/java/com/openeggbert/lwjgl3/DesktopUtils.java @@ -38,8 +38,13 @@ public class DesktopUtils { public static Optional tryToLoadGameSpace() { String gameSpaceDirectoryFromEnvironmentVariable = System.getenv().getOrDefault("GAME_SPACE_DIRECTORY", ""); + String gameSpaceDirectoryFromSystemProperty = System.getProperty("GAME_SPACE_DIRECTORY", ""); + if (!gameSpaceDirectoryFromEnvironmentVariable.isBlank()) { return tryToLoadGameSpaceFromEnvironmentVariable(gameSpaceDirectoryFromEnvironmentVariable); + } + if (!gameSpaceDirectoryFromSystemProperty.isBlank()) { + return tryToLoadGameSpaceFromEnvironmentVariable(gameSpaceDirectoryFromSystemProperty); } Optional gameOptional = tryToLoadGameSpaceFromCurrentDirectory(); return gameOptional; diff --git a/lwjgl3/src/main/java/com/openeggbert/lwjgl3/Lwjgl3Launcher.java b/lwjgl3/src/main/java/com/openeggbert/lwjgl3/Lwjgl3Launcher.java index d56c8fa..e28ab7a 100644 --- a/lwjgl3/src/main/java/com/openeggbert/lwjgl3/Lwjgl3Launcher.java +++ b/lwjgl3/src/main/java/com/openeggbert/lwjgl3/Lwjgl3Launcher.java @@ -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.OpenEggbertMainClass; +import com.openeggbert.main.OpenEggbertGame; import com.openeggbert.entity.common.GameSpace; import java.util.Optional; @@ -34,10 +34,12 @@ public class Lwjgl3Launcher { } private static Lwjgl3Application createApplication() { + //System.getProperties().put("GAME_SPACE_DIRECTORY", "/rv/data/desktop/code/code.nanoboot.org/nanoboot/open-eggbert/assets/open-eggbert-legacy-assets/speedy_blupi_I"); + Optional gameSpace = DesktopUtils.tryToLoadGameSpace(); String currentDirectory = DesktopUtils.getPathToDirectoryWhereJarIsRunning(); - final OpenEggbertMainClass openEggbertMainClass = gameSpace.isPresent() ? new OpenEggbertMainClass(gameSpace.get(), currentDirectory) : new OpenEggbertMainClass(currentDirectory); - return new Lwjgl3Application(openEggbertMainClass, getDefaultConfiguration()); + final OpenEggbertGame openEggbertGame = gameSpace.isPresent() ? new OpenEggbertGame(gameSpace.get(), currentDirectory) : new OpenEggbertGame(currentDirectory); + return new Lwjgl3Application(openEggbertGame, getDefaultConfiguration()); } private static Lwjgl3ApplicationConfiguration getDefaultConfiguration() { @@ -49,7 +51,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(840, 480); + configuration.setWindowedMode(640, 480); configuration.setWindowIcon("libgdx128.png", "libgdx64.png", "libgdx32.png", "libgdx16.png"); return configuration; }