From 69809df4c361347da5acfaba6fe913cf43c933db Mon Sep 17 00:00:00 2001 From: StevenRS11 <stevenrs11@aol.com> Date: Tue, 5 Nov 2013 00:36:38 -0500 Subject: [PATCH] Added versioning to savedata --- .../mod_pocketDim/saving/DDSaveHandler.java | 28 +++++++++++++++++++ .../saving/DimDataProcessor.java | 28 ++++++++----------- .../mod_pocketDim/saving/PackedDimData.java | 2 ++ 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java b/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java index 445996cf..2fe9d3a7 100644 --- a/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java +++ b/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java @@ -47,10 +47,38 @@ public class DDSaveHandler for (File dataFile : dataFiles) { PackedDimData packedDim = readDimension(dataFile, reader); + //packedDims.add(packedDim); + } + return unpackDimData(packedDims); + } + + /** + * Takes a list of packedDimData and rebuilds the DimData for it, as well as registering all of + * them and their links. + * @param packedDims + * @return + */ + private static boolean unpackDimData(List<PackedDimData> packedDims) + { + List<PackedDimData> unpackedDims = new ArrayList<PackedDimData>(); + + while(!packedDims.isEmpty()) + { + //Load roots + for(PackedDimData packedDim : packedDims) + { + if(packedDim.ParentID==packedDim.ID) + { + + } + } + + packedDims.removeAll(unpackedDims); } return true; } + private static PackedDimData readDimension(File dataFile, DimDataProcessor reader) { try diff --git a/StevenDimDoors/mod_pocketDim/saving/DimDataProcessor.java b/StevenDimDoors/mod_pocketDim/saving/DimDataProcessor.java index ae82feb1..cca6ad33 100644 --- a/StevenDimDoors/mod_pocketDim/saving/DimDataProcessor.java +++ b/StevenDimDoors/mod_pocketDim/saving/DimDataProcessor.java @@ -27,20 +27,6 @@ import StevenDimDoors.mod_pocketDim.util.Point4D; public class DimDataProcessor extends BaseConfigurationProcessor<PackedDimData> { - private static final String dimID = "DIM_ID"; - private static final String depth = "DEPTH"; - private static final String children = "CHILDREN_DIM_IDS"; - private static final String linkTails = "LINK_TAILS"; - private static final String filled = "IS_FILLED"; - private static final String isDungeon = "IS_DUNGEON"; - private static final String orientation = "ORIENTATION"; - private static final String parentID = "PARENT_DIM_ID"; - private static final String rootID = "ROOT_DIM_ID"; - private static final String packDepth = "PACK_DEPTH"; - private static final String links = "LINKS"; - private static final String origin = "ORIGIN_POINT"; - - @Override public PackedDimData readFromStream(InputStream inputStream) throws ConfigurationProcessingException @@ -50,12 +36,11 @@ public class DimDataProcessor extends BaseConfigurationProcessor<PackedDimData> JsonReader reader = new JsonReader(new InputStreamReader(inputStream, "UTF-8")); PackedDimData data = this.createDImDataFromJson(reader); return data; - } catch (IOException e) { e.printStackTrace(); - throw new ConfigurationProcessingException(); + throw new ConfigurationProcessingException("Could not read packedDimData"); } } @@ -109,6 +94,12 @@ public class DimDataProcessor extends BaseConfigurationProcessor<PackedDimData> reader.beginObject(); + reader.nextName(); + if(reader.nextLong()!=PackedDimData.SAVE_DATA_VERSION_ID) + { + throw new IOException("Save data version mismatch"); + } + reader.nextName(); ID = reader.nextInt(); @@ -246,7 +237,10 @@ public class DimDataProcessor extends BaseConfigurationProcessor<PackedDimData> return new PackedLinkData(source, parent, tail, orientation, children); } - + private PackedDungeonData createDungeonDataFromJson(JsonReader reader) throws IOException + { + return null; + } private PackedLinkTail createLinkTailFromJson(JsonReader reader) throws IOException { Point4D destination=null; diff --git a/StevenDimDoors/mod_pocketDim/saving/PackedDimData.java b/StevenDimDoors/mod_pocketDim/saving/PackedDimData.java index 38af8f18..0719ae3b 100644 --- a/StevenDimDoors/mod_pocketDim/saving/PackedDimData.java +++ b/StevenDimDoors/mod_pocketDim/saving/PackedDimData.java @@ -7,6 +7,8 @@ import StevenDimDoors.mod_pocketDim.Point3D; public class PackedDimData { // These fields will be public since this is a simple data container + public final static long SAVE_DATA_VERSION_ID = 982405775L; + public final long SAVE_DATA_VERSION_ID_INSTANCE = SAVE_DATA_VERSION_ID; public final int ID; public final boolean IsDungeon; public final boolean IsFilled;