summaryrefslogtreecommitdiffstats
path: root/src/MapLoader.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/MapLoader.java')
-rw-r--r--src/MapLoader.java69
1 files changed, 0 insertions, 69 deletions
diff --git a/src/MapLoader.java b/src/MapLoader.java
deleted file mode 100644
index 4bd4e02..0000000
--- a/src/MapLoader.java
+++ /dev/null
@@ -1,69 +0,0 @@
-import java.lang.String;
-
-// TODO: use java.nio? http://tutorials.jenkov.com/java-nio/nio-vs-io.html
-import java.io.File;
-import java.io.PrintWriter;
-import java.io.FileReader;
-import java.io.BufferedReader;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-
-import java.awt.Dimension;
-
-import com.google.gson.Gson;
-
-// TODO: this class loads AND saves classes, refractor name
-class MapLoader {
- File path;
-
- public MapLoader(Object path) {
- if (path instanceof java.io.File) {
- this.path = (File) path;
- } else {
- this.path = new File((String) path);
- }
- }
-
- public Map getMap() {
- String mapText = "";
- String line = null;
- FileReader fr = null;
- BufferedReader bf = null;
-
- try {
- fr = new FileReader(this.path);
- bf = new BufferedReader(fr);
- // TODO: read all at once
- while ((line = bf.readLine()) != null) {
- mapText = mapText + line;
- }
- bf.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
-
- Gson gson = new Gson();
- Map importMap = gson.fromJson(mapText, Map.class);
-
- // TODO: ask @mafaldo why is there a copy?
- // update map with new classes
- // Map map = new Map(new Dimension(importMap.getSize(), importMap.getSize()));
- // map.update(importMap.getActors(), importMap.getGrid());
- // return map;
-
- return importMap;
- }
-
- public void saveMap(Map map) {
- Gson gson = new Gson();
- String mapText = gson.toJson(map);
- PrintWriter out = null;
- try {
- out = new PrintWriter(this.path + ".json");
- } catch (FileNotFoundException ex) {
- ex.printStackTrace();
- }
- out.println(mapText);
- out.close();
- }
-}