Class MainModuleConfig

java.lang.Object
io.codetoil.curved_spacetime.MainModuleConfig

public class MainModuleConfig extends Object
The engine's own settings, read from config/main-module.config.

Holds the frame rate the callback loop runs at and the level every module's logger is set to. Neither key is required to be present: loading substitutes a documented default for anything missing or unparseable and reports that through isDirty(), so that a user who deletes the file gets a complete one back on the next run.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a configuration that reports load problems to the given logger.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the frame rate the engine's callback loop runs at.
    Returns the level every module sets its logger to.
    boolean
    Returns whether this configuration differs from what is on disk.
    Reads the configuration from disk, substituting defaults for anything missing or invalid.
    void
    Writes the configuration to disk, creating config/ if it does not exist.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MainModuleConfig

      public MainModuleConfig(Logger logger)
      Creates a configuration that reports load problems to the given logger.

      Nothing is read from disk until load() is called.

      Parameters:
      logger - the logger to warn through when a key is missing or invalid
  • Method Details

    • getFPS

      public int getFPS()
      Returns the frame rate the engine's callback loop runs at.
      Returns:
      the configured frames per second, within the inclusive bounds 1 and 1000
    • getLoggerLevel

      public Level getLoggerLevel()
      Returns the level every module sets its logger to.
      Returns:
      the configured logging level
    • load

      public MainModuleConfig load() throws IOException
      Reads the configuration from disk, substituting defaults for anything missing or invalid.

      A missing file is not an error. Each key that is absent or fails to parse is reported through the logger, replaced with its default, and marks the configuration dirty.

      Returns:
      this configuration, so that construction and loading compose
      Throws:
      IOException - if the file exists but cannot be read
    • save

      public void save() throws IOException
      Writes the configuration to disk, creating config/ if it does not exist.

      Every key is written, not only those that changed, and the dirty flag is cleared on success.

      Throws:
      IOException - if the config directory cannot be created or the file cannot be written
    • isDirty

      public boolean isDirty()
      Returns whether this configuration differs from what is on disk.

      Loading having substituted a default for fps or logger_level is the usual cause; save() clears it.

      Returns:
      true if the file does not match this configuration and should be rewritten