Created BinGenerator to generate bin files from tsv txt files via their Excel schemas

This commit is contained in:
Collin Smith 2020-12-12 17:40:54 -08:00
parent 05b37637bb
commit ff3d807de7
2 changed files with 75 additions and 0 deletions

View File

@ -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 <E extends Excel.Entry, S extends Serializer<E>, T extends Excel<E, S>>
void generateBin(T excel) {
final Class<? extends Excel> 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()));
}
}

View File

@ -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);
}
}