From 8c45dda66cf5f37066f02c22ceb36509d0ac35c2 Mon Sep 17 00:00:00 2001 From: syeyoung <42869671+cyoung06@users.noreply.github.com> Date: Tue, 24 Nov 2020 16:15:00 +0900 Subject: save and edit generic roomdata --- .../roomfinder/DungeonRoomInfoRegistry.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder') diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java index a382273c..d9df6a8d 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java @@ -2,6 +2,7 @@ package kr.syeyoung.dungeonsguide.dungeon.roomfinder; import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoomInfo; +import java.io.*; import java.util.*; public class DungeonRoomInfoRegistry { @@ -38,4 +39,34 @@ public class DungeonRoomInfoRegistry { shapeMap.get(dungeonRoomInfo.getShape()).remove(dungeonRoomInfo); uuidMap.remove(dungeonRoomInfo.getUuid()); } + + public static void saveAll(File dir) { + dir.mkdirs(); + for (DungeonRoomInfo dungeonRoomInfo : registered) { + try { + FileOutputStream fos = new FileOutputStream(new File(dir, dungeonRoomInfo.getUuid().toString() + ".roomdata")); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(dungeonRoomInfo); + oos.flush(); + oos.close(); + } catch (Exception e) {e.printStackTrace();} + } + } + + public static void loadAll(File dir) { + registered.clear(); + shapeMap.clear(); + uuidMap.clear(); + for (File f: dir.listFiles()) { + if (!f.isFile() || !f.getName().endsWith(".roomdata")) continue; + try { + FileInputStream fis = new FileInputStream(f); + ObjectInputStream ois = new ObjectInputStream(fis); + DungeonRoomInfo dri = (DungeonRoomInfo) ois.readObject(); + ois.close(); + fis.close(); + register(dri); + } catch (Exception e) {e.printStackTrace();} + } + } } -- cgit