Bug 20: Rework and refactor the Screen class

This commit is contained in:
Robert Vokac 2024-09-15 19:37:05 +02:00 committed by Robert Vokac
parent e7ef3decd3
commit 882d5466f8
Signed by: robertvokac
GPG Key ID: FB9CE8E20AADA55F
17 changed files with 512 additions and 15 deletions

View File

@ -0,0 +1,40 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// 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.pixelgamelibrary.api;
/**
*
* @author robertvokac
*/
public interface ApplicationListener {
void resize(int width, int height);
void show();
void hide();
void pause();
void resume();
void dispose();
}

View File

@ -0,0 +1,91 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// 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.pixelgamelibrary.api;
/**
*
* @author robertvokac
*/
public class GameAdapter implements GameI {
private ScreenI screen;
private OnSetScreenListener setOnSetScreenListener;
@Override
public void create() {
}
@Override
public void setScreen(ScreenI screen) {
this.screen = screen;
System.out.println("setOnSetScreenListener=" + setOnSetScreenListener);
if(setOnSetScreenListener != null) {
setOnSetScreenListener.onSetScreen(screen);
}
System.out.println("GameAdapter:setScreen");
}
@Override
public ScreenI getScreen() {
return screen;
}
@Override
public void render() {
}
@Override
public void resize(int width, int height) {
}
@Override
public void show() {
}
@Override
public void hide() {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
@Override
public void setOnSetScreenListener(OnSetScreenListener setScreenListener) {
this.setOnSetScreenListener = setScreenListener;
}
}

View File

@ -0,0 +1,37 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// 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.pixelgamelibrary.api;
/**
*
* @author robertvokac
*/
public interface GameI extends ApplicationListener {
void create();
void setScreen(ScreenI screen);
ScreenI getScreen();
void render();
void setOnSetScreenListener(OnSetScreenListener setScreenListener);
}

View File

@ -0,0 +1,90 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// 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.pixelgamelibrary.api;
/**
*
* @author robertvokac
*/
public class GameWrapper implements GameI {
private final GameI game;
public GameWrapper(GameI gameI) {
this.game = gameI;
}
@Override
public void create() {
game.create();
}
@Override
public void setScreen(ScreenI screen) {
game.setScreen(screen);
}
@Override
public ScreenI getScreen() {
return game.getScreen();
}
@Override
public void render() {
game.render();
}
@Override
public void resize(int width, int height) {
game.resize(width, height);
}
@Override
public void show() {
game.show();
}
@Override
public void hide() {
game.hide();
}
@Override
public void pause() {
game.pause();
}
@Override
public void resume() {
game.resume();
}
@Override
public void dispose() {
game.dispose();
}
@Override
public void setOnSetScreenListener(OnSetScreenListener setScreenListener) {
game.setOnSetScreenListener(setScreenListener);
}
}

View File

@ -17,13 +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.pixelgamelibrary.api;
/**
*
* @author robertvokac
*/
public abstract class Game extends com.badlogic.gdx.Game {
public interface OnSetScreenListener {
void onSetScreen(ScreenI screen);
}

View File

@ -24,6 +24,7 @@ import com.pixelgamelibrary.api.interfaces.AssetI;
import com.pixelgamelibrary.api.interfaces.AudioI;
import com.pixelgamelibrary.api.interfaces.GraphicsI;
import com.pixelgamelibrary.api.interfaces.InputI;
import com.pixelgamelibrary.api.interfaces.InternalI;
import com.pixelgamelibrary.api.interfaces.NetI;
import com.pixelgamelibrary.api.interfaces.PixelBackend;
import com.pixelgamelibrary.api.interfaces.StorageI;
@ -77,6 +78,10 @@ public class Pixel {
public static UtilsI utils() {
return get().utils();
}
public static InternalI internal() {
return get().internal();
}
////
public static void initBackend(PixelBackend pixelBackend) {

View File

@ -0,0 +1,50 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// 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.pixelgamelibrary.api;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author robertvokac
*/
public abstract class PixelApplication {
abstract public GameI createGameViaMap(Map<String, Object> objects);
public GameI createGame() {
return createGame(new HashMap<>());
}
public GameI createGame(Object... objects) {
Map<String, Object> map = new HashMap<>();
int i = 0;
int maxI = objects.length - 1;
while(i<objects.length) {
String key = (String)objects[i];
i++;
Object value = i > maxI ? null : objects[i];
map.put(key, value);
}
return createGameViaMap(map);
}
}

View File

@ -24,9 +24,10 @@ package com.pixelgamelibrary.api;
* @author robertvokac
*/
public enum Platform {
DESKTOP, ANDROID, WEB;
DESKTOP, ANDROID, WEB, IOS;
public boolean isDesktop() {return this == DESKTOP;}
public boolean isAndroid() {return this == ANDROID;}
public boolean isWeb() {return this == WEB;}
public boolean isIOS() {return this == IOS;}
}

View File

@ -0,0 +1,64 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// 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.pixelgamelibrary.api;
/**
*
* @author robertvokac
*/
public class ScreenAdapter implements ScreenI{
private GameI game = null;
@Override
public void resize(int width, int height) {
}
@Override
public void render(float delta) {
}
@Override
public void show() {
}
@Override
public void hide() {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}

View File

@ -23,6 +23,7 @@ package com.pixelgamelibrary.api;
*
* @author robertvokac
*/
public abstract class Screen extends com.badlogic.gdx.ScreenAdapter {
public interface ScreenI extends ApplicationListener {
void render(float delta);
}

View File

@ -0,0 +1,70 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// 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.pixelgamelibrary.api;
/**
*
* @author robertvokac
*/
public class ScreenWrapper implements ScreenI {
private final ScreenI screen;
public ScreenWrapper(ScreenI screenIn) {
this.screen = screenIn;
}
@Override
public void render(float delta) {
screen.render(delta);
}
@Override
public void resize(int width, int height) {
screen.resize(width, height);
}
@Override
public void show() {
screen.show();
}
@Override
public void hide() {
screen.hide();
}
@Override
public void pause() {
screen.pause();
}
@Override
public void resume() {
screen.resume();
}
@Override
public void dispose() {
screen.dispose();
}
}

View File

@ -17,18 +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.pixelgamelibrary.api;
/**
*
* @author robertvokac
*/
public class WindowMode {
public enum WindowMode {
private WindowMode() {
//Not meant to be instantiated.
}
public static final String WINDOW = "WINDOW";
public static final String FULLSCREEN = "FULLSCREEN";
WINDOW, FULLSCREEN;
}

View File

@ -19,6 +19,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////
package com.pixelgamelibrary.api.interfaces;
import com.pixelgamelibrary.api.GameI;
import com.pixelgamelibrary.api.Platform;
/**
@ -45,4 +46,8 @@ public interface AppI {
String getAppName();
boolean isAppNameSet();
void setGame(GameI game);
GameI getGame();
}

View File

@ -19,12 +19,14 @@
///////////////////////////////////////////////////////////////////////////////////////////////
package com.pixelgamelibrary.api.interfaces;
import com.pixelgamelibrary.api.WindowMode;
/**
*
* @author robertvokac
*/
public interface GraphicsI {
boolean setToOriginalDisplayMode();
String setDisplayMode(boolean fullscreen, boolean window);
WindowMode setDisplayMode(boolean fullscreen, boolean window);
}

View File

@ -0,0 +1,28 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// 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.pixelgamelibrary.api.interfaces;
/**
*
* @author robertvokac
*/
public interface InternalI {
}

View File

@ -25,8 +25,6 @@ package com.pixelgamelibrary.api.interfaces;
*/
public interface PixelBackend {
AppI app();
GraphicsI graphics();
AudioI audio();
@ -35,5 +33,6 @@ public interface PixelBackend {
AssetI asset();
StorageI storage();
UtilsI utils();
InternalI internal();
}

View File

@ -1,5 +1,6 @@
package com.pixelgamelibrary.api.storage.map;
import com.pixelgamelibrary.api.GameI;
import com.pixelgamelibrary.api.Pixel;
import com.pixelgamelibrary.api.Platform;
import com.pixelgamelibrary.api.interfaces.AppI;
@ -7,6 +8,7 @@ import com.pixelgamelibrary.api.interfaces.AssetI;
import com.pixelgamelibrary.api.interfaces.AudioI;
import com.pixelgamelibrary.api.interfaces.GraphicsI;
import com.pixelgamelibrary.api.interfaces.InputI;
import com.pixelgamelibrary.api.interfaces.InternalI;
import com.pixelgamelibrary.api.interfaces.NetI;
import com.pixelgamelibrary.api.interfaces.PixelBackend;
import com.pixelgamelibrary.api.interfaces.StorageI;
@ -75,6 +77,16 @@ public class MapStorageTest {
public boolean isAppNameSet() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
@Override
public void setGame(GameI game) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
@Override
public GameI getGame() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
};
}
@ -113,6 +125,11 @@ public class MapStorageTest {
public UtilsI utils() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
@Override
public InternalI internal() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
};
Pixel.initBackend(dummyPixelBackend);
}