API improvements II

This commit is contained in:
Robert Vokac 2024-10-01 21:38:22 +02:00
parent 8d4c62f414
commit 78cfe4fa33
Signed by: robertvokac
GPG Key ID: FB9CE8E20AADA55F
20 changed files with 644 additions and 7 deletions

View File

@ -29,5 +29,9 @@ public class PixelException extends RuntimeException{
public PixelException(String string) {
super(string);
}
public PixelException(String string, Exception e) {
super(string, e);
}
}

View File

@ -0,0 +1,71 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel Game Library.
// Copyright (C) 2024 Your Name or Company.
//
// 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 com.pixelgamelibrary.api.PixelException;
/** Represents the version of the game library.
*
* Author: Your Name */
public class Version {
/** The current version of the game library in major.minor.revision format **/
public static final String VERSION_STRING = "1.0.0";
/** The current major version **/
public static final int MAJOR_VERSION;
/** The current minor version **/
public static final int MINOR_VERSION;
/** The current revision version **/
public static final int REVISION_VERSION;
static {
try {
String[] versionParts = VERSION_STRING.split("\\.");
MAJOR_VERSION = versionParts.length < 1 ? 0 : Integer.parseInt(versionParts[0]);
MINOR_VERSION = versionParts.length < 2 ? 0 : Integer.parseInt(versionParts[1]);
REVISION_VERSION = versionParts.length < 3 ? 0 : Integer.parseInt(versionParts[2]);
} catch (Exception e) {
// This should not happen
throw new PixelException("Invalid version format: " + VERSION_STRING, e);
}
}
public static boolean isVersionHigher(int major, int minor, int revision) {
return isVersionHigherOrEqual(major, minor, revision + 1);
}
public static boolean isVersionHigherOrEqual(int major, int minor, int revision) {
if (MAJOR_VERSION != major) return MAJOR_VERSION > major;
if (MINOR_VERSION != minor) return MINOR_VERSION > minor;
return REVISION_VERSION >= revision;
}
public static boolean isVersionLower(int major, int minor, int revision) {
return isVersionLowerOrEqual(major, minor, revision - 1);
}
public static boolean isVersionLowerOrEqual(int major, int minor, int revision) {
if (MAJOR_VERSION != major) return MAJOR_VERSION < major;
if (MINOR_VERSION != minor) return MINOR_VERSION < minor;
return REVISION_VERSION <= revision;
}
}

View File

