Start work on json exporter
This commit is contained in:
parent
92741698f4
commit
f33f98690d
5 changed files with 195 additions and 6 deletions
|
@ -19,6 +19,7 @@ import net.minecraftforge.fml.common.registry.GameData;
|
|||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import reborncore.api.fuel.FluidPowerManager;
|
||||
import reborncore.api.recipe.RecipeHandler;
|
||||
import techreborn.dev.JsonGenerator;
|
||||
|
||||
public class TechRebornDevCommand extends CommandBase
|
||||
{
|
||||
|
@ -103,6 +104,8 @@ public class TechRebornDevCommand extends CommandBase
|
|||
} else {
|
||||
((EntityPlayer) sender).addChatComponentMessage(new TextComponentString("hold an item!"));
|
||||
}
|
||||
} else if ("gen".equals(args[0])) { //TODO DO NOT SHIP!!!
|
||||
new JsonGenerator().generate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
73
src/main/java/techreborn/dev/JsonGenerator.java
Normal file
73
src/main/java/techreborn/dev/JsonGenerator.java
Normal file
|
@ -0,0 +1,73 @@
|
|||
package techreborn.dev;
|
||||
|
||||
import reborncore.RebornCore;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Created by Mark on 24/04/2016.
|
||||
*/
|
||||
|
||||
//TODO DO NOT SHIP THIS!
|
||||
public class JsonGenerator {
|
||||
|
||||
public void generate(){
|
||||
File mcDir = new File(".");
|
||||
File exportFolder = new File(mcDir, "export");
|
||||
if(!exportFolder.exists()){
|
||||
exportFolder.mkdir();
|
||||
}
|
||||
File assetsFolder = new File(exportFolder, "assets");
|
||||
if(!assetsFolder.exists()){
|
||||
assetsFolder.mkdir();
|
||||
}
|
||||
File modFolder = new File(assetsFolder, "techreborn");
|
||||
if(!modFolder.exists()){
|
||||
modFolder.mkdir();
|
||||
}
|
||||
File blockstates = new File(modFolder, "blockstates");
|
||||
if(!blockstates.exists()){
|
||||
blockstates.mkdir();
|
||||
}
|
||||
File models = new File(modFolder, "models");
|
||||
if(!models.exists()){
|
||||
models.mkdir();
|
||||
}
|
||||
File blockModels = new File(models, "block");
|
||||
if(!blockModels.exists()){
|
||||
blockModels.mkdir();
|
||||
}
|
||||
File itemModles = new File(models, "item");
|
||||
if(!itemModles.exists()){
|
||||
itemModles.mkdir();
|
||||
}
|
||||
for(Object object : RebornCore.jsonDestroyer.objectsToDestroy){
|
||||
if(object instanceof BlockMachineBase){
|
||||
BlockMachineBase base = (BlockMachineBase) object;
|
||||
File state = new File(blockstates, base.getUnlocalizedName() + ".json");
|
||||
if(state.exists()){
|
||||
state.delete();
|
||||
}
|
||||
try {
|
||||
state.createNewFile();
|
||||
FileOutputStream is = new FileOutputStream(state);
|
||||
OutputStreamWriter osw = new OutputStreamWriter(is);
|
||||
Writer w = new BufferedWriter(osw);
|
||||
w.write("{");
|
||||
w.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -14,6 +14,7 @@ import techreborn.init.ModBlocks;
|
|||
import techreborn.init.ModItems;
|
||||
import techreborn.items.ItemParts;
|
||||
import techreborn.items.ItemPlates;
|
||||
import techreborn.manual.loader.ManualLoader;
|
||||
import techreborn.manual.pages.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -33,7 +34,8 @@ public class GuiManual extends GuiScreen
|
|||
{
|
||||
this.xSize = 200;
|
||||
this.ySize = 180;
|
||||
root = createRoot();
|
||||
// root = createRoot();
|
||||
root = ManualLoader.getPages();
|
||||
}
|
||||
|
||||
protected PageCollection createRoot()
|
||||
|
|
|
@ -3,13 +3,19 @@ package techreborn.manual.loader;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.compress.archivers.zip.ZipFile;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import reborncore.common.util.Unzip;
|
||||
import techreborn.manual.PageCollection;
|
||||
import techreborn.manual.Reference;
|
||||
import techreborn.manual.loader.pages.CategoriesPage;
|
||||
import techreborn.manual.pages.ContentsPage;
|
||||
import techreborn.manual.saveFormat.ManualFormat;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
@ -25,6 +31,8 @@ public class ManualLoader {
|
|||
|
||||
File configDir;
|
||||
|
||||
public static ManualFormat format;
|
||||
|
||||
public ManualLoader(File configDir) {
|
||||
this.configDir = configDir;
|
||||
}
|
||||
|
@ -59,28 +67,43 @@ public class ManualLoader {
|
|||
}
|
||||
|
||||
if(downloadablePackageInfo != null){
|
||||
boolean hasIntactZip = false;
|
||||
File zipLocation = new File(manualdir, downloadablePackageInfo.fileName);
|
||||
if(zipLocation.exists()){
|
||||
String md5 = getMD5(zipLocation);
|
||||
if(md5.equals(downloadablePackageInfo.md5)){
|
||||
//Oh look we allready have it!
|
||||
hasIntactZip = true;
|
||||
}
|
||||
} else {
|
||||
FileUtils.copyURLToFile(new URL("http://modmuss50.me/techreborn/manual/packages/" + downloadablePackageInfo.fileName), zipLocation);
|
||||
String md5 = getMD5(zipLocation);
|
||||
if(md5.equals(downloadablePackageInfo.md5)){
|
||||
//ok the downloaded file is valid
|
||||
hasIntactZip = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ZipFile file = new ZipFile(zipLocation);
|
||||
// file.
|
||||
if(hasIntactZip){
|
||||
File outputDir = new File(manualdir, zipLocation.getName().replace(".zip", ""));
|
||||
Unzip.unzip(zipLocation, outputDir);
|
||||
File inputData = new File(outputDir, "master.json");
|
||||
BufferedReader reader = new BufferedReader(new FileReader(inputData));
|
||||
ManualLoader.format = gson.fromJson(reader, ManualFormat.class);
|
||||
System.out.println(ManualLoader.format);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static PageCollection getPages(){
|
||||
final PageCollection pageCollection = new PageCollection();
|
||||
pageCollection.addPage(new CategoriesPage(Reference.pageNames.CONTENTS_PAGE, pageCollection));
|
||||
|
||||
return pageCollection;
|
||||
}
|
||||
|
||||
|
||||
public static String getMD5(File file) throws IOException {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
String md5 = DigestUtils.md5Hex(fis);
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
package techreborn.manual.loader.pages;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.init.ModItems;
|
||||
import techreborn.items.ItemPlates;
|
||||
import techreborn.manual.PageCollection;
|
||||
import techreborn.manual.Reference;
|
||||
import techreborn.manual.loader.ManualLoader;
|
||||
import techreborn.manual.pages.TitledPage;
|
||||
import techreborn.manual.saveFormat.Entry;
|
||||
import techreborn.manual.saveFormat.ManualFormat;
|
||||
import techreborn.manual.util.GuiButtonItemTexture;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by Mark on 23/04/2016.
|
||||
*/
|
||||
public class CategoriesPage extends TitledPage
|
||||
{
|
||||
|
||||
|
||||
public CategoriesPage(String name, PageCollection collection)
|
||||
{
|
||||
super(name, false, collection, Reference.CONTENTS_KEY, Color.white.getRGB());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
buttonList.clear();
|
||||
ArrayList<String> categories = new ArrayList<>();
|
||||
for(Entry entry : ManualLoader.format.entries){
|
||||
if(categories.contains(entry.category)){
|
||||
categories.add(entry.category);
|
||||
}
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for(String string : categories){
|
||||
buttonList.add(new GuiButtonItemTexture(i, getXMin() + 20, getYMin() + 20 + (i * 20), 0, 46, 100, 20,
|
||||
ItemPlates.getPlateByName("iron"), string,
|
||||
ttl(Reference.GETTINGSTARTED_KEY)));
|
||||
}
|
||||
//
|
||||
//
|
||||
// buttonList.add(new GuiButtonItemTexture(0, getXMin() + 20, getYMin() + 20, 0, 46, 100, 20,
|
||||
// ItemPlates.getPlateByName("iron"), Reference.pageNames.GETTINGSTARTED_PAGE,
|
||||
// ttl(Reference.GETTINGSTARTED_KEY)));
|
||||
// buttonList.add(new GuiButtonItemTexture(1, getXMin() + 20, getYMin() + 40, 0, 46, 100, 20,
|
||||
// new ItemStack(ModBlocks.Generator), Reference.pageNames.GENERATINGPOWER_PAGE,
|
||||
// ttl(Reference.GENERATINGPOWER_KEY)));
|
||||
// buttonList.add(new GuiButtonItemTexture(2, getXMin() + 20, getYMin() + 60, 0, 46, 100, 20,
|
||||
// new ItemStack(ModBlocks.ElectricFurnace), Reference.pageNames.BASICMACHINES_PAGE,
|
||||
// ttl(Reference.BASICMACHINES_KEY)));
|
||||
// buttonList.add(new GuiButtonItemTexture(3, getXMin() + 20, getYMin() + 80, 0, 46, 100, 20,
|
||||
// new ItemStack(ModBlocks.BlastFurnace), Reference.pageNames.ADVANCEDMACHINES_PAGE,
|
||||
// ttl(Reference.ADVANCEDMACHINES_KEY)));
|
||||
// buttonList.add(new GuiButtonItemTexture(4, getXMin() + 20, getYMin() + 100, 0, 46, 100, 20,
|
||||
// new ItemStack(ModItems.ironDrill), Reference.pageNames.TOOLS_PAGE, ttl(Reference.TOOLS_KEY)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBackgroundLayer(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY)
|
||||
{
|
||||
super.renderBackgroundLayer(minecraft, offsetX, offsetY, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button)
|
||||
{
|
||||
// if (button.id == 0)
|
||||
// collection.changeActivePage(Reference.pageNames.GETTINGSTARTED_PAGE);
|
||||
// if (button.id == 1)
|
||||
// collection.changeActivePage(Reference.pageNames.GENERATINGPOWER_PAGE);
|
||||
// if (button.id == 2)
|
||||
// collection.changeActivePage(Reference.pageNames.BASICMACHINES_PAGE);
|
||||
// if (button.id == 3)
|
||||
// collection.changeActivePage(Reference.pageNames.ADVANCEDMACHINES_PAGE);
|
||||
// if (button.id == 4)
|
||||
// collection.changeActivePage(Reference.pageNames.TOOLS_PAGE);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue