You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
193 lines
7.2 KiB
193 lines
7.2 KiB
/** |
|
* Copyright 2022 Jamie Munro, Distributed under the Common Public Attribution License Version 1.0 (CPAL-1.0) |
|
* Tile engine |
|
*/ |
|
|
|
import java.io.FileInputStream; |
|
import java.io.IOException; |
|
import java.io.InputStream; |
|
import java.util.Properties; |
|
|
|
/** |
|
* Configuation Class |
|
* Singleton class containing all customisable configuration options for application |
|
*/ |
|
class Configuration { |
|
/** |
|
* Where to find properties file if no location is supplied |
|
*/ |
|
private static final String DEFAULT_CONFIG_PATH = "config.properties"; |
|
|
|
public final int aspectX; |
|
public final int aspectY; |
|
|
|
public final int framerate; |
|
|
|
public final int viewportWidth; |
|
public final int viewportHeight; |
|
|
|
public final int levelWidth; |
|
public final int levelHeight; |
|
|
|
public final String resPath; |
|
public final String tilePath; |
|
public final String levelPath; |
|
public final String spritePath; |
|
public final String soundPath; |
|
public final String musicPath; |
|
public final String fontPath; |
|
|
|
public final String levelExtension; |
|
public final String tileDeliminator; |
|
public final String tileImageExtension; |
|
public final String tilePropertiesExtension; |
|
public final int emptyTile; |
|
public final int unknownTitle; |
|
|
|
public final String title; |
|
public final String titleMsg1; |
|
public final String loadingMsg; |
|
public final String pauseMsg1; |
|
public final String pauseMsg2; |
|
public final String controlsMsg; |
|
public final String storyCrawl; |
|
public final String gameOverMsg; |
|
public final String credits; |
|
public final String copyright; |
|
|
|
public final int storyWaitTime; |
|
public final int scrollSpeed; |
|
|
|
public final int serialDevice; |
|
public final int baudRate; |
|
public final int lineEnding; |
|
public final int messageLength; |
|
public final String microbitSplitRegex; |
|
public final String microbitControlChar; |
|
|
|
public int thresholdX; |
|
public int thresholdY; |
|
public int headingThreshold; |
|
|
|
public final int playerScaleFactor; |
|
public final int playerProjectileScaleFactor; |
|
|
|
public final float mainEngineForce; |
|
public final float reverseEngineForce; |
|
public final int rotationSpeed; |
|
|
|
public final float maxForwardsMomentum; |
|
public final float maxRearMomentum; |
|
|
|
public final float friction; |
|
|
|
public final int initialLives; |
|
public final int initialBombs; |
|
public final int bombSpeed; |
|
|
|
public final int enemyTypes; |
|
|
|
public final int maxPlayerProjectiles; |
|
public final int reloadTime; |
|
public final int shieldTime; |
|
|
|
public final int extraLifeInterval; |
|
public final int extraBombInterval; |
|
|
|
public final int difficultyInterval; |
|
public final int spawnInterval; |
|
|
|
/** |
|
* Private constructor |
|
* Parses properties file and loads each parameter into relevent variable |
|
* @param filepath configuration properties filepath |
|
*/ |
|
public Configuration() throws IOException{ |
|
Properties prop = new Properties(); |
|
|
|
InputStream input = new FileInputStream(sketchPath() + System.getProperty("file.separator") + DEFAULT_CONFIG_PATH); |
|
|
|
prop.load(input); |
|
|
|
this.aspectX = Integer.parseInt(prop.getProperty("aspectX")); |
|
this.aspectY = Integer.parseInt(prop.getProperty("aspectY")); |
|
|
|
this.framerate = Integer.parseInt(prop.getProperty("framerate")); |
|
|
|
this.viewportWidth = Integer.parseInt(prop.getProperty("viewportWidth")); |
|
this.viewportHeight = Integer.parseInt(prop.getProperty("viewportHeight")); |
|
|
|
this.levelWidth = Integer.parseInt(prop.getProperty("levelWidth")); |
|
this.levelHeight = Integer.parseInt(prop.getProperty("levelHeight")); |
|
|
|
this.resPath = prop.getProperty("resPath"); |
|
this.tilePath = prop.getProperty("tilePath"); |
|
this.levelPath = prop.getProperty("levelPath"); |
|
this.spritePath = prop.getProperty("spritePath"); |
|
this.musicPath = prop.getProperty("musicPath"); |
|
this.soundPath = prop.getProperty("soundPath"); |
|
this.fontPath = prop.getProperty("fontPath"); |
|
|
|
this.levelExtension = prop.getProperty("levelExtension"); |
|
this.tileDeliminator = prop.getProperty("tileDeliminator"); |
|
this.tileImageExtension = prop.getProperty("tileImageExtension"); |
|
this.tilePropertiesExtension = prop.getProperty("tilePropertiesExtension"); |
|
this.emptyTile = Integer.parseInt(prop.getProperty("emptyTile")); |
|
this.unknownTitle = Integer.parseInt(prop.getProperty("unknownTitle")); |
|
|
|
this.title = prop.getProperty("title"); |
|
this.titleMsg1 = prop.getProperty("titleMsg1"); |
|
this.loadingMsg = prop.getProperty("loadingMsg"); |
|
this.pauseMsg1 = prop.getProperty("pauseMsg1"); |
|
this.pauseMsg2 = prop.getProperty("pauseMsg2"); |
|
this.controlsMsg = prop.getProperty("controlsMsg"); |
|
this.storyCrawl = prop.getProperty("storyCrawl"); |
|
this.gameOverMsg = prop.getProperty("gameOverMsg"); |
|
this.credits = prop.getProperty("credits"); |
|
this.copyright = prop.getProperty("copyright"); |
|
|
|
this.storyWaitTime = Integer.parseInt(prop.getProperty("storyWaitTime")); |
|
this.scrollSpeed = Integer.parseInt(prop.getProperty("scrollSpeed")); |
|
|
|
this.serialDevice = Integer.parseInt(prop.getProperty("serialDevice")); |
|
this.baudRate = Integer.parseInt(prop.getProperty("baudRate")); |
|
this.lineEnding = Integer.parseInt(prop.getProperty("lineEnding")); |
|
this.messageLength = Integer.parseInt(prop.getProperty("messageLength")); |
|
this.microbitSplitRegex = prop.getProperty("microbitSplitRegex"); |
|
this.microbitControlChar = prop.getProperty("microbitControlChar"); |
|
|
|
this.thresholdX = Integer.parseInt(prop.getProperty("thresholdX")); |
|
this.thresholdY = Integer.parseInt(prop.getProperty("thresholdY")); |
|
this.headingThreshold = Integer.parseInt(prop.getProperty("headingThreshold")); |
|
|
|
this.playerScaleFactor = Integer.parseInt(prop.getProperty("playerScaleFactor")); |
|
this.playerProjectileScaleFactor = Integer.parseInt(prop.getProperty("playerProjectileScaleFactor")); |
|
|
|
this.mainEngineForce = Float.parseFloat(prop.getProperty("mainEngineForce")); |
|
this.reverseEngineForce = Float.parseFloat(prop.getProperty("reverseEngineForce")); |
|
this.rotationSpeed = Integer.parseInt(prop.getProperty("rotationSpeed")); |
|
|
|
this.maxForwardsMomentum = Float.parseFloat(prop.getProperty("maxForwardsMomentum")); |
|
this.maxRearMomentum = Float.parseFloat(prop.getProperty("maxRearMomentum")); |
|
|
|
this.friction = Float.parseFloat(prop.getProperty("friction")); |
|
|
|
this.initialLives = Integer.parseInt(prop.getProperty("initialLives")); |
|
this.initialBombs = Integer.parseInt(prop.getProperty("initialBombs")); |
|
this.bombSpeed = Integer.parseInt(prop.getProperty("bombSpeed")); |
|
|
|
this.enemyTypes = Integer.parseInt(prop.getProperty("enemyTypes")); |
|
|
|
this.maxPlayerProjectiles = Integer.parseInt(prop.getProperty("maxPlayerProjectiles")); |
|
this.reloadTime = Integer.parseInt(prop.getProperty("reloadTime")); |
|
this.shieldTime = Integer.parseInt(prop.getProperty("shieldTime")); |
|
|
|
this.extraLifeInterval = Integer.parseInt(prop.getProperty("extraLifeInterval")); |
|
this.extraBombInterval = Integer.parseInt(prop.getProperty("extraBombInterval")); |
|
|
|
this.difficultyInterval = Integer.parseInt(prop.getProperty("difficultyInterval")); |
|
this.spawnInterval = Integer.parseInt(prop.getProperty("spawnInterval")); |
|
|
|
input.close(); |
|
} |
|
}
|
|
|