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

com.daxie.xops.bd1.BD1Writer Maven / Gradle / Ivy

package com.daxie.xops.bd1;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.daxie.basis.vector.Vector;
import com.daxie.tool.ByteFunctions;
import com.daxie.tool.FileFunctions;

/**
 * Writes data to a BD1 file.
 * @author Daba
 *
 */
class BD1Writer {
	private Logger logger=LoggerFactory.getLogger(BD1Writer.class);
	
	private List blocks;
	private Map texture_filenames_map;
	
	public BD1Writer(List blocks,Map texture_filenames_map) {
		this.blocks=blocks;
		this.texture_filenames_map=texture_filenames_map;
	}
	
	public int Write(String bd1_filename){
		if(blocks==null||texture_filenames_map==null) {
			logger.warn("Data not prepared.");
			return -1;
		}
		
		List bin=new ArrayList<>();
		
		this.AddTextureFilenamesToBin(bin);
		
		//Number of blocks
		int block_num=blocks.size();
		ByteFunctions.AddUShortValueToBin_LE(bin, block_num);
		
		//Block data
		for(int i=0;i bin) {
		Map sorted_texture_filenames_map=new TreeMap<>(texture_filenames_map);
		
		int texture_count=0;
		for(int texture_id:sorted_texture_filenames_map.keySet()) {
			String texture_filename=sorted_texture_filenames_map.get(texture_id);
			if(texture_filename.length()>30) {
				texture_filename=texture_filename.substring(0, 30);
			}
			
			byte[] texture_filename_buffer=new byte[31];
			
			int pos;
			for(pos=0;pos




© 2015 - 2025 Weber Informatics LLC | Privacy Policy