Refactoring IX
This commit is contained in:
parent
19219c681d
commit
ce996b8e1e
@ -19,13 +19,8 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.openeggbert.core.configuration;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Graphics;
|
||||
import com.badlogic.gdx.Graphics.DisplayMode;
|
||||
import com.openeggbert.core.fbox.core.FBox;
|
||||
import com.openeggbert.core.main.OpenEggbertException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -52,64 +47,25 @@ public enum OpenEggbertDisplayMode {
|
||||
public static OpenEggbertDisplayMode setDisplayModeToWindow() {
|
||||
return setDisplayMode(WINDOW);
|
||||
}
|
||||
private static DisplayMode originalDisplayMode = null;
|
||||
|
||||
public static OpenEggbertDisplayMode setDisplayMode(OpenEggbertDisplayMode displayMode) {
|
||||
|
||||
if (displayMode == OpenEggbertDisplayMode.FULLSCREEN) {
|
||||
Graphics.Monitor currentMonitor = Gdx.graphics.getMonitor();
|
||||
Graphics.DisplayMode displayModeFromLibGdx = Gdx.graphics.getDisplayMode(currentMonitor);
|
||||
if (originalDisplayMode == null) {
|
||||
originalDisplayMode = displayModeFromLibGdx;
|
||||
}
|
||||
|
||||
DisplayMode foundVgaDisplayMode = null;
|
||||
////
|
||||
// System.out.println("started loading all display modes");
|
||||
List<DisplayMode> vgaDisplayModes = Arrays
|
||||
.asList(Gdx.graphics.getDisplayModes(currentMonitor))
|
||||
.stream()
|
||||
.filter(d -> d.width == 640 && d.height == 480)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
//fixme
|
||||
// foundVgaDisplayMode = vgaDisplayModes.stream()
|
||||
// .sorted((a, b) -> Integer.valueOf(a.refreshRate).compareTo(b.refreshRate)).findFirst().get();
|
||||
|
||||
// System.out.println("ended loading all display modes");
|
||||
|
||||
// System.out.println(foundVgaDisplayMode.refreshRate);
|
||||
// System.out.println(foundVgaDisplayMode.width);
|
||||
// System.out.println(foundVgaDisplayMode.height);
|
||||
|
||||
////
|
||||
if (!Gdx.graphics.setFullscreenMode(foundVgaDisplayMode == null ? displayModeFromLibGdx : foundVgaDisplayMode)) {
|
||||
Gdx.app.error("InitScreen", "Switching to fullscreen mode failed.");
|
||||
return null;
|
||||
}
|
||||
return FULLSCREEN;
|
||||
|
||||
public static OpenEggbertDisplayMode find(boolean fullscreen, boolean window) {
|
||||
if (fullscreen && window) {
|
||||
throw new OpenEggbertException("Both arguments fullscreen and window are true.");
|
||||
}
|
||||
if (displayMode == OpenEggbertDisplayMode.WINDOW) {
|
||||
setToOriginalDisplayMode();
|
||||
Gdx.graphics.setWindowedMode(640, 480);
|
||||
if (!fullscreen && !window) {
|
||||
throw new OpenEggbertException("Both arguments fullscreen and window are false.");
|
||||
}
|
||||
if (fullscreen) {
|
||||
return FULLSCREEN;
|
||||
} else {
|
||||
return WINDOW;
|
||||
}
|
||||
throw new OpenEggbertException("Unsupported DisplayMode: " + displayMode);
|
||||
|
||||
}
|
||||
|
||||
public static void setToOriginalDisplayMode() {
|
||||
if (originalDisplayMode == null) {
|
||||
//nothing to do
|
||||
return;
|
||||
}
|
||||
if (!Gdx.graphics.setFullscreenMode(originalDisplayMode)) {
|
||||
Gdx.app.error("OpenEggbertDisplayMode", "Switching to original display mode failed.");
|
||||
return;
|
||||
}
|
||||
public static OpenEggbertDisplayMode setDisplayMode(OpenEggbertDisplayMode displayMode) {
|
||||
String result = FBox.get().graphics().setDisplayMode(displayMode == FULLSCREEN, displayMode == WINDOW);
|
||||
|
||||
return result == null ? null : OpenEggbertDisplayMode.valueOf(result);
|
||||
}
|
||||
|
||||
public OpenEggbertDisplayMode flip() {
|
||||
|
@ -17,12 +17,14 @@
|
||||
// <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.definitiveframework;
|
||||
package com.openeggbert.core.fbox.api;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface DefinitiveFramework {
|
||||
public interface FBoxGraphicsInterface {
|
||||
boolean setToOriginalDisplayMode();
|
||||
String setDisplayMode(boolean fullscreen, boolean window);
|
||||
|
||||
}
|
@ -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.fbox.api;
|
||||
|
||||
import com.openeggbert.core.fbox.entity.Platform;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface FBoxInterface {
|
||||
|
||||
void exit();
|
||||
Platform getPlatform();
|
||||
FBoxGraphicsInterface graphics();
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.fbox.core;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class DefinitiveFrameworkException extends RuntimeException{
|
||||
|
||||
public DefinitiveFrameworkException(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
}
|
41
core/src/main/java/com/openeggbert/core/fbox/core/FBox.java
Normal file
41
core/src/main/java/com/openeggbert/core/fbox/core/FBox.java
Normal file
@ -0,0 +1,41 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.fbox.core;
|
||||
|
||||
import com.openeggbert.core.fbox.impl.libgdx.FBoxLibGdxImpl;
|
||||
import com.openeggbert.core.fbox.api.FBoxInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class FBox {
|
||||
private static FBoxInterface INSTANCE = null;
|
||||
|
||||
private FBox() {
|
||||
//Not meant to be instantiated.
|
||||
}
|
||||
public static FBoxInterface get() {
|
||||
if(INSTANCE == null) {
|
||||
INSTANCE = new FBoxLibGdxImpl();
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.fbox.entity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public enum Platform {
|
||||
DESKTOP, ANDROID, WEB;
|
||||
public boolean isDesktop() {return this == DESKTOP;}
|
||||
public boolean isAndroid() {return this == ANDROID;}
|
||||
public boolean isWeb() {return this == WEB;}
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.fbox.impl.libgdx;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Graphics;
|
||||
import com.openeggbert.core.fbox.utils.Constants;
|
||||
import com.openeggbert.core.fbox.core.DefinitiveFrameworkException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import com.openeggbert.core.fbox.api.FBoxGraphicsInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class FBoxGraphicsLibGdxImpl implements FBoxGraphicsInterface {
|
||||
|
||||
|
||||
@Override
|
||||
public String setDisplayMode(boolean fullscreen, boolean window) {
|
||||
|
||||
if (fullscreen) {
|
||||
Graphics.Monitor currentMonitor = Gdx.graphics.getMonitor();
|
||||
Graphics.DisplayMode displayModeFromLibGdx = Gdx.graphics.getDisplayMode(currentMonitor);
|
||||
if (originalDisplayMode == null) {
|
||||
originalDisplayMode = displayModeFromLibGdx;
|
||||
}
|
||||
|
||||
Graphics.DisplayMode foundVgaDisplayMode = null;
|
||||
////
|
||||
// System.out.println("started loading all display modes");
|
||||
List<Graphics.DisplayMode> vgaDisplayModes = Arrays
|
||||
.asList(Gdx.graphics.getDisplayModes(currentMonitor))
|
||||
.stream()
|
||||
.filter(d -> d.width == 640 && d.height == 480)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//fixme
|
||||
// foundVgaDisplayMode = vgaDisplayModes.stream()
|
||||
// .sorted((a, b) -> Integer.valueOf(a.refreshRate).compareTo(b.refreshRate)).findFirst().get();
|
||||
// System.out.println("ended loading all display modes");
|
||||
// System.out.println(foundVgaDisplayMode.refreshRate);
|
||||
// System.out.println(foundVgaDisplayMode.width);
|
||||
// System.out.println(foundVgaDisplayMode.height);
|
||||
////
|
||||
if (!Gdx.graphics.setFullscreenMode(foundVgaDisplayMode == null ? displayModeFromLibGdx : foundVgaDisplayMode)) {
|
||||
Gdx.app.error("InitScreen", "Switching to fullscreen mode failed.");
|
||||
return null;
|
||||
}
|
||||
return Constants.FULLSCREEN;
|
||||
|
||||
}
|
||||
if (window) {
|
||||
setToOriginalDisplayMode();
|
||||
Gdx.graphics.setWindowedMode(640, 480);
|
||||
return Constants.WINDOW;
|
||||
}
|
||||
throw new DefinitiveFrameworkException("Unsupported DisplayMode: fullscreen=" + fullscreen + " window=" + window);
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean setToOriginalDisplayMode() {
|
||||
if (originalDisplayMode == null) {
|
||||
//nothing to do
|
||||
return true;
|
||||
}
|
||||
if (!Gdx.graphics.setFullscreenMode(originalDisplayMode)) {
|
||||
Gdx.app.error("DefinitiveFrameworkLibGdxImpl", "Switching to original display mode failed.");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Graphics.DisplayMode originalDisplayMode = null;
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.fbox.impl.libgdx;
|
||||
|
||||
import com.badlogic.gdx.Application;
|
||||
import static com.badlogic.gdx.Application.ApplicationType.Desktop;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.openeggbert.core.fbox.core.DefinitiveFrameworkException;
|
||||
import com.openeggbert.core.fbox.entity.Platform;
|
||||
import com.openeggbert.core.fbox.api.FBoxGraphicsInterface;
|
||||
import com.openeggbert.core.fbox.api.FBoxInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class FBoxLibGdxImpl implements FBoxInterface {
|
||||
|
||||
private FBoxGraphicsLibGdxImpl fBoxGraphicsLibGdxImpl = null;
|
||||
@Override
|
||||
public void exit() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
@Override
|
||||
public Platform getPlatform() {
|
||||
Application.ApplicationType applicationType = Gdx.app.getType();
|
||||
switch(applicationType) {
|
||||
case Desktop: return Platform.DESKTOP;
|
||||
case Android: return Platform.ANDROID;
|
||||
case WebGL: return Platform.WEB;
|
||||
default: throw new DefinitiveFrameworkException("Unsupported platform: " + applicationType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FBoxGraphicsInterface graphics() {
|
||||
if(fBoxGraphicsLibGdxImpl == null) {
|
||||
fBoxGraphicsLibGdxImpl = new FBoxGraphicsLibGdxImpl();
|
||||
}
|
||||
return fBoxGraphicsLibGdxImpl;
|
||||
}
|
||||
}
|
@ -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.fbox.utils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class Constants {
|
||||
|
||||
private Constants() {
|
||||
//Not meant to be instantiated.
|
||||
}
|
||||
|
||||
public static final String WINDOW = "WINDOW";
|
||||
public static final String FULLSCREEN = "FULLSCREEN";
|
||||
}
|
@ -19,9 +19,9 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.openeggbert.core.utils;
|
||||
|
||||
import com.badlogic.gdx.Application;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.openeggbert.core.fbox.core.FBox;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -35,7 +35,7 @@ public class EmbeddedFileHandleFactory {
|
||||
|
||||
public static FileHandle create(String name) {
|
||||
|
||||
if (Gdx.app.getType() == Application.ApplicationType.Android || Gdx.app.getType() == Application.ApplicationType.WebGL) {
|
||||
if (FBox.get().getPlatform().isAndroid() || FBox.get().getPlatform().isWeb()) {
|
||||
return Gdx.files.internal(name);
|
||||
} else {
|
||||
return Gdx.files.classpath(name);
|
||||
|
@ -17,7 +17,7 @@
|
||||
// <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.lwjgl3.debugging.storage;
|
||||
package com.openeggbert.lwjgl3.debugging;
|
||||
|
||||
import com.openeggbert.gdx.storage.command.CommandLineScanner;
|
||||
import java.util.Scanner;
|
@ -17,7 +17,7 @@
|
||||
// <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.lwjgl3.debugging.storage;
|
||||
package com.openeggbert.lwjgl3.debugging;
|
||||
|
||||
import com.openeggbert.gdx.storage.command.StorageCommandLine;
|
||||
import com.openeggbert.gdx.storage.command.StorageCommandLineScanner;
|
Reference in New Issue
Block a user