From f48b8c837db34878b1ce500dc1f3dd0cf162a97c Mon Sep 17 00:00:00 2001 From: sowgro Date: Tue, 1 Oct 2024 23:55:55 -0400 Subject: Improve Splash screen --- src/main/java/net/sowgro/npehero/levelapi/Levels.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/main/java/net/sowgro/npehero/levelapi/Levels.java') diff --git a/src/main/java/net/sowgro/npehero/levelapi/Levels.java b/src/main/java/net/sowgro/npehero/levelapi/Levels.java index f4cdc1d..7a89ed1 100755 --- a/src/main/java/net/sowgro/npehero/levelapi/Levels.java +++ b/src/main/java/net/sowgro/npehero/levelapi/Levels.java @@ -18,6 +18,14 @@ import net.sowgro.npehero.Driver; */ public class Levels { + public interface MessageUpdaterLambda { + void updateMessage(String message); + } + + public interface ProgressUpdaterLambda { + void updateProgress(double workDone, double progress); + } + public static final ObservableList list = FXCollections.observableArrayList(); public static final HashMap problems = new HashMap<>(); @@ -31,18 +39,26 @@ public class Levels { * @throws IOException If there is a problem reading in the levels. */ public static void readData() throws IOException { + readData(_ -> {}, (_, _) -> {}); + } + public static void readData(MessageUpdaterLambda mu, ProgressUpdaterLambda pu) throws IOException { list.clear(); File[] fileList = dir.listFiles(); if (fileList == null) { throw new FileNotFoundException(); } + int i = 0; + int max = fileList.length; for (File file: fileList) { try { Level level = new Level(file); list.add(level); + i++; + mu.updateMessage("Loaded " + i + " Levels"); } catch (Exception e) { problems.put("Failed to load load level in folder '" + file.getName() + "'", e); } + pu.updateProgress(i, max); } list.sort(Comparator.naturalOrder()); } -- cgit v1.2.3