mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-22 02:07:26 +07:00
Created BinGenerator to generate bin files from tsv txt files via their Excel schemas
This commit is contained in:
parent
05b37637bb
commit
ff3d807de7
44
core/src/main/java/com/riiablo/excel2/BinGenerator.java
Normal file
44
core/src/main/java/com/riiablo/excel2/BinGenerator.java
Normal 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()));
|
||||
}
|
||||
}
|
31
core/src/test/java/com/riiablo/excel2/BinGeneratorTest.java
Normal file
31
core/src/test/java/com/riiablo/excel2/BinGeneratorTest.java
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user