Added new class AssetsTxt
This commit is contained in:
parent
dd7b6a3493
commit
b35987c7c2
156
core/src/main/java/com/openeggbert/main/AssetsTxt.java
Normal file
156
core/src/main/java/com/openeggbert/main/AssetsTxt.java
Normal file
@ -0,0 +1,156 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.main;
|
||||
|
||||
import com.openeggbert.entity.common.OpenEggbertException;
|
||||
import com.openeggbert.utils.OpenEggbertUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class AssetsTxt {
|
||||
|
||||
|
||||
private final List<List<String>> filesLists = new ArrayList<>();
|
||||
private final List<List<String>> directoriesLists = new ArrayList<>();
|
||||
|
||||
private final Set<String> directoriesSet = new HashSet<>();
|
||||
|
||||
public AssetsTxt(String readString) {
|
||||
OpenEggbertUtils.lines(readString).forEach(line -> {
|
||||
var lineArray = Arrays.asList(line.split("/"));
|
||||
filesLists.add(lineArray);
|
||||
if (lineArray.size() > 1) {
|
||||
String fileName = lineArray.get(lineArray.size() - 1);
|
||||
String directory = line.substring(0, line.length() - 1 - fileName.length());
|
||||
if (!directoriesSet.contains(directory)) {
|
||||
directoriesSet.add(directory);
|
||||
directoriesLists.add(Arrays.asList(directory.split("/")));
|
||||
}
|
||||
}
|
||||
});
|
||||
//directories: without files, with only directories
|
||||
Set<String> subDirectoriesTmpSet = new HashSet<>();
|
||||
for (String dir : directoriesSet) {
|
||||
List<String> list = Arrays.asList(dir.split("/"));
|
||||
int depth = list.size();
|
||||
|
||||
while (depth > 1) {
|
||||
depth = depth - 1;
|
||||
String aSubdirectory = list.stream().limit(depth).collect(Collectors.joining("/"));
|
||||
if (!directoriesSet.contains(aSubdirectory)) {
|
||||
subDirectoriesTmpSet.add(aSubdirectory);
|
||||
directoriesLists.add(Arrays.asList(aSubdirectory.split("/")));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
directoriesSet.addAll(subDirectoriesTmpSet);
|
||||
|
||||
}
|
||||
|
||||
public void listDirectories() {
|
||||
directoriesLists.forEach(l -> System.out.println(convertListStringToStringPath(l)));
|
||||
}
|
||||
|
||||
public void listFiles() {
|
||||
filesLists.forEach(l -> System.out.println(convertListStringToStringPath(l)));
|
||||
}
|
||||
|
||||
public List<String> listRoot(boolean directoryType, boolean fileType) {
|
||||
return list(".", directoryType, fileType);
|
||||
}
|
||||
|
||||
public List<String> listRoot() {
|
||||
return listRoot(true, true);
|
||||
}
|
||||
|
||||
public List<String> list(String pathToDirectory) {
|
||||
return list(pathToDirectory, true, true);
|
||||
}
|
||||
|
||||
public List<String> listDirectories(String pathToDirectory) {
|
||||
return list(pathToDirectory, true, false);
|
||||
}
|
||||
|
||||
public List<String> listFiles(String pathToDirectory) {
|
||||
return list(pathToDirectory, false, true);
|
||||
}
|
||||
|
||||
public List<String> list(String pathToDirectory, boolean directoryType, boolean fileType) {
|
||||
if (!directoryType && !fileType) {
|
||||
throw new OpenEggbertException("Invalid arguments, both arguments are false: directoryType, fileType");
|
||||
}
|
||||
|
||||
if (pathToDirectory.equals(".")) {
|
||||
List<String> files = fileType ? filesLists
|
||||
.stream()
|
||||
.filter(l -> l.size() == 1)
|
||||
.map(l -> l.get(0))
|
||||
.collect(Collectors.toList()) : new ArrayList<>();
|
||||
List<String> directories = directoryType ? directoriesLists
|
||||
.stream()
|
||||
.filter(l -> l.size() == 1)
|
||||
.map(l -> l.get(0))
|
||||
.collect(Collectors.toList()) : new ArrayList<>();
|
||||
List<String> result = new ArrayList<>();
|
||||
result.addAll(files);
|
||||
result.addAll(directories);
|
||||
return result;
|
||||
}
|
||||
if (!directoriesSet.contains(pathToDirectory)) {
|
||||
throw new OpenEggbertException("There is no such directory in assets: " + pathToDirectory);
|
||||
}
|
||||
|
||||
var directoryArray = pathToDirectory.split("/");
|
||||
int depth = directoryArray.length;
|
||||
|
||||
List<String> files = fileType ? filesLists
|
||||
.stream()
|
||||
.filter(l -> l.size() == depth + 1)
|
||||
.filter(l -> convertListStringToStringPath(l).startsWith(pathToDirectory))
|
||||
.map(l -> l.get(depth))
|
||||
.collect(Collectors.toList()) : new ArrayList<>();
|
||||
List<String> directories = directoryType ? directoriesLists
|
||||
.stream()
|
||||
.filter(l -> l.size() == depth + 1)
|
||||
.filter(l -> convertListStringToStringPath(l).startsWith(pathToDirectory))
|
||||
.map(l -> l.get(depth))
|
||||
.distinct()
|
||||
.collect(Collectors.toList()) : new ArrayList<>();
|
||||
List<String> result = new ArrayList<>();
|
||||
result.addAll(files);
|
||||
result.addAll(directories);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private static String convertListStringToStringPath(List<String> list) {
|
||||
return list.stream().collect(Collectors.joining("/"));
|
||||
}
|
||||
|
||||
}
|
@ -22,12 +22,16 @@ package com.openeggbert.main;
|
||||
import com.badlogic.gdx.Game;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Camera;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||
import com.openeggbert.entity.common.GameSpace;
|
||||
import com.openeggbert.mods.Mod;
|
||||
import com.openeggbert.screens.GameSpaceListScreen;
|
||||
@ -55,6 +59,9 @@ public class OpenEggbertGame extends Game {
|
||||
private List<Mod> embeddedMods = new ArrayList<>();
|
||||
private int heightInPixels = 480;
|
||||
private int widthInPixels = 640;
|
||||
private Camera camera;
|
||||
private Viewport viewport;
|
||||
private AssetsTxt assetsTxt;
|
||||
|
||||
public OpenEggbertGame() {
|
||||
this(null, null);
|
||||
@ -72,8 +79,18 @@ public class OpenEggbertGame extends Game {
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
// viewport = new FitViewport(640,480);
|
||||
// viewport.apply();
|
||||
//camera = new OrthographicCamera();
|
||||
|
||||
//.setToOrtho(false,640,480);
|
||||
|
||||
assetsTxt = new AssetsTxt(Gdx.files.internal("assets.txt").readString());
|
||||
System.out.println("Searching mods");
|
||||
|
||||
for(FileHandle f:Gdx.files.internal(".").list()) {
|
||||
System.out.println("assets contains also: " + f.name());
|
||||
}
|
||||
FileHandle embeddedModsDirectory = Gdx.files.internal("embedded_mods");
|
||||
System.out.println("embeddedModsDirectory.list().length=" + embeddedModsDirectory.list().length);
|
||||
for (FileHandle embeddedModGroup : embeddedModsDirectory.list()) {
|
||||
@ -107,6 +124,7 @@ public class OpenEggbertGame extends Game {
|
||||
}
|
||||
////
|
||||
batch = new SpriteBatch();
|
||||
//batch.setProjectionMatrix(viewport.getCamera().combined);
|
||||
image = new Texture("libgdx.png");
|
||||
shapeRenderer = new ShapeRenderer();
|
||||
font = new BitmapFont();
|
||||
|
@ -55,7 +55,7 @@ public class GameSpaceListScreen extends AbstractOpenEggbertScreen {
|
||||
this.fullEmbeddedMods = openEggbertGame.getEmbeddedMods().stream().filter(m -> m.getModType() == ModType.FULL).collect(Collectors.toList());
|
||||
Gdx.app.log("fullEmbeddedMods: ", String.valueOf(fullEmbeddedMods.size()));
|
||||
Gdx.app.log("openEggbertGame.getEmbeddedMods(): ", String.valueOf(openEggbertGame.getEmbeddedMods().size()));
|
||||
|
||||
|
||||
if (Gdx.app.getType() == Application.ApplicationType.Android) {
|
||||
game.setHeightInPixels(Gdx.app.getGraphics().getHeight());
|
||||
game.setWidthInPixels(Gdx.app.getGraphics().getWidth());
|
||||
@ -70,6 +70,10 @@ public class GameSpaceListScreen extends AbstractOpenEggbertScreen {
|
||||
if (keyCode == Input.Keys.SPACE) {
|
||||
game.setScreen(new TestScreen(game));
|
||||
}
|
||||
if (keyCode == Input.Keys.ESCAPE) {
|
||||
Gdx.app.exit();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -89,7 +93,7 @@ public class GameSpaceListScreen extends AbstractOpenEggbertScreen {
|
||||
if(
|
||||
x > fourArray[i].x && x < (fourArray[i].x + fourArray[i].width)
|
||||
&&
|
||||
y > fourArray[i].y && y < (fourArray[i].y + fourArray[i].height)
|
||||
y > fourArray[4-i].y && y < (fourArray[4-i].y + fourArray[4-i].height)
|
||||
) {
|
||||
System.out.println("button " + i);
|
||||
}
|
||||
@ -102,7 +106,10 @@ public class GameSpaceListScreen extends AbstractOpenEggbertScreen {
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
|
||||
ScreenUtils.clear(1f, 1f, 0.6f, 0.5f);
|
||||
int buttonHeight = (int) (game.getHeightInPixels() * 0.1f);
|
||||
|
||||
batch.begin();
|
||||
|
||||
BitmapFont font;
|
||||
@ -128,7 +135,6 @@ public class GameSpaceListScreen extends AbstractOpenEggbertScreen {
|
||||
|
||||
final boolean isLastPage = !(pageNumber * pageSize < fullEmbeddedMods.size());
|
||||
|
||||
int buttonHeight = (int) (game.getHeightInPixels() * 0.1f);
|
||||
final ShapeRenderer shapeRenderer = game.getShapeRenderer();
|
||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
|
||||
shapeRenderer.setColor(1f, 1f, 0.8f, 0.5f);
|
||||
|
@ -80,6 +80,7 @@ public class TestScreen extends AbstractOpenEggbertScreen {
|
||||
font = new BitmapFont();
|
||||
font.draw(game.getBatch(), game.getCurrentDirectory(), 40, 340);
|
||||
}
|
||||
batch.draw(game.getImage(), 40, 400);
|
||||
game.getBatch().end();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,37 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class OpenEggbertUtils {
|
||||
private OpenEggbertUtils() {
|
||||
//Not meant to be instantiated.
|
||||
}
|
||||
public static Stream<String> lines(String string) {
|
||||
return Arrays.asList(string.split("\\r?\\n")).stream();
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user