All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.daxie.joglf.gl.model.loader.bd1.BD1Parser Maven / Gradle / Ivy

There is a newer version: 11.7.0
Show newest version
package com.daxie.joglf.gl.model.loader.bd1;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.daxie.tool.ByteFunctions;
import com.daxie.tool.FileFunctions;
import com.daxie.tool.FilenameFunctions;

/**
 * Reads data from a BD1 file.
 * @author Daba
 *
 */
class BD1Parser {
	private Map texture_filenames_map;//(texture_id,texture_filename)
	private List blocks;
	
	public BD1Parser(String bd1_filename)  throws FileNotFoundException{
		texture_filenames_map=new HashMap<>();
		blocks=new ArrayList<>();
		
		List bin=FileFunctions.GetFileAllBin(bd1_filename);
		
		int count=0;
		
		//Texture filenames
		byte[] texture_filename_buffer=new byte[31];
		String texture_filename_temp;
		int first_null_pos;
		for(int i=0;i<10;i++) {
			for(int j=0;j<31;j++) {
				texture_filename_buffer[j]=bin.get(count);
				count++;
			}
			texture_filename_temp=new String(texture_filename_buffer);
			
			first_null_pos=30;
			for(int j=0;j<30;j++) {
				if(texture_filename_temp.charAt(j)=='\0') {
					first_null_pos=j;
					break;
				}
			}
			
			texture_filename_temp=texture_filename_temp.substring(0, first_null_pos);
			texture_filename_temp=FilenameFunctions.ReplaceWindowsDelimiterWithLinuxDelimiter(texture_filename_temp);
			
			texture_filenames_map.put(i, texture_filename_temp);
		}
		
		//Number of blocks
		byte[] block_num_buffer=new byte[2];
		block_num_buffer[0]=bin.get(count);
		block_num_buffer[1]=bin.get(count+1);
		
		int block_num=ByteFunctions.byte_to_ushort_le(block_num_buffer);
		
		count+=2;
		
		//Blocks
		for(int i=0;i GetBlocks(){
		return new ArrayList(blocks);
	}
	public Map GetTextureFilenamesMap(){
		return new HashMap(texture_filenames_map);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy