diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index cf0cff29..15414786 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1543,6 +1543,7 @@ Block area selection Exporting block prefabs to compressed files Minor block fab improvements Fab selection tool +Fab selection tool actually loads fab files diff --git a/src/main/java/electrosphere/client/ui/menu/ingame/FabMenus.java b/src/main/java/electrosphere/client/ui/menu/ingame/FabMenus.java index 0da5c3b1..b52e9d5a 100644 --- a/src/main/java/electrosphere/client/ui/menu/ingame/FabMenus.java +++ b/src/main/java/electrosphere/client/ui/menu/ingame/FabMenus.java @@ -8,6 +8,8 @@ import electrosphere.client.ui.menu.WindowUtils; import electrosphere.controls.ControlHandler.ControlsState; import electrosphere.engine.Globals; import electrosphere.engine.signal.Signal.SignalType; +import electrosphere.game.data.block.BlockFab; +import electrosphere.logger.LoggerInterface; import electrosphere.renderer.ui.elements.Window; import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaAlignment; import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaFlexDirection; @@ -54,7 +56,8 @@ public class FabMenus { //attach scrollable after search input for organzation purposes fabSelectionPanelWindow.addChild(FabSelectionPanel.createFabSelectionPanel((File selectedFile) -> { - System.out.println(selectedFile); + BlockFab fab = BlockFab.read(selectedFile); + LoggerInterface.loggerEngine.WARNING("" + fab.getDimensions()); })); Globals.signalSystem.post(SignalType.YOGA_APPLY,fabSelectionPanelWindow); diff --git a/src/main/java/electrosphere/game/data/block/BlockFab.java b/src/main/java/electrosphere/game/data/block/BlockFab.java index 62f8e59d..ab7fd5e9 100644 --- a/src/main/java/electrosphere/game/data/block/BlockFab.java +++ b/src/main/java/electrosphere/game/data/block/BlockFab.java @@ -9,6 +9,7 @@ import java.nio.ShortBuffer; import org.joml.Vector3i; import electrosphere.client.block.BlockChunkData; +import electrosphere.logger.LoggerInterface; import electrosphere.util.FileUtils; /** @@ -91,4 +92,75 @@ public class BlockFab { } } + /** + * Reads a BlockFab from a specified file + * @param file The file + * @return The BlockFab + */ + public static BlockFab read(File file){ + BlockFab rVal = null; + ByteBuffer buff; + try { + buff = FileUtils.readBufferFromCompressedFile(file); + IntBuffer intView = buff.asIntBuffer(); + int fileVer = intView.get(); + LoggerInterface.loggerFileIO.DEBUG("Read fab file with ver " + fileVer); + + int dimX = intView.get(); + int dimY = intView.get(); + int dimZ = intView.get(); + Vector3i dims = new Vector3i(dimX, dimY, dimZ); + buff.position(HEADER_SIZE); + + ShortBuffer shortView = buff.asShortBuffer(); + + int blockCount = dims.x * dims.y * dims.z; + short[] types = new short[blockCount]; + short[] metadata = new short[blockCount]; + int i = 0; + for(int x = 0; x < dims.x; x++){ + for(int y = 0; y < dims.y; y++){ + for(int z = 0; z < dims.z; z++){ + types[i] = shortView.get(); + metadata[i] = shortView.get(); + i++; + } + } + } + + rVal = new BlockFab(); + rVal.dimensions = dims; + rVal.types = types; + rVal.metadata = metadata; + } catch (IOException e) { + LoggerInterface.loggerFileIO.ERROR(e); + throw new Error("Failed to read BlockFab " + file); + } + return rVal; + } + + /** + * Gets the dimensions of the fab + * @return The dimensions of the fab + */ + public Vector3i getDimensions() { + return dimensions; + } + + /** + * Gets the type data of the fab + * @return The type data + */ + public short[] getTypes() { + return types; + } + + /** + * Gets the metadata of the fab + * @return The metadata + */ + public short[] getMetadata() { + return metadata; + } + }