Class gameConfig

All Implemented Interfaces:
Serializable, Cloneable, Map<Object,​Object>

public class gameConfig extends Properties
Read an XML properties configuration file of game settings.

This class provides default values for all properties which can be individually overridden in the XML config.

These properties are transferred into the game application settings in main()

The config file is either in the working directory or on the classpath.

Author:
Kevin Moore <dev@kevin.moore.name>
See Also:
main.start(java.lang.String[]), Serialized Form
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • searchpaths

      private final List<File> searchpaths
    • configFile

      private File configFile
      The config file that was actually found and loaded.
  • Constructor Details

    • gameConfig

      public gameConfig(List<File> paths)
      Initialise this Property list's defaults with the the keys and defaults allowed by the keys enum.
      Parameters:
      paths - additional locations to search for the config file - generally initialised to the java classpath
  • Method Details

    • parse

      public void parse(File cf) throws IOException
      Parse the requested XML properties file into the fields of this object.

      The file is searched for along the paths provided in the constructor. The keys will be lowercase which means future searching needs to be lowercase.

      Parameters:
      cf - filename eg zodiac.xml
      Throws:
      IOException
    • getConfigFile

      public File getConfigFile()
    • getProperty

      public String getProperty(gameConfig.keys e)
      Get the requested value by enum key, will always provide a value.
      Parameters:
      e -
      Returns:
    • getProperty

      public String getProperty(String p)
      Override the Properties method to test if the provided string is actually one of the allowed enums.

      This means we cant just create or get arbitrary keys, it has to have been defined in our enum.

      Overrides:
      getProperty in class Properties
      Parameters:
      p -
      Returns:
      See Also:
      gameConfig.keys