Package config

Source Code of config.GameConfig

package config;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import com.threed.jpct.Logger;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;

public class GameConfig {
  private float anglePerPixel;
  private float defaultCameraDist;
  private float defaultZoomDist;
  private int defaultRotateDx;
  private int defaultRotateDy;
  private float maxZoom;
  private float minZoom;
 
  public GameConfig(String configFile){
      try {
        String line;
        BufferedReader in = new BufferedReader(new FileReader(configFile));
        Logger.log("Wczytano plik konfiguracyjny: "+configFile);
     
        while ((line = in.readLine()) != null) {
        if(line.equals("textures{")){
          loadTextures(in);
        }
        else if(line.equals("camera{")){
          loadCameraProperties(in);
        }
      }
    } catch (NumberFormatException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
 
  private void loadTextures(BufferedReader in) throws IOException{
    String line;
    String [] tmp;
      while (!(line = in.readLine()).equals("}")) {
      tmp = line.split("=");
      TextureManager.getInstance().addTexture(tmp[0].trim(), new Texture(tmp[1].trim()));
    }   
  }
 
  private void loadCameraProperties(BufferedReader in) throws IOException{
    String line;
    String [] tmp;
      while (!(line = in.readLine()).equals("}")) {
      tmp = line.split("=");
      if(tmp[0].trim().equals("ANGLE_PER_PIXEL")){
        Logger.log("CAMERA PARAM ANGLE_PER_PIXEL = "+tmp[1].trim());
        anglePerPixel = Float.parseFloat(tmp[1].trim());
      }
      else if(tmp[0].trim().equals("DEFAULT_CAMERA_DIST")){
        Logger.log("CAMERA PARAM DEFAULT_CAMERA_DIST = "+tmp[1].trim());
        defaultCameraDist = Float.parseFloat(tmp[1].trim());
      }
      else if(tmp[0].trim().equals("DEFAULT_ZOOM_DIST")){
        Logger.log("CAMERA PARAM DEFAULT_ZOOM_DIST = "+tmp[1].trim());
        defaultZoomDist = Float.parseFloat(tmp[1].trim());
      }
      else if(tmp[0].trim().equals("DEFAULT_ROTATE_DX")){
        Logger.log("CAMERA PARAM DEFAULT_ROTATE_DX = "+tmp[1].trim());
        defaultRotateDx = Integer.parseInt(tmp[1].trim());
      }
      else if(tmp[0].trim().equals("DEFAULT_ROTATE_DY")){
        Logger.log("CAMERA PARAM DEFAULT_ROTATE_DY = "+tmp[1].trim());
        defaultRotateDy = Integer.parseInt(tmp[1].trim());
      }
      else if(tmp[0].trim().equals("MAX_ZOOM")){
        Logger.log("CAMERA PARAM MAX_ZOOM = "+tmp[1].trim());
        maxZoom = Float.parseFloat(tmp[1].trim());
      }
      else if(tmp[0].trim().equals("MIN_ZOOM")){
        Logger.log("CAMERA PARAM MIN_ZOOM = "+tmp[1].trim());
        minZoom = Float.parseFloat(tmp[1].trim());
      }
    }   
  }
 
  public float getAnglePerPixel() {
    return anglePerPixel;
  }

  public void setAnglePerPixel(float anglePerPixel) {
    this.anglePerPixel = anglePerPixel;
  }

  public float getDefaultCameraDist() {
    return defaultCameraDist;
  }

  public void setDefaultCameraDist(float defaultCameraDist) {
    this.defaultCameraDist = defaultCameraDist;
  }

  public float getDefaultZoomDist() {
    return defaultZoomDist;
  }

  public void setDefaultZoomDist(float defaultZoomDist) {
    this.defaultZoomDist = defaultZoomDist;
  }

  public int getDefaultRotateDx() {
    return defaultRotateDx;
  }

  public void setDefaultRotateDx(int defaultRotateDx) {
    this.defaultRotateDx = defaultRotateDx;
  }

  public int getDefaultRotateDy() {
    return defaultRotateDy;
  }

  public void setDefaultRotateDy(int defaultRotateDy) {
    this.defaultRotateDy = defaultRotateDy;
  }

  public float getMaxZoom() {
    return maxZoom;
  }

  public void setMaxZoom(float maxZoom) {
    this.maxZoom = maxZoom;
  }

  public float getMinZoom() {
    return minZoom;
  }

  public void setMinZoom(float minZoom) {
    this.minZoom = minZoom;
  }
}
TOP

Related Classes of config.GameConfig

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.