Search in sources :

Example 1 with IllegalVoxelDeclarationException

use of io.xol.chunkstories.api.exceptions.content.IllegalVoxelDeclarationException in project chunkstories by Hugobros3.

the class VoxelsStore method readVoxelsDefinitions.

private void readVoxelsDefinitions(Asset f) {
    if (f == null)
        return;
    try {
        BufferedReader reader = new BufferedReader(f.reader());
        String line = "";
        // Voxel voxel = null;
        int ln = 0;
        int loadedVoxels = 0;
        while ((line = reader.readLine()) != null) {
            line = line.replace("\t", "");
            if (line.startsWith("#")) {
            // It's a comment, ignore.
            } else {
                if (line.startsWith("voxel")) {
                    String[] splitted = line.split(" ");
                    if (splitted.length < 2) {
                        logger().warn("Parse error in file " + f + ", line " + ln + ", malformed voxel tag. Aborting read.");
                        break;
                    }
                    // int id = Integer.parseInt(splitted[2]);
                    String name = splitted[1];
                    try {
                        VoxelDefinitionImplementation voxelType = new VoxelDefinitionImplementation(this, name, reader);
                        Voxel voxel = voxelType.getVoxelObject();
                        voxelsByName.put(voxel.getName(), voxel);
                        loadedVoxels++;
                        if (name.equals("air"))
                            air = voxel;
                    } catch (IllegalVoxelDeclarationException e) {
                        e.printStackTrace();
                    }
                } else if (line.startsWith("end")) {
                    logger().warn("Parse error in file " + f + ", line " + ln + ", unexpected 'end' token.");
                }
            }
            ln++;
        }
        logger().debug("Parsed file " + f + " correctly, loading " + loadedVoxels + " voxels.");
        reader.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Voxel(io.xol.chunkstories.api.voxel.Voxel) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) IllegalVoxelDeclarationException(io.xol.chunkstories.api.exceptions.content.IllegalVoxelDeclarationException)

Aggregations

IllegalVoxelDeclarationException (io.xol.chunkstories.api.exceptions.content.IllegalVoxelDeclarationException)1 Voxel (io.xol.chunkstories.api.voxel.Voxel)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1