@ -20,10 +20,12 @@
package com.pixelgamelibrary.api.app;
import com.pixelgamelibrary.api.storage.map.SimpleMap;
/**
*
* @author robertvokac
*/
public interface Preferences {
public interface Preferences extends SimpleMap {
}

View File

@ -17,13 +17,21 @@
// <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.graphics;
import com.pixelgamelibrary.api.math.Vector2;
/**
*
* @author robertvokac
*/
public interface Camera {
void zoom(float zoom);
void rotate(float angle);
void translate(float x, float y);
void translate(Vector2 vector);
}

View File

@ -20,11 +20,19 @@
package com.pixelgamelibrary.api.graphics;
import com.pixelgamelibrary.api.Disposable;
/**
*
* @author robertvokac
*/
public interface Texture {
public interface Texture extends Disposable {
void draw (Pixmap pixmap, int x, int y);
int getWidth ();
int getHeight ();
int getDepth ();
//
void makeColorTransparent(int r, int g, int b);
void scale(double d);
void setColorMode(ColorMode colorMode, int bitCount);

View File

@ -0,0 +1,34 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// 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.graphics;
import com.pixelgamelibrary.api.storage.FileHandle;
/**
*
* @author robertvokac
*/
public interface TextureFactory {
Texture create(String assetPath);
Texture create(FileHandle fileHandle);
Texture create(Pixmap pixmap);
Texture create(int width, int height);
}

View File

@ -0,0 +1,31 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// 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.graphics;
/**
*
* @author robertvokac
*/
public enum TextureFilter {
NEAREST, LINEAR;
//todo
}

View File

@ -0,0 +1,29 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// 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.input;
/**
*
* @author robertvokac
*/
public enum DeviceOrientation {
LANDSCAPE, PORTRAIT;
}

View File

@ -0,0 +1,46 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// 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.input;
/**
*
* @author robertvokac
*/
public interface InputProcessor {
public boolean keyDown (int keycode);
public boolean keyUp (int keycode);
public boolean keyTyped (char character);
public boolean touchDown (int screenX, int screenY, int pointer, int button);
public boolean touchUp (int screenX, int screenY, int pointer, int button);
public boolean touchCancelled (int screenX, int screenY, int pointer, int button);
public boolean touchDragged (int screenX, int screenY, int pointer);
public boolean mouseMoved (int screenX, int screenY);
public boolean scrolled (float amountX, float amountY);
}

View File

@ -0,0 +1,73 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// 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.input;
/**
*
* @author robertvokac
*/
public class InputProcessorAdapter implements InputProcessor {
@Override
public boolean keyDown(int keycode) {
return false;
}
@Override
public boolean keyUp(int keycode) {
return false;
}
@Override
public boolean keyTyped(char character) {
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchCancelled(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
@Override
public boolean scrolled(float amountX, float amountY) {
return false;
}
}

View File

@ -0,0 +1,29 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// 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.input;
/**
*
* @author robertvokac
*/
public enum KeyboardKey {
//todo
}

View File

@ -0,0 +1,29 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// 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.input;
/**
*
* @author robertvokac
*/
public enum MouseButton {
LEFT, RIGHT, MIDDLE, BACK, FORWARD;
}

View File

@ -0,0 +1,29 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// 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.input;
/**
*
* @author robertvokac
*/
public enum OnScreenKeyboardType {
DEFAULT, NUMBER_PAD, E_MAIL, PASSWORD, URI, GAME;
}

View File

@ -0,0 +1,38 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// 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.input;
/**
*
* @author robertvokac
*/
public enum Peripheral {
HARDWARE_KEYBOARD,
ONSCREEN_KEYBOARD,
MULTITOUCH_SCREEN,
ACCELEROMETER,
COMPASS,
VIBRATOR,
HAPTIC_FEEDBACK,
GYROSCOPE,
ROTATION_VECTOR,
PRESSURE
}

View File

@ -25,5 +25,5 @@ package com.pixelgamelibrary.api.input;
* @author robertvokac
*/
public enum VibrationType {
LIGHT, MEDIUM, HEAVY;
}

View File

@ -60,6 +60,6 @@ public interface App {
}
boolean isFeatureEnabled(String feature);
boolean isMobileDevice();
void postRunnable(Runnable runnable);
void runLater(Runnable runnable);
ClipBoard getClipBoard();
}

View File

@ -19,10 +19,152 @@
///////////////////////////////////////////////////////////////////////////////////////////////
package com.pixelgamelibrary.api.interfaces;
import com.pixelgamelibrary.api.input.DeviceOrientation;
import com.pixelgamelibrary.api.input.InputProcessor;
import com.pixelgamelibrary.api.input.KeyboardKey;
import com.pixelgamelibrary.api.input.MouseButton;
import com.pixelgamelibrary.api.input.OnScreenKeyboardType;
import com.pixelgamelibrary.api.input.Peripheral;
import com.pixelgamelibrary.api.input.VibrationType;
import com.pixelgamelibrary.api.math.Vector2;
import com.pixelgamelibrary.api.math.Vector3;
/**
*
* @author robertvokac
*/
public interface Input {
default void unlockCursor() {
lockCursor(false);
}
default void lockCursor() {
lockCursor(true);
}
default void lockCursor(boolean value) {
setCursorLocked(value);
}
void setCursorLocked(boolean value);
boolean isCursorLocked();
void setCursorPosition(int x, int y);
Vector3 getAccelerometerPosition();
default float getAccelerometerX() {
return getAccelerometerPosition().getX();
}
default float getAccelerometerY() {
return getAccelerometerPosition().getY();
}
default float getAccelerometerZ() {
return getAccelerometerPosition().getZ();
}
Vector3 getGyroscopPosition();
default float getGyroscopX() {
return getGyroscopPosition().getX();
}
default float getGyroscopY() {
return getGyroscopPosition().getY();
}
default float getGyroscopZ() {
return getGyroscopPosition().getZ();
}
int getMaxTouchPoints();
Vector2 getCursorPosition();
default float getCursorX() {
return getCursorPosition().getX();
}
default float getCursorY() {
return getCursorPosition().getY();
}
Vector2 getDeltaCursorPosition();
default float getDeltaCursorX() {
return getDeltaCursorPosition().getX();
}
default float getDeltaCursorY() {
return getDeltaCursorPosition().getY();
}
Vector2 getDeltaCursorPosition(int touchPointNumber);
default float getDeltaCursorX(int touchPointNumber) {
return getDeltaCursorPosition(touchPointNumber).getX();
}
default float getDeltaCursorY(int touchPointNumber) {
return getDeltaCursorPosition(touchPointNumber).getY();
}
boolean isTouched();
boolean justTouched();
boolean isTouched(int touchPointNumber);
float getTouchPressure();
float getTouchPressure(int pointer);
boolean isMouseButtonPressed(MouseButton button);
boolean isMouseButtonJustPressed(MouseButton button);
boolean isKeyboardKeyPressed(KeyboardKey key);
boolean isKeyboardKeyJustPressed(KeyboardKey key);
void setOnscreenKeyboardVisible(boolean visible);
void setOnscreenKeyboardVisible(boolean visible, OnScreenKeyboardType type);
void vibrate(int milliseconds);
void vibrate(int milliseconds, boolean fallback);
void vibrate(int milliseconds, int amplitude, boolean fallback);
void vibrate(VibrationType vibrationType);
Vector3 getOrientationAngles();
//pitch
default float getOrientationAngleX() {
return getOrientationAngles().getX();
}
//roll
default float getOrientationAngleY() {
return getOrientationAngles().getY();
}
//azimuth
default float getOrientationAngleZ() {
return getOrientationAngles().getZ();
}
public void setInputProcessor(InputProcessor processor);
public InputProcessor getInputProcessor();
boolean isPeripheralAvailable(Peripheral peripheral);
DeviceOrientation getDeviceOrientation();
}

View File

@ -0,0 +1,32 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// 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.math;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@AllArgsConstructor
@Getter
@Setter
public final class Vector2 {
private int x,y;
}

View File

@ -0,0 +1,32 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// 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.math;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@AllArgsConstructor
@Getter
@Setter
public final class Vector3 {
private int x,y,z;
}

View File

@ -112,7 +112,7 @@ public class MapStorageTest {
}
@Override
public void postRunnable(Runnable runnable) {
public void runLater(Runnable runnable) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}