Ore config now uses HJSon, its easier for humans to read and I have included a converter

This commit is contained in:
modmuss50 2016-04-16 08:58:17 +01:00
parent cdee0ddc06
commit 3abfc3cb13
No known key found for this signature in database
GPG key ID: 1838986A0F12E8EE
2 changed files with 35 additions and 10 deletions

View file

@ -76,6 +76,7 @@ public class Core
config = ConfigTechReborn.initialize(new File(configDir, "main.cfg")); config = ConfigTechReborn.initialize(new File(configDir, "main.cfg"));
worldGen = new TechRebornWorldGen(); worldGen = new TechRebornWorldGen();
worldGen.configFile = (new File(configDir, "ores.json")); worldGen.configFile = (new File(configDir, "ores.json"));
worldGen.hConfigFile = (new File(configDir, "ores.hjson"));
recipeCompact = new RecipeCompact(); recipeCompact = new RecipeCompact();
TechRebornAPI.recipeCompact = recipeCompact; TechRebornAPI.recipeCompact = recipeCompact;

View file

@ -1,10 +1,6 @@
package techreborn.world; package techreborn.world;
import java.io.BufferedReader; import java.io.*;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -18,6 +14,8 @@ import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable; import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.fml.common.IWorldGenerator; import net.minecraftforge.fml.common.IWorldGenerator;
import org.hjson.JsonValue;
import org.hjson.Stringify;
import reborncore.common.misc.ChunkCoord; import reborncore.common.misc.ChunkCoord;
import techreborn.Core; import techreborn.Core;
import techreborn.init.ModBlocks; import techreborn.init.ModBlocks;
@ -37,6 +35,7 @@ public class TechRebornWorldGen implements IWorldGenerator
public static RubberTreeGenerator treeGenerator = new RubberTreeGenerator(); public static RubberTreeGenerator treeGenerator = new RubberTreeGenerator();
public final TechRebornRetroGen retroGen = new TechRebornRetroGen(); public final TechRebornRetroGen retroGen = new TechRebornRetroGen();
public File configFile; public File configFile;
public File hConfigFile;
public boolean jsonInvalid = false; public boolean jsonInvalid = false;
WorldGenConfig config; WorldGenConfig config;
WorldGenConfig defaultConfig; WorldGenConfig defaultConfig;
@ -75,7 +74,30 @@ public class TechRebornWorldGen implements IWorldGenerator
public void load() public void load()
{ {
init(); init();
if (configFile.exists()) //Converts the old format to the new one
if(configFile.exists()){
if(!hConfigFile.exists()){
try {
//Reads json
BufferedReader reader = new BufferedReader(new FileReader(configFile));
//Converts to hjson
String hJson = JsonValue.readHjson(reader).toString(Stringify.HJSON);
//Saves as the new HJson file
FileWriter writer = new FileWriter(hConfigFile);
writer.write(hJson);
writer.close();
reader.close();
//Delete old json file
configFile.delete();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (hConfigFile.exists())
{ {
loadFromJson(); loadFromJson();
} else } else
@ -119,11 +141,12 @@ public class TechRebornWorldGen implements IWorldGenerator
try try
{ {
Gson gson = new Gson(); Gson gson = new Gson();
BufferedReader reader = new BufferedReader(new FileReader(configFile)); BufferedReader reader = new BufferedReader(new FileReader(hConfigFile));
String jsonString = JsonValue.readHjson(reader).toString();
Type typeOfHashMap = new TypeToken<WorldGenConfig>() Type typeOfHashMap = new TypeToken<WorldGenConfig>()
{ {
}.getType(); }.getType();
config = gson.fromJson(reader, typeOfHashMap); config = gson.fromJson(jsonString, typeOfHashMap);
} catch (Exception e) } catch (Exception e)
{ {
Core.logHelper.error( Core.logHelper.error(
@ -140,10 +163,11 @@ public class TechRebornWorldGen implements IWorldGenerator
{ {
Gson gson = new GsonBuilder().setPrettyPrinting().create(); Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(config); String json = gson.toJson(config);
String hJson = JsonValue.readHjson(json).toString(Stringify.HJSON);
try try
{ {
FileWriter writer = new FileWriter(configFile); FileWriter writer = new FileWriter(hConfigFile);
writer.write(json); writer.write(hJson);
writer.close(); writer.close();
} catch (IOException e) } catch (IOException e)
{ {