Bug 13: Separate Pixel Game Library (API) into a separate Git repository
This commit is contained in:
parent
95e5d4f992
commit
94d8bc131c
@ -44,3 +44,9 @@ Useful Gradle tasks and flags:
|
||||
|
||||
Note that most tasks that are not specific to a single project can be run with `name:` prefix, where the `name` should be replaced with the ID of a specific project.
|
||||
For example, `core:clean` removes `build` folder only from the `core` project.
|
||||
|
||||
## FAQ
|
||||
|
||||
How to clean Gradle cache
|
||||
|
||||
`./gradlew clean build --refresh-dependencies`
|
||||
|
@ -57,7 +57,7 @@ dependencies {
|
||||
implementation "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
|
||||
implementation "com.github.MrStahlfelge.gdx-websockets:common:$websocketVersion"
|
||||
implementation project(':core')
|
||||
implementation project(':pixel')
|
||||
implementation "com.pixelgamelibrary:pixel:$pixelVersion"
|
||||
implementation project(':pixel-backend-libgdx')
|
||||
//implementation "com.openeggbert.gdx:gdx-storage:0.0.0-SNAPSHOT"
|
||||
|
||||
|
@ -2,6 +2,7 @@ buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'https://s01.oss.sonatype.org' }
|
||||
maven { url 'https://repo.openeggbert.com' }
|
||||
gradlePluginPortal()
|
||||
mavenLocal()
|
||||
google()
|
||||
@ -60,9 +61,6 @@ configure(subprojects - project(':android')) {
|
||||
subprojects {
|
||||
version = '0.0.0-SNAPSHOT'
|
||||
ext.appName = 'open-eggbert'
|
||||
if (project.name == 'pixel') {
|
||||
ext.appName = 'pixel'
|
||||
}
|
||||
if (project.name == 'pixel-backend-libgdx') {
|
||||
ext.appName = 'pixel-backend-libgdx'
|
||||
}
|
||||
@ -74,6 +72,11 @@ subprojects {
|
||||
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
|
||||
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
|
||||
maven { url 'https://jitpack.io' }
|
||||
|
||||
maven { url 'https://repo.openeggbert.com' }
|
||||
maven { url 'https://repo.openeggbert.com/releases/' }
|
||||
maven { url 'https://repo.openeggbert.com/snapshots/' }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,8 @@ dependencies {
|
||||
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.3"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.3"
|
||||
implementation project(':pixel')
|
||||
api "com.pixelgamelibrary:pixel:$pixelVersion"
|
||||
|
||||
}
|
||||
|
||||
test {
|
||||
|
@ -18,3 +18,4 @@ android.enableR8.fullMode=false
|
||||
gwtFrameworkVersion=2.11.0
|
||||
gwtPluginVersion=1.1.29
|
||||
gdxVersion=1.12.1
|
||||
pixelVersion=0.0.0-SNAPSHOT
|
||||
|
@ -47,13 +47,13 @@ dependencies {
|
||||
implementation "com.github.tommyettinger:libgdx-utils:$utilsVersion:sources"
|
||||
implementation "com.google.jsinterop:jsinterop-annotations:2.0.2:sources"
|
||||
implementation "de.golfgl.gdxcontrollerutils:gdx-controllerutils-mapping:$controllerMappingVersion:sources"
|
||||
|
||||
implementation project(':core')
|
||||
implementation project(':pixel')
|
||||
implementation "com.pixelgamelibrary:pixel:$pixelVersion:sources"
|
||||
implementation project(':pixel-backend-libgdx')
|
||||
implementation("com.badlogicgames.gdx-controllers:gdx-controllers-gwt:$gdxControllersVersion:sources"){exclude group: "com.badlogicgames.gdx", module: "gdx-backend-gwt"}
|
||||
implementation("com.badlogicgames.gdx:gdx-box2d-gwt:$gdxVersion:sources") {exclude group: "com.google.gwt", module: "gwt-user"}
|
||||
implementation("com.github.crykn.guacamole:gdx-gwt:$guacamoleVersion:sources"){exclude group: "com.badlogicgames.gdx", module: "gdx-backend-gwt"}
|
||||
//implementation "com.openeggbert.gdx:gdx-storage:0.0.0-SNAPSHOT"
|
||||
|
||||
}
|
||||
|
||||
@ -149,7 +149,6 @@ task dist(dependsOn: [clean, compileGwt]) {
|
||||
task addSource {
|
||||
doLast {
|
||||
sourceSets.main.compileClasspath += files(project(':core').sourceSets.main.allJava.srcDirs)
|
||||
sourceSets.main.compileClasspath += files(project(':pixel').sourceSets.main.allJava.srcDirs)
|
||||
sourceSets.main.compileClasspath += files(project(':pixel-backend-libgdx').sourceSets.main.allJava.srcDirs)
|
||||
sourceSets.main.compileClasspath += files("../core/build/generated/sources/annotationProcessor/java/main")
|
||||
|
||||
|
@ -23,9 +23,8 @@
|
||||
<inherits name="com.github.czyzby.websocket.GdxWebSocketGwt" />
|
||||
<inherits name="com.github.czyzby.websocket.GdxWebSocketSerialization" />
|
||||
<inherits name="com.openeggbert.core.main.OpenEggbertGame" />
|
||||
<inherits name="com.pixelgamelibrary.Pixel" />
|
||||
<inherits name="com.pixelgamelibrary" />
|
||||
<inherits name="com.pixelgamelibrary.backend.libgdx.PixelLibGDXBackend" />
|
||||
<!--<inherits name="com.openeggbert.gdx.storage.GdxStorageMainClass" />-->
|
||||
<inherits name="formic" />
|
||||
<inherits name="guacamole_gdx_gwt" />
|
||||
<inherits name="libgdx-utils" />
|
||||
|
@ -5,6 +5,7 @@ import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
|
||||
import com.openeggbert.core.configuration.ScreenResolution;
|
||||
import com.openeggbert.core.main.OpenEggbertGame;
|
||||
import com.badlogic.gdx.ai.GdxLogger;
|
||||
import com.pixelgamelibrary.Pixel;
|
||||
import com.pixelgamelibrary.backend.libgdx.PixelLibGDXBackend;
|
||||
|
||||
|
@ -31,9 +31,9 @@ dependencies {
|
||||
implementation "com.github.MrStahlfelge.gdx-websockets:common:$websocketVersion"
|
||||
implementation "com.github.crykn.guacamole:gdx-desktop:$guacamoleVersion"
|
||||
implementation "games.rednblack.miniaudio:miniaudio:$miniaudioVersion:natives-desktop"
|
||||
//implementation "com.openeggbert.gdx:gdx-storage:0.0.0-SNAPSHOT"
|
||||
|
||||
implementation project(':core')
|
||||
implementation project(':pixel')
|
||||
implementation "com.pixelgamelibrary:pixel:$pixelVersion"
|
||||
implementation project(':pixel-backend-libgdx')
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ dependencies {
|
||||
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.3"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.3"
|
||||
implementation project(':pixel')
|
||||
implementation "com.pixelgamelibrary:pixel:$pixelVersion"
|
||||
}
|
||||
|
||||
test {
|
||||
|
@ -1,31 +0,0 @@
|
||||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
||||
//eclipse.project.name = appName + '-core'
|
||||
eclipse.project.name = 'pixel'
|
||||
|
||||
sourceSets.test.java.srcDirs = [ "src/test/java/" ]
|
||||
|
||||
dependencies {
|
||||
api "com.badlogicgames.gdx-controllers:gdx-controllers-core:$gdxControllersVersion"
|
||||
api "com.badlogicgames.gdx:gdx-ai:$aiVersion"
|
||||
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
|
||||
api "com.badlogicgames.gdx:gdx:$gdxVersion"
|
||||
api "com.github.MrStahlfelge.gdx-websockets:core:$websocketVersion"
|
||||
api "com.github.MrStahlfelge.gdx-websockets:serialization:$websocketSerializationVersion"
|
||||
api "com.github.crykn.guacamole:core:$guacamoleVersion"
|
||||
api "com.github.crykn.guacamole:gdx:$guacamoleVersion"
|
||||
api "com.github.tommyettinger:formic:$formicVersion"
|
||||
api "com.github.tommyettinger:libgdx-utils-box2d:$utilsBox2dVersion"
|
||||
api "com.github.tommyettinger:libgdx-utils:$utilsVersion"
|
||||
api "de.golfgl.gdxcontrollerutils:gdx-controllerutils-mapping:$controllerMappingVersion"
|
||||
api "games.rednblack.miniaudio:miniaudio:$miniaudioVersion"
|
||||
//api "com.openeggbert.gdx:gdx-storage:0.0.0-SNAPSHOT"
|
||||
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
||||
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.3"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.3"
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform {
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public abstract class Game extends com.badlogic.gdx.Game {
|
||||
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.11.0//EN" "https://www.gwtproject.org/doctype/2.11.0/gwt-module.dtd">
|
||||
<module>
|
||||
<!-- Paths to source are relative to this file and separated by slashes ('/'). -->
|
||||
<source path="" />
|
||||
<!-- Reflection includes may be needed for your code or library code. Each value is separated by periods ('.'). -->
|
||||
<!-- You can include a full package by not including the name of a type at the end. -->
|
||||
|
||||
</module>
|
@ -1,99 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
|
||||
import com.pixelgamelibrary.api.AppI;
|
||||
import com.pixelgamelibrary.api.AssetI;
|
||||
import com.pixelgamelibrary.api.AudioI;
|
||||
import com.pixelgamelibrary.api.GraphicsI;
|
||||
import com.pixelgamelibrary.api.InputI;
|
||||
import com.pixelgamelibrary.api.NetI;
|
||||
import com.pixelgamelibrary.api.PixelBackend;
|
||||
import com.pixelgamelibrary.api.StorageI;
|
||||
import com.pixelgamelibrary.api.UtilsI;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class Pixel {
|
||||
|
||||
private static PixelBackend INSTANCE = null;
|
||||
|
||||
private Pixel() {
|
||||
//Not meant to be instantiated.
|
||||
}
|
||||
|
||||
private static PixelBackend get() {
|
||||
return getBackend();
|
||||
}
|
||||
|
||||
////
|
||||
public static AppI app() {
|
||||
return get().app();
|
||||
}
|
||||
|
||||
public static GraphicsI graphics() {
|
||||
return get().graphics();
|
||||
}
|
||||
|
||||
public static AudioI audio() {
|
||||
return get().audio();
|
||||
}
|
||||
|
||||
public static InputI input() {
|
||||
return get().input();
|
||||
}
|
||||
|
||||
public static NetI net() {
|
||||
return get().net();
|
||||
}
|
||||
|
||||
public static AssetI asset() {
|
||||
return get().asset();
|
||||
}
|
||||
|
||||
public static StorageI storage() {
|
||||
return get().storage();
|
||||
}
|
||||
|
||||
public static UtilsI utils() {
|
||||
return get().utils();
|
||||
}
|
||||
////
|
||||
|
||||
public static void initBackend(PixelBackend pixelBackend) {
|
||||
if (isBackendSet()) {
|
||||
throw new PixelException("Pixel Backend was already set");
|
||||
}
|
||||
INSTANCE = pixelBackend;
|
||||
}
|
||||
|
||||
private static PixelBackend getBackend() {
|
||||
if (!isBackendSet()) {
|
||||
throw new PixelException("Pixel Backend was not set");
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static boolean isBackendSet() {
|
||||
return INSTANCE != null;
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class PixelException extends RuntimeException{
|
||||
|
||||
public PixelException(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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;}
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public abstract class Screen extends com.badlogic.gdx.ScreenAdapter {
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class WindowMode {
|
||||
|
||||
private WindowMode() {
|
||||
//Not meant to be instantiated.
|
||||
}
|
||||
|
||||
public static final String WINDOW = "WINDOW";
|
||||
public static final String FULLSCREEN = "FULLSCREEN";
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 com.pixelgamelibrary.Platform;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface AppI {
|
||||
Platform getPlatform();
|
||||
|
||||
default boolean isOneOfPlatforms(Platform ... platforms) {
|
||||
for(Platform p: platforms) {
|
||||
if(getPlatform() == p) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void exit();
|
||||
void log(String msg);
|
||||
void error(String msg);
|
||||
void debug(String msg);
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 AssetI {
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 AudioI {
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 GraphicsI {
|
||||
boolean setToOriginalDisplayMode();
|
||||
String setDisplayMode(boolean fullscreen, boolean window);
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 InputI {
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 NetI {
|
||||
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 com.pixelgamelibrary.Platform;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface PixelBackend {
|
||||
|
||||
|
||||
|
||||
AppI app();
|
||||
GraphicsI graphics();
|
||||
AudioI audio();
|
||||
InputI input();
|
||||
NetI net();
|
||||
AssetI asset();
|
||||
StorageI storage();
|
||||
UtilsI utils();
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 com.pixelgamelibrary.storage.Storage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface StorageI {
|
||||
Storage getStorage();
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 com.badlogic.gdx.utils.Base64Coder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface UtilsI {
|
||||
XmlElement parseXml(String xmlString);
|
||||
default String decodeBase64AsString(String string) {
|
||||
return new String(decodeBase64AsByteArray(string));
|
||||
}
|
||||
|
||||
byte[] decodeBase64AsByteArray(String string);
|
||||
|
||||
default String encodeToBase64(String string) {
|
||||
return encodeToBase64(string.getBytes());
|
||||
}
|
||||
|
||||
String encodeToBase64(byte[] data);
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 XmlElement {
|
||||
XmlElement getChildByName(String name);
|
||||
String get(String elementName);
|
||||
int getChildCount();
|
||||
XmlElement getChild(int i);
|
||||
String getText();
|
||||
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.storage;
|
||||
|
||||
import com.pixelgamelibrary.Platform;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface Storage {
|
||||
|
||||
Platform getPlatform();
|
||||
|
||||
public String cd(String path);
|
||||
|
||||
default String cd() {
|
||||
cd("/");
|
||||
mkdir("home");
|
||||
cd("home");
|
||||
mkdir(uname());
|
||||
cd(uname());
|
||||
return "";
|
||||
}
|
||||
|
||||
public String mkdir(String argument);
|
||||
default String mkdirmore(String... argument) {
|
||||
// System.out.println("argumentCount=" + argument.length);
|
||||
// for(String z: argument){System.out.println(z);}
|
||||
if(argument.length == 0) {
|
||||
return "Missing argument";
|
||||
}
|
||||
for(String n:argument) {
|
||||
String result = mkdir(n);
|
||||
if(!result.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String pwd();
|
||||
|
||||
public List<String> ls(String workingDirectory);
|
||||
|
||||
default List<String> ls() {
|
||||
return ls(pwd());
|
||||
}
|
||||
|
||||
public int depth(String path);
|
||||
|
||||
default int depth() {
|
||||
return depth(pwd());
|
||||
}
|
||||
|
||||
public String touch(String name);
|
||||
|
||||
public boolean rm(String name);
|
||||
|
||||
public boolean rmdir(String dirname);
|
||||
|
||||
public String cp(String source, String target);
|
||||
|
||||
public String mv(String source, String target);
|
||||
|
||||
public String readtext(String name);
|
||||
|
||||
public byte[] readbin(String name);
|
||||
|
||||
public String savetext(String name, String text);
|
||||
|
||||
public String savebin(String name, byte[] data);
|
||||
|
||||
public boolean exists(String name);
|
||||
|
||||
public boolean isfile(String name);
|
||||
|
||||
public boolean isdir(String name);
|
||||
|
||||
public String debug();
|
||||
|
||||
public void flush();
|
||||
|
||||
default String uname() {return OPENEGGBERT;}
|
||||
static final String OPENEGGBERT = "openeggbert";
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.storage;
|
||||
|
||||
import com.pixelgamelibrary.PixelException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class StorageException extends PixelException {
|
||||
|
||||
public StorageException(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.storage.command;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class BaseCommand implements StorageCommand {
|
||||
|
||||
private StorageCommandLine storageCommandLine = null;
|
||||
private String name;
|
||||
private final Function<String, StorageCommandResult> function;
|
||||
|
||||
public BaseCommand(
|
||||
StorageCommandLine storageCommandLineIn, String nameIn, Function<String, StorageCommandResult> functionIn
|
||||
) {
|
||||
setStorageCommandLine(storageCommandLineIn);
|
||||
this.name = nameIn;
|
||||
this.function = functionIn;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setStorageCommandLine(StorageCommandLine storageCommandLineIn) {
|
||||
storageCommandLine = storageCommandLineIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final StorageCommandLine getStorageCommandLine() {
|
||||
return storageCommandLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageCommandResult execute(String commandWithArguments) {
|
||||
return function.apply(commandWithArguments);
|
||||
}
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.storage.command;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface CommandLineScanner {
|
||||
String nextLine();
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.storage.command;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface StorageCommand {
|
||||
|
||||
public String getName();
|
||||
|
||||
StorageCommandResult execute(String arguments);
|
||||
StorageCommandLine getStorageCommandLine();
|
||||
|
||||
void setStorageCommandLine(StorageCommandLine storageCommandLine);
|
||||
static StorageCommandResult emptyNewResult() {
|
||||
return new StorageCommandResult();
|
||||
}
|
||||
|
||||
}
|
@ -1,225 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.storage.command;
|
||||
|
||||
import com.pixelgamelibrary.storage.Storage;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class StorageCommandLine {
|
||||
|
||||
private String user;
|
||||
private String hostname;
|
||||
private Storage storage;
|
||||
//
|
||||
private boolean exited = false;
|
||||
//
|
||||
private long startNanoTime = System.nanoTime();
|
||||
|
||||
public String getCommandLineStart() {
|
||||
return user + "@" + hostname + ":" + storage.pwd() + "$ ";
|
||||
}
|
||||
|
||||
private String extractArgument(String arguments, int argumentIndex) {
|
||||
if(arguments.isEmpty()) {
|
||||
return arguments;
|
||||
}
|
||||
String[] array = arguments.split(" ");
|
||||
if (argumentIndex > (array.length)) {
|
||||
return "";
|
||||
}
|
||||
return array[argumentIndex + 1];
|
||||
}
|
||||
|
||||
public StorageCommandLine(String userIn, String hostnameIn, Storage storageIn) {
|
||||
|
||||
this.user = userIn;
|
||||
this.hostname = hostnameIn;
|
||||
this.storage = storageIn;
|
||||
|
||||
addCommand("date", arguments -> provideOutput(result -> result.setOutput(new Date().toString())));
|
||||
addCommand("whoami", arguments -> provideOutput(result -> result.setOutput(user)));
|
||||
addCommand("uptime", arguments -> provideOutput(result
|
||||
-> result.setOutput(
|
||||
new Date().toString().substring(11, 19) + " up "
|
||||
+ (System.nanoTime() - startNanoTime) / 1000000000l / 60l
|
||||
+ " minutes"
|
||||
+ ", 1 user"
|
||||
)));
|
||||
|
||||
addCommand("hostname", arguments -> provideOutput(result -> result.setOutput(hostname)));
|
||||
addCommand("test", arguments-> provideOutput(result-> result.setOutput((extractArgument(arguments, 0)))));
|
||||
addCommand("uname", arguments -> provideOutput(result -> result.setOutput(
|
||||
"LinuxBashCommandLinePartialEmulation"
|
||||
+ ((extractArgument(arguments, 0).equals("-a"))
|
||||
? (hostname + " 0.0.0 ("
|
||||
+ new Date().toString() + ")")
|
||||
: "")
|
||||
)));
|
||||
|
||||
addCommand("ls", arguments -> provideOutput(result -> result.setOutput(storage
|
||||
.ls()
|
||||
.stream()
|
||||
.map(l -> {
|
||||
String[] a = l.split("/");
|
||||
return a[a.length - 1];
|
||||
}
|
||||
).collect(Collectors.joining("\n")))));
|
||||
|
||||
addCommand("pwd", arguments -> provideOutput(result -> result.setOutput(storage.pwd())));
|
||||
addCommand("depth", arguments -> provideOutput(result -> result.setOutput(storage.depth())));
|
||||
|
||||
addCommand("mkdir", arguments -> provideOutput(result
|
||||
-> {
|
||||
String string = storage.mkdirmore(extractArguments(arguments));
|
||||
if (string.isEmpty()) {
|
||||
result.setOutput("New directory was successfully created");
|
||||
|
||||
} else {
|
||||
result.setErrorOutput("Creating new directory failed: " + string);
|
||||
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
commands.keySet().stream().map(k -> commands.get(k)).forEach(c -> c.setStorageCommandLine(this));
|
||||
}
|
||||
|
||||
private String[] extractArguments(String arguments) {
|
||||
return Arrays.asList(arguments.split(" ")).stream()
|
||||
.filter(a->!a.isEmpty())
|
||||
.toArray(String[]::new);
|
||||
}
|
||||
|
||||
private StorageCommandResult provideOutput(Consumer<StorageCommandResult> consumer) {
|
||||
|
||||
StorageCommandResult result = StorageCommand.emptyNewResult();
|
||||
consumer.accept(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void addCommand(String nameIn, Function<String, StorageCommandResult> functionIn) {
|
||||
StorageCommand storageCommand = new BaseCommand(this, nameIn, functionIn);
|
||||
commands.put(storageCommand.getName(), storageCommand);
|
||||
}
|
||||
|
||||
private final Map<String, StorageCommand> commands = new HashMap<>();
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public Storage getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public boolean isExited() {
|
||||
return exited;
|
||||
}
|
||||
|
||||
public StorageCommandResult execute(String commandWithArguments) {
|
||||
|
||||
String[] arguments = commandWithArguments.split(" ");
|
||||
String command = arguments.length == 0 ? "" : arguments[0];
|
||||
|
||||
StorageCommand storageCommand = commands.get(command);
|
||||
if (storageCommand != null) {
|
||||
return storageCommand.execute(commandWithArguments.substring(command.length()));
|
||||
}
|
||||
|
||||
int argumentCount = arguments.length - 1;
|
||||
//System.out.println("argumentCount=" + argumentCount);
|
||||
Optional<String> argument1 = Optional.ofNullable(argumentCount >= 1 ? arguments[1] : null);
|
||||
Optional<String> argument2 = Optional.ofNullable(argumentCount >= 2 ? arguments[2] : null);
|
||||
|
||||
StorageCommandResult finalResult = new StorageCommandResult();
|
||||
switch (command) {
|
||||
|
||||
case "touch":
|
||||
|
||||
String r = storage.touch(argument1.get());
|
||||
if (r.isEmpty()) {
|
||||
finalResult.setOutput("New file was successfully created");
|
||||
} else {
|
||||
finalResult.setErrorOutput("Creating new directory failed: " + r);
|
||||
}
|
||||
|
||||
break;
|
||||
case "readtext":
|
||||
|
||||
String rr = storage.readtext(argument1.get());
|
||||
if (rr != null) {
|
||||
finalResult.setOutput("Text file was successfully loaded" + "\n\n" + rr);
|
||||
} else {
|
||||
finalResult.setErrorOutput("Loading text file failed:");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "savetext":
|
||||
|
||||
String result = storage.savetext(argument1.get(), argument2.get());
|
||||
if (result.isEmpty()) {
|
||||
finalResult.setOutput("Text file was successfully saved");
|
||||
} else {
|
||||
finalResult.setErrorOutput("Saving text file failed: " + result);
|
||||
}
|
||||
|
||||
break;
|
||||
case "cd":
|
||||
String rrr = argument1.isEmpty() ? storage.cd() : storage.cd(argument1.get());
|
||||
if (rrr.isEmpty()) {
|
||||
finalResult.setOutput("Changing working directory was successfully created");
|
||||
} else {
|
||||
finalResult.setErrorOutput("Changing working directory failed: " + rrr);
|
||||
}
|
||||
|
||||
break;
|
||||
case "debug":
|
||||
finalResult.setOutput(storage.debug());
|
||||
|
||||
break;
|
||||
|
||||
case "exit":
|
||||
exited = true;
|
||||
finalResult.setOutput("Exited");
|
||||
break;
|
||||
default: {
|
||||
finalResult.setErrorOutput("Unsupported command: " + command);
|
||||
}
|
||||
}
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.storage.command;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class StorageCommandLineScanner {
|
||||
|
||||
public StorageCommandLineScanner(StorageCommandLine storageCommandLine, CommandLineScanner scanner) {
|
||||
|
||||
while (true) {
|
||||
System.out.print(storageCommandLine.getCommandLineStart());
|
||||
String argument = scanner.nextLine();
|
||||
|
||||
StorageCommandResult result = storageCommandLine.execute(argument);
|
||||
if (result.isError()) {
|
||||
printError(result.getOutput());
|
||||
} else {
|
||||
print(result.getOutput());
|
||||
|
||||
}
|
||||
if (storageCommandLine.isExited()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void print(String msg) {
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
private static void printError(String msg) {
|
||||
System.err.println(msg);
|
||||
}
|
||||
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.storage.command;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class StorageCommandResult {
|
||||
|
||||
public StorageCommandResult() {
|
||||
this("");
|
||||
}
|
||||
|
||||
public StorageCommandResult(String output) {
|
||||
this(output, false);
|
||||
}
|
||||
|
||||
public StorageCommandResult(String output, boolean error) {
|
||||
this.output = output;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public String getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
public boolean isError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setOutput(int output) {
|
||||
setOutput(String.valueOf(output));
|
||||
}
|
||||
|
||||
public void setErrorOutput(String output) {
|
||||
this.output = output;
|
||||
setError(true);
|
||||
}
|
||||
|
||||
public void setOutput(String output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public void setError(boolean error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
private String output;
|
||||
private boolean error;
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.storage.map;
|
||||
|
||||
import com.pixelgamelibrary.storage.StorageException;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public enum MapFileType {
|
||||
FILE, DIRECTORY;
|
||||
|
||||
public static MapFileType ofKey(String key, SimpleMap map) {
|
||||
if (!map.contains(key)) {
|
||||
throw new StorageException("Map does not contain key: " + key);
|
||||
}
|
||||
String value = map.getString(key);
|
||||
if (value.startsWith(FILE.name())) {
|
||||
return FILE;
|
||||
}
|
||||
if (value.startsWith(DIRECTORY.name())) {
|
||||
return DIRECTORY;
|
||||
}
|
||||
throw new StorageException("Unsupported MapFileType for key in the map: " + key);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,344 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.storage.map;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.pixelgamelibrary.Pixel;
|
||||
import com.pixelgamelibrary.Platform;
|
||||
import com.pixelgamelibrary.storage.StorageException;
|
||||
import com.pixelgamelibrary.storage.Storage;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class MapStorage implements Storage {
|
||||
|
||||
private final SimpleMap map;
|
||||
|
||||
private final MapStorageCompression mapStorageCompression;
|
||||
public MapStorage(SimpleMap mapIn) {
|
||||
this(mapIn, MapStorageCompression.NONE);
|
||||
}
|
||||
public MapStorage(SimpleMap mapIn, MapStorageCompression mapStorageCompressionIn) {
|
||||
this.map = mapIn;
|
||||
this.mapStorageCompression = mapStorageCompressionIn;
|
||||
mkdir("/");
|
||||
|
||||
}
|
||||
|
||||
private String workingDirectory = "/";
|
||||
|
||||
@Override
|
||||
public Platform getPlatform() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String convertToAbsolutePathIfNeeded(String path) {
|
||||
if (path.startsWith(SLASH)) {
|
||||
return path;
|
||||
}
|
||||
|
||||
return workingDirectory + (workingDirectory.equals("/") ? "" : SLASH) + path;
|
||||
}
|
||||
|
||||
private static final String TWO_DOTS = "..";
|
||||
|
||||
@Override
|
||||
public String cd(String path) {
|
||||
// System.out.println("path="+path);
|
||||
String absolutePath = path.equals(TWO_DOTS) ? getParentPath(workingDirectory) : convertToAbsolutePathIfNeeded(path);
|
||||
|
||||
if (!exists(absolutePath)) {
|
||||
final String msg = "Path does not exist: " + absolutePath;
|
||||
logError(msg);
|
||||
return msg;
|
||||
}
|
||||
if (!isdir(absolutePath)) {
|
||||
final String msg = "Path is not directory: " + absolutePath;
|
||||
logError(msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
workingDirectory = absolutePath;
|
||||
return "";
|
||||
}
|
||||
private static final String SLASH = "/";
|
||||
|
||||
@Override
|
||||
public String mkdir(String path) {
|
||||
if(path.isEmpty()) {
|
||||
String msg = "Missing argument";
|
||||
logError(msg);
|
||||
return msg;
|
||||
}
|
||||
String absolutePath = convertToAbsolutePathIfNeeded(path);
|
||||
final String parentPath = getParentPath(absolutePath);
|
||||
if (!path.equals(SLASH) && !exists(parentPath)) {
|
||||
var msg = "Cannot create new directory, because parent path does not exist: " + parentPath;
|
||||
logError(msg);
|
||||
return msg;
|
||||
}
|
||||
if (!path.equals(SLASH) && !isdir(parentPath)) {
|
||||
var msg = "Cannot create new directory, because parent path is not directory: " + parentPath;
|
||||
logError(msg);
|
||||
return msg;
|
||||
}
|
||||
if (exists(absolutePath)) {
|
||||
var msg = "Cannot create new directory, because path already exists: " + absolutePath;
|
||||
logError(msg);
|
||||
return msg;
|
||||
}
|
||||
map.putString(absolutePath, MapFileType.DIRECTORY + EIGHT_COLONS);
|
||||
|
||||
return "";
|
||||
|
||||
}
|
||||
private static final String EIGHT_COLONS = "::::::::";
|
||||
|
||||
private static String getParentPath(String path) {
|
||||
// System.out.println("getParentPath()");
|
||||
if (path == null) {
|
||||
throw new StorageException("Path is null");
|
||||
}
|
||||
if (path.trim().isEmpty()) {
|
||||
throw new StorageException("Path is empty");
|
||||
}
|
||||
|
||||
if (path.equals("/")) {
|
||||
return path;
|
||||
}
|
||||
String[] array = path.split(SLASH);
|
||||
if (array.length == 2) {
|
||||
return SLASH;
|
||||
}
|
||||
return path.substring(0, path.length() - 1 - array[array.length - 1].length());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String pwd() {
|
||||
return workingDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int depth(String path) {
|
||||
String absolutePath = convertToAbsolutePathIfNeeded(path);
|
||||
if (absolutePath.equals(SLASH)) {
|
||||
return 0;
|
||||
}
|
||||
String[] array = absolutePath.split(SLASH);
|
||||
return array.length -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> ls(String path) {
|
||||
int currentDepth = depth(path);
|
||||
return map
|
||||
.keyList()
|
||||
.stream()
|
||||
.filter(key -> key.startsWith(workingDirectory))
|
||||
.filter(key -> depth(key) == (currentDepth + 1))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String touch(String path) {
|
||||
return touch(path, "");
|
||||
}
|
||||
|
||||
public String touch(String path, String content) {
|
||||
String absolutePath = convertToAbsolutePathIfNeeded(path);
|
||||
final String parentPath = getParentPath(absolutePath);
|
||||
if (!exists(parentPath)) {
|
||||
var msg = "Cannot create new file, because parent path does not exist: " + parentPath;
|
||||
logError(msg);
|
||||
return msg;
|
||||
}
|
||||
if (!isdir(parentPath)) {
|
||||
var msg = "Cannot create new file, because parent path is not directory: " + parentPath;
|
||||
logError(msg);
|
||||
return msg;
|
||||
}
|
||||
if (exists(absolutePath)) {
|
||||
var msg = "Cannot create new file, because path already exists: " + absolutePath;
|
||||
logError(msg);
|
||||
return msg;
|
||||
}
|
||||
map.putString(absolutePath, MapFileType.FILE + EIGHT_COLONS + content);
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rm(String path) {
|
||||
String absolutePath = convertToAbsolutePathIfNeeded(path);
|
||||
|
||||
if (!map.contains(absolutePath)) {
|
||||
logError("Cannot remove file, because it does not exist: " + absolutePath);
|
||||
return false;
|
||||
}
|
||||
map.remove(absolutePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String cp(String source, String target) {
|
||||
return moveOrCp(source, target, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mv(String source, String target) {
|
||||
return moveOrCp(source, target, true, false);
|
||||
}
|
||||
|
||||
private String moveOrCp(String source, String target, boolean move, boolean cp) {
|
||||
if (move && cp) {
|
||||
throw new StorageException("move == true && cp == true");
|
||||
}
|
||||
if (!move && !cp) {
|
||||
throw new StorageException("move != true && cp != true");
|
||||
}
|
||||
String absolutePathSource = convertToAbsolutePathIfNeeded(source);
|
||||
String absolutePathTarget = convertToAbsolutePathIfNeeded(target);
|
||||
String targetParentPath = getParentPath(absolutePathTarget);
|
||||
|
||||
if (!exists(absolutePathSource)) {
|
||||
final String msg = "absolutePathSource does not exist: " + absolutePathSource;
|
||||
logError(msg);
|
||||
return msg;
|
||||
}
|
||||
if (isdir(absolutePathSource)) {
|
||||
final String msg = "absolutePathSource is directory: " + absolutePathSource;
|
||||
logError(msg);
|
||||
return msg;
|
||||
}
|
||||
if (!exists(targetParentPath)) {
|
||||
final String msg = "targetParentPath does not exist: " + absolutePathSource;
|
||||
logError(msg);
|
||||
return msg;
|
||||
}
|
||||
if (!isdir(targetParentPath)) {
|
||||
final String msg = "targetParentPath is not directory: " + absolutePathSource;
|
||||
logError(msg);
|
||||
return msg;
|
||||
}
|
||||
String contentOfSourceFile = map.getString(absolutePathSource);
|
||||
String result = touch(absolutePathTarget);
|
||||
if (!result.isEmpty()) {
|
||||
var msg = "Creating new file failed: " + absolutePathTarget;
|
||||
logError(msg);
|
||||
return msg;
|
||||
}
|
||||
map.remove(absolutePathTarget);
|
||||
map.putString(absolutePathTarget, contentOfSourceFile);
|
||||
if (move) {
|
||||
map.remove(absolutePathSource);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readtext(String path) {
|
||||
String absolutePath = convertToAbsolutePathIfNeeded(path);
|
||||
if (!exists(absolutePath)) {
|
||||
logError("absolutePathSource does not exist: " + absolutePath);
|
||||
return null;
|
||||
}
|
||||
if (isdir(absolutePath)) {
|
||||
logError("absolutePathSource is directory: " + absolutePath);
|
||||
return null;
|
||||
}
|
||||
String value = map.getString(absolutePath);
|
||||
return value.split(EIGHT_COLONS)[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] readbin(String path) {
|
||||
String absolutePath = convertToAbsolutePathIfNeeded(path);
|
||||
|
||||
String text = readtext(absolutePath);
|
||||
if (!text.startsWith(BINARYFILE)) {
|
||||
logError("File is not binary:" + absolutePath);
|
||||
return null;
|
||||
}
|
||||
text = text.substring(BINARYFILE.length());
|
||||
return Pixel.utils().decodeBase64AsByteArray(text);
|
||||
}
|
||||
private static final String BINARYFILE = "BINARYFILE";
|
||||
|
||||
@Override
|
||||
public String savetext(String name, String text) {
|
||||
return touch(name, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String savebin(String name, byte[] data) {
|
||||
return savetext(name, BINARYFILE + Pixel.utils().encodeToBase64(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(String name) {
|
||||
return map.contains(convertToAbsolutePathIfNeeded(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isfile(String name) {
|
||||
return filetype(name) == MapFileType.FILE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isdir(String name) {
|
||||
return filetype(name) == MapFileType.DIRECTORY;
|
||||
}
|
||||
|
||||
public MapFileType filetype(String name) {
|
||||
return MapFileType.ofKey(convertToAbsolutePathIfNeeded(name), map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String debug() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(String key: map.keyList()) {
|
||||
sb
|
||||
.append(key)
|
||||
.append("=")
|
||||
.append(map.getString(key))
|
||||
.append("\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
map.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rmdir(String dirname) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
private void logError(String msg) {
|
||||
Pixel.app().error(msg);
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.storage.map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public enum MapStorageCompression {
|
||||
NONE;
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.storage.map;
|
||||
|
||||
import com.pixelgamelibrary.Platform;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class MemoryStorage extends MapStorage {
|
||||
|
||||
@Override
|
||||
public Platform getPlatform() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public MemoryStorage() {
|
||||
super(new SimpleJavaMap());
|
||||
}
|
||||
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.storage.map;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class SimpleJavaMap implements SimpleMap {
|
||||
|
||||
private final Map<String, String> map;
|
||||
|
||||
public SimpleJavaMap() {
|
||||
this(new HashMap<>());
|
||||
}
|
||||
public SimpleJavaMap(Map<String, String> mapIn) {
|
||||
this.map = mapIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putString(String key, String val) {
|
||||
map.put(key, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(Map<String, String> map) {
|
||||
for (String key : map.keySet()) {
|
||||
putString(key, map.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String key, String defaultValue) {
|
||||
return contains(key) ? getString(key) : defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getReadOnlyMap() {
|
||||
return Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(String key) {
|
||||
return map.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(String key) {
|
||||
map.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
//nothing to do
|
||||
}
|
||||
@Override
|
||||
public List<String> keyList() {
|
||||
return map.keySet().stream().collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.storage.map;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public interface SimpleMap {
|
||||
|
||||
public void putString(String key, String val);
|
||||
|
||||
public void put(Map<String, String> map);
|
||||
|
||||
public String getString(String key);
|
||||
|
||||
public String getString(String key, String defaultValue);
|
||||
|
||||
public Map<String, String> getReadOnlyMap();
|
||||
|
||||
public boolean contains(String key);
|
||||
|
||||
public void clear();
|
||||
|
||||
public void remove(String key);
|
||||
|
||||
public void flush();
|
||||
|
||||
public List<String> keyList();
|
||||
}
|
@ -1 +0,0 @@
|
||||
|
@ -1,4 +1,4 @@
|
||||
// A list of which subprojects to load as part of the same larger project.
|
||||
// You can remove Strings from the list and reload the Gradle project
|
||||
// if you want to temporarily disable a subproject.
|
||||
include 'lwjgl3', 'android', 'html', 'core', 'pixel', 'pixel-backend-libgdx'
|
||||
include 'lwjgl3', 'android', 'html', 'core', 'pixel-backend-libgdx'
|
||||
|
Reference in New Issue
Block a user