diff --git a/core/src/main/java/com/riiablo/excel2/BinGenerator.java b/core/src/main/java/com/riiablo/excel2/BinGenerator.java new file mode 100644 index 00000000..b3c9d56a --- /dev/null +++ b/core/src/main/java/com/riiablo/excel2/BinGenerator.java @@ -0,0 +1,44 @@ +package com.riiablo.excel2; + +import io.netty.buffer.ByteBufUtil; +import io.netty.buffer.Unpooled; + +import com.badlogic.gdx.files.FileHandle; + +import com.riiablo.io.ByteOutput; +import com.riiablo.logger.LogManager; +import com.riiablo.logger.Logger; + +public class BinGenerator { + private static final Logger log = LogManager.getLogger(BinGenerator.class); + + String sourcePackage = "com.riiablo.excel2.txt"; + String excelPath = "DATA\\GLOBAL\\EXCEL2".toLowerCase(); // string will be defined elsewhere in caps + FileHandle binDir; + + public void generateBins() { + log.info("Generating bins for {}...", sourcePackage); + + } + + public , T extends Excel> + void generateBin(T excel) { + final Class excelClass = excel.excelClass(); + log.trace("excel: {}", excelClass.getCanonicalName()); + + FileHandle excelDir = binDir.child(excelPath); + log.trace("excelDir: {}", excelDir); + excelDir.mkdirs(); + + FileHandle binFile = excelDir.child(excelClass.getSimpleName() + "." + "bin"); + log.trace("binFile: {}", binFile); + + ByteOutput out = ByteOutput.wrap(Unpooled.buffer()); + S serializer = excel.newSerializer(); + for (E entry : excel) { + serializer.writeBin(entry, out); + } + + log.trace("\n{}", ByteBufUtil.prettyHexDump(out.buffer())); + } +} diff --git a/core/src/test/java/com/riiablo/excel2/BinGeneratorTest.java b/core/src/test/java/com/riiablo/excel2/BinGeneratorTest.java new file mode 100644 index 00000000..e47bba45 --- /dev/null +++ b/core/src/test/java/com/riiablo/excel2/BinGeneratorTest.java @@ -0,0 +1,31 @@ +package com.riiablo.excel2; + +import java.io.IOException; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.files.FileHandle; + +import com.riiablo.RiiabloTest; +import com.riiablo.excel2.txt.MonStats; +import com.riiablo.logger.Level; +import com.riiablo.logger.LogManager; + +public class BinGeneratorTest extends RiiabloTest { + @BeforeClass + public static void before() { + LogManager.setLevel("com.riiablo.excel2.BinGenerator", Level.TRACE); + } + + @Test + public void monstats() throws IOException { + FileHandle handle = Gdx.files.internal("test/monstats.txt"); + Excel monstats = Excel.loadTxt(new MonStats(), handle); + + BinGenerator generator = new BinGenerator(); + generator.binDir = Gdx.files.absolute( + "C:\\Users\\csmith\\projects\\libgdx\\riiablo\\assets"); + generator.generateBin(monstats); + } +}