Added storage classes - work in progress IV
This commit is contained in:
parent
2e9a1efd23
commit
c4f577a701
@ -56,7 +56,7 @@ configure(subprojects - project(':android')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
version = '1.0.0'
|
version = '0.0.0-SNAPSHOT'
|
||||||
ext.appName = 'open-eggbert'
|
ext.appName = 'open-eggbert'
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
@ -17,6 +17,7 @@ dependencies {
|
|||||||
api "com.github.tommyettinger:libgdx-utils:$utilsVersion"
|
api "com.github.tommyettinger:libgdx-utils:$utilsVersion"
|
||||||
api "de.golfgl.gdxcontrollerutils:gdx-controllerutils-mapping:$controllerMappingVersion"
|
api "de.golfgl.gdxcontrollerutils:gdx-controllerutils-mapping:$controllerMappingVersion"
|
||||||
api "games.rednblack.miniaudio:miniaudio:$miniaudioVersion"
|
api "games.rednblack.miniaudio:miniaudio:$miniaudioVersion"
|
||||||
|
api "com.openeggbert.gdx:gdx-storage:0.0.0-SNAPSHOT"
|
||||||
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
||||||
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
||||||
testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.3"
|
testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.3"
|
||||||
@ -26,4 +27,4 @@ dependencies {
|
|||||||
test {
|
test {
|
||||||
useJUnitPlatform {
|
useJUnitPlatform {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
// <https://www.gnu.org/licenses/> or write to the Free Software
|
// <https://www.gnu.org/licenses/> or write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.openeggbert.lwjgl3.debugging.storage;
|
package com.openeggbert.storage.filesystem.command;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
@ -0,0 +1,29 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Open Eggbert: Free recreation of the computer game Speedy Eggbert.
|
||||||
|
// Copyright (C) 2024 the original author or authors.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License
|
||||||
|
// as published by the Free Software Foundation, either version 3
|
||||||
|
// of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see
|
||||||
|
// <https://www.gnu.org/licenses/> or write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
package com.openeggbert.storage.filesystem.command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author robertvokac
|
||||||
|
*/
|
||||||
|
public interface CommandLineScanner {
|
||||||
|
String nextLine();
|
||||||
|
|
||||||
|
}
|
@ -17,7 +17,7 @@
|
|||||||
// <https://www.gnu.org/licenses/> or write to the Free Software
|
// <https://www.gnu.org/licenses/> or write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.openeggbert.lwjgl3.debugging.storage;
|
package com.openeggbert.storage.filesystem.command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
@ -17,13 +17,12 @@
|
|||||||
// <https://www.gnu.org/licenses/> or write to the Free Software
|
// <https://www.gnu.org/licenses/> or write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.openeggbert.lwjgl3.debugging.storage;
|
package com.openeggbert.storage.filesystem.command;
|
||||||
|
|
||||||
import com.openeggbert.storage.Storage;
|
import com.openeggbert.storage.Storage;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@ -49,11 +48,14 @@ public class StorageCommandLine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String extractArgument(String arguments, int argumentIndex) {
|
private String extractArgument(String arguments, int argumentIndex) {
|
||||||
|
if(arguments.isEmpty()) {
|
||||||
|
return arguments;
|
||||||
|
}
|
||||||
String[] array = arguments.split(" ");
|
String[] array = arguments.split(" ");
|
||||||
if (argumentIndex > (array.length - 1)) {
|
if (argumentIndex > (array.length)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return array[argumentIndex];
|
return array[argumentIndex + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageCommandLine(String userIn, String hostnameIn, Storage storageIn) {
|
public StorageCommandLine(String userIn, String hostnameIn, Storage storageIn) {
|
||||||
@ -62,21 +64,23 @@ public class StorageCommandLine {
|
|||||||
this.hostname = hostnameIn;
|
this.hostname = hostnameIn;
|
||||||
this.storage = storageIn;
|
this.storage = storageIn;
|
||||||
|
|
||||||
|
addCommand("date", arguments -> provideOutput(result -> result.setOutput(new Date().toString())));
|
||||||
addCommand("whoami", arguments -> provideOutput(result -> result.setOutput(user)));
|
addCommand("whoami", arguments -> provideOutput(result -> result.setOutput(user)));
|
||||||
addCommand("uptime", arguments -> provideOutput(result
|
addCommand("uptime", arguments -> provideOutput(result
|
||||||
-> result.setOutput(
|
-> result.setOutput(
|
||||||
LocalDateTime.now().toString().replace("T", " ").substring(10, 19) + " up "
|
new Date().toString().substring(11, 19) + " up "
|
||||||
+ (System.nanoTime() - startNanoTime) / 1000000000l / 60l
|
+ (System.nanoTime() - startNanoTime) / 1000000000l / 60l
|
||||||
+ " minutes"
|
+ " minutes"
|
||||||
+ ", 1 user"
|
+ ", 1 user"
|
||||||
)));
|
)));
|
||||||
|
|
||||||
addCommand("hostname", arguments -> provideOutput(result -> result.setOutput(hostname)));
|
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(
|
addCommand("uname", arguments -> provideOutput(result -> result.setOutput(
|
||||||
"LinuxBashCommandLinePartialEmulation"
|
"LinuxBashCommandLinePartialEmulation"
|
||||||
+ ((extractArgument(arguments, 0).equals("-a"))
|
+ ((extractArgument(arguments, 0).equals("-a"))
|
||||||
? (hostname + " 0.0.0 ("
|
? (hostname + " 0.0.0 ("
|
||||||
+ LocalDateTime.now().toString().replace("T", " ").substring(0, 10) + ")")
|
+ new Date().toString() + ")")
|
||||||
: "")
|
: "")
|
||||||
)));
|
)));
|
||||||
|
|
@ -17,7 +17,7 @@
|
|||||||
// <https://www.gnu.org/licenses/> or write to the Free Software
|
// <https://www.gnu.org/licenses/> or write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.openeggbert.lwjgl3.debugging.storage;
|
package com.openeggbert.storage.filesystem.command;
|
||||||
|
|
||||||
import com.openeggbert.storage.map.MemoryStorage;
|
import com.openeggbert.storage.map.MemoryStorage;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
@ -28,17 +28,7 @@ import java.util.Scanner;
|
|||||||
*/
|
*/
|
||||||
public class StorageCommandLineScanner {
|
public class StorageCommandLineScanner {
|
||||||
|
|
||||||
private StorageCommandLineScanner() {
|
public StorageCommandLineScanner(StorageCommandLine storageCommandLine, CommandLineScanner scanner) {
|
||||||
//Not meant to be instantiated.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
MemoryStorage memoryStorage = new MemoryStorage();
|
|
||||||
final String user = "player";
|
|
||||||
final String hostname = "openegggbert";
|
|
||||||
|
|
||||||
StorageCommandLine storageCommandLine = new StorageCommandLine(user, hostname, memoryStorage);
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
System.out.print(storageCommandLine.getCommandLineStart());
|
System.out.print(storageCommandLine.getCommandLineStart());
|
@ -17,7 +17,7 @@
|
|||||||
// <https://www.gnu.org/licenses/> or write to the Free Software
|
// <https://www.gnu.org/licenses/> or write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.openeggbert.lwjgl3.debugging.storage;
|
package com.openeggbert.storage.filesystem.command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
@ -65,7 +65,7 @@ public class MapStorage implements Storage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String cd(String path) {
|
public String cd(String path) {
|
||||||
System.out.println("path="+path);
|
// System.out.println("path="+path);
|
||||||
String absolutePath = path.equals(TWO_DOTS) ? getParentPath(workingDirectory) : convertToAbsolutePathIfNeeded(path);
|
String absolutePath = path.equals(TWO_DOTS) ? getParentPath(workingDirectory) : convertToAbsolutePathIfNeeded(path);
|
||||||
|
|
||||||
if (!exists(absolutePath)) {
|
if (!exists(absolutePath)) {
|
||||||
@ -122,7 +122,7 @@ public class MapStorage implements Storage {
|
|||||||
private static final String EIGHT_COLONS = "::::::::";
|
private static final String EIGHT_COLONS = "::::::::";
|
||||||
|
|
||||||
private static String getParentPath(String path) {
|
private static String getParentPath(String path) {
|
||||||
System.out.println("getParentPath()");
|
// System.out.println("getParentPath()");
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
throw new OpenEggbertException("Path is null");
|
throw new OpenEggbertException("Path is null");
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Open Eggbert: Free recreation of the computer game Speedy Eggbert.
|
||||||
|
// Copyright (C) 2024 the original author or authors.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License
|
||||||
|
// as published by the Free Software Foundation, either version 3
|
||||||
|
// of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see
|
||||||
|
// <https://www.gnu.org/licenses/> or write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
package com.openeggbert.lwjgl3.debugging.storage;
|
||||||
|
|
||||||
|
import com.openeggbert.storage.filesystem.command.CommandLineScanner;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author robertvokac
|
||||||
|
*/
|
||||||
|
public class DesktopCommandLineScanner implements CommandLineScanner {
|
||||||
|
|
||||||
|
private final Scanner scanner;
|
||||||
|
|
||||||
|
public DesktopCommandLineScanner() {
|
||||||
|
this.scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String nextLine() {
|
||||||
|
return scanner.nextLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Open Eggbert: Free recreation of the computer game Speedy Eggbert.
|
||||||
|
// Copyright (C) 2024 the original author or authors.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License
|
||||||
|
// as published by the Free Software Foundation, either version 3
|
||||||
|
// of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see
|
||||||
|
// <https://www.gnu.org/licenses/> or write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
package com.openeggbert.lwjgl3.debugging.storage;
|
||||||
|
|
||||||
|
import com.openeggbert.storage.filesystem.command.StorageCommandLine;
|
||||||
|
import com.openeggbert.storage.filesystem.command.StorageCommandLineScanner;
|
||||||
|
import com.openeggbert.storage.map.MemoryStorage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author robertvokac
|
||||||
|
*/
|
||||||
|
public class DesktopStorageCommandLineScanner {
|
||||||
|
|
||||||
|
private DesktopStorageCommandLineScanner() {
|
||||||
|
//Not meant to be instantiated.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
MemoryStorage memoryStorage = new MemoryStorage();
|
||||||
|
final String user = "player";
|
||||||
|
final String hostname = "openegggbert";
|
||||||
|
StorageCommandLine storageCommandLine = new StorageCommandLine(user, hostname, memoryStorage);
|
||||||
|
StorageCommandLineScanner storageCommandLineScanner = new StorageCommandLineScanner(
|
||||||
|
storageCommandLine, new DesktopCommandLineScanner());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user