Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealEmissions committed Mar 21, 2024
1 parent 442f96a commit 5e9e98b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: uk.ac.york.student.DesktopLauncher

3 changes: 3 additions & 0 deletions core/resources/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: uk.ac.york.student.DesktopLauncher

3 changes: 3 additions & 0 deletions core/src/uk/ac/york/student/GdxGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
import org.jetbrains.annotations.NotNull;
import uk.ac.york.student.assets.map.MapManager;
import uk.ac.york.student.audio.AudioManager;
import uk.ac.york.student.audio.music.MusicManager;
import uk.ac.york.student.audio.sound.SoundManager;
Expand Down Expand Up @@ -45,6 +46,8 @@ public void create() {
final AudioManager soundManager = SoundManager.getInstance();
soundManager.onEnable();

MapManager.onEnable();

// Set the initial screen to the loading screen
setScreen(Screens.LOADING);
}
Expand Down
17 changes: 9 additions & 8 deletions core/src/uk/ac/york/student/assets/map/MapManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.ac.york.student.assets.map;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
Expand All @@ -9,6 +10,7 @@
import uk.ac.york.student.utils.MapOfSuppliers;

import java.io.File;
import java.util.List;
import java.util.Objects;

Check warning on line 14 in core/src/uk/ac/york/student/assets/map/MapManager.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import java.util.Objects;`

/**
Expand All @@ -25,24 +27,23 @@ public final class MapManager {
@Getter
private static final MapOfSuppliers<String, TiledMap> maps = new MapOfSuppliers<>();

// Static initializer block that loads the maps from the "map" directory in the internal "assets" directory
static {
// Get the directory containing the map files
File mapFiles = Gdx.files.internal("map").file();
// Throw an exception if the directory does not exist
if (!mapFiles.isDirectory()) throw new RuntimeException("map directory not found");
public static void onEnable() {

List<String> maps = List.of("map", "blankMap", "inside_house");
// Create parameters for loading the maps
TmxMapLoader.Parameters parameter = new TmxMapLoader.Parameters();
parameter.textureMinFilter = Texture.TextureFilter.Nearest;
parameter.textureMagFilter = Texture.TextureFilter.Nearest;

// Load each map file in the directory (and hide the potential NullPointerException with Objects.requireNonNull)
for (File file : Objects.requireNonNull(mapFiles.listFiles())) {
for (String map : maps) {
map = "map/" + map + ".tmx";
FileHandle internal = Gdx.files.internal(map);
File file = internal.file();
// Only load files with the ".tmx" extension
if (file.getName().endsWith(".tmx")) {
// Add the map to the MapOfSuppliers, using a lambda to allow for lazy loading
maps.put(file.getName().replace(".tmx", ""), () -> new TmxMapLoader().load("map/" + file.getName(), parameter));
MapManager.maps.put(file.getName().replace(".tmx", ""), () -> new TmxMapLoader().load("map/" + file.getName(), parameter));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions core/src/uk/ac/york/student/screens/MainMenuScreen.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.ac.york.student.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;

Check warning on line 4 in core/src/uk/ac/york/student/screens/MainMenuScreen.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import com.badlogic.gdx.files.FileHandle;`
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
Expand Down

0 comments on commit 5e9e98b

Please sign in to comment.