Class Settings

java.lang.Object
studio.magemonkey.fabled.api.Settings

public class Settings extends Object

Represents a set of settings that store configurable data for an object.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Settings(Settings settings)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    checkDefault(String key, double defaultBase, double defaultScale)
    Checks to make sure the settings have a required scaling value.
    void
    Dumps the settings to the console for debugging purposes
    double
    getAttr(String key, int level)
    Calculates a value for a scaling setting at a given level.
    double
    getAttr(String key, int level, double defaultValue)
    Calculates a value for a scaling setting at a given level.
    double
    Gets the base value of an attribute
    boolean
    Retrieves a boolean value from the settings.
    boolean
    getBool(String key, boolean defaultValue)
    Retrieves a boolean value from the settings.
    double
    Retrieves a double value from the settings.
    double
    getDouble(String key, double defaultValue)
    Retrieves a double value from the settings.
    float
    Retrieves a float value from the settings.
    float
    getFloat(String key, float defaultValue)
    Retrieves a float value from the settings.
    int
    Retrieves an integer value from the settings.
    int
    getInt(String key, int defaultValue)
    Retrieves an integer value from the settings.
    getObj(String key, int level)
    Retrieves a generic attribute.
    double
    Gets the scale value of an attribute
    Retrieves a string value from the settings.
    getString(String key, String defaultValue)
    Retrieves a string value from the settings.
    Retrieves a string list from the settings
    boolean
    has(String key)
    Checks whether the setting is defined.
    void
    load(studio.magemonkey.codex.mccore.config.parse.DataSection config)
    Loads attributes from a configuration section
    void
    Removes a setting.
    void
    save(studio.magemonkey.codex.mccore.config.parse.DataSection config)
    Saves settings to a configuration section.
    void
    set(String key, double base, double scale)
    Defines a new scaling setting
    void
    set(String key, Object value)
    Sets the value for a setting.
    void
    setBase(String key, double value)
    Sets the base value of a scaling setting
    void
    setScale(String key, double value)
    Sets the bonus value of a scaling setting

    Methods inherited from class java.lang.Object

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

    • Settings

      public Settings()
    • Settings

      public Settings(Settings settings)
  • Method Details

    • set

      public void set(String key, Object value)
      Sets the value for a setting. You should only provide a String, int, boolean, or double as those are the only supported types.
      Parameters:
      key - setting key
      value - setting value
    • set

      public void set(String key, double base, double scale)

      Defines a new scaling setting

      Values are overwritten after the configuration is loaded. Using this method is simply to define the default values before configuration changes.

      You should not use this method after the initial setup.

      Parameters:
      key - attribute name
      base - base value
      scale - value scale
    • setBase

      public void setBase(String key, double value)

      Sets the base value of a scaling setting

      If the scaling setting is not set, this will default the scale of the setting to 0.

      This is used to override the default values. You should not use this method. When defining scaling settings, use set(String, double, double)

      Parameters:
      key - scaling setting name
      value - new base value
    • setScale

      public void setScale(String key, double value)

      Sets the bonus value of a scaling setting

      If the scaling setting is not set, this will default the base of the setting to 0.

      This is used by the API to override the default values. You should not use this method. When defining scaling settings, use set(String, double, double)

      Parameters:
      key - scaling setting name
      value - new scale value
    • getDouble

      public double getDouble(String key)
      Retrieves a double value from the settings. If the setting is not set, this will instead return 0.
      Parameters:
      key - setting key
      Returns:
      double setting value
    • getDouble

      public double getDouble(String key, double defaultValue)
      Retrieves a double value from the settings. If the setting is not set, this will instead return 0.
      Parameters:
      key - setting key
      defaultValue - the default value in case not set
      Returns:
      double setting value
    • getFloat

      public float getFloat(String key)
      Retrieves a float value from the settings. If the setting is not set, this will instead return 0.
      Parameters:
      key - setting key
      Returns:
      float setting value
    • getFloat

      public float getFloat(String key, float defaultValue)
      Retrieves a float value from the settings. If the setting is not set, this will instead return 0.
      Parameters:
      key - setting key
      defaultValue - the default value in case not set
      Returns:
      float setting value
    • getInt

      public int getInt(String key)
      Retrieves an integer value from the settings. If the setting is not set, this will instead return 0.
      Parameters:
      key - setting key
      Returns:
      integer setting value
    • getInt

      public int getInt(String key, int defaultValue)
      Retrieves an integer value from the settings. If the setting is not set, this will instead return the default value.
      Parameters:
      key - setting key
      defaultValue - the default value in case not set
      Returns:
      integer setting value
    • getBool

      public boolean getBool(String key)
      Retrieves a boolean value from the settings. If the setting is not set, this will instead return false.
      Parameters:
      key - setting key
      Returns:
      boolean setting value
    • getBool

      public boolean getBool(String key, boolean defaultValue)
      Retrieves a boolean value from the settings. If the setting is not set, this will instead return false.
      Parameters:
      key - setting key
      defaultValue - the default value in case not set
      Returns:
      boolean setting value
    • getString

      public String getString(String key)
      Retrieves a string value from the settings. If the setting is not set, this will instead return null.
      Parameters:
      key - setting key
      Returns:
      String setting value
    • getString

      public String getString(String key, String defaultValue)
      Retrieves a string value from the settings. If the setting is not set, this will instead return the default value.
      Parameters:
      key - setting key
      defaultValue - the default value in case not set
      Returns:
      String setting value
    • getStringList

      public List<String> getStringList(String key)
      Retrieves a string list from the settings
      Parameters:
      key - settings key
      Returns:
      string list or empty list if not found
    • getAttr

      public double getAttr(String key, int level)

      Calculates a value for a scaling setting at a given level.

      If the scaling setting does not exist, this will instead return 0.

      Parameters:
      key - scaling setting name
      level - level of scaling
      Returns:
      scaled setting value
    • getAttr

      public double getAttr(String key, int level, double defaultValue)

      Calculates a value for a scaling setting at a given level.

      If the scaling setting does not exist, this will instead return the provided default value.

      Parameters:
      key - scaling setting name
      level - level of scaling
      defaultValue - the default value in case not set
      Returns:
      scaled setting value
    • getBase

      public double getBase(String key)

      Gets the base value of an attribute

      If the attribute is not set, this will return 0.

      Parameters:
      key - attribute name
      Returns:
      base value
    • getScale

      public double getScale(String key)

      Gets the scale value of an attribute

      If the attribute is not set, this will return 0.

      Parameters:
      key - attribute name
      Returns:
      change in value per level
    • getObj

      public Object getObj(String key, int level)

      Retrieves a generic attribute.

      If the attribute is not set, this will return 0 instead.

      Parameters:
      key - attribute name
      level - level of scaling
      Returns:
      attribute value or 0 if not found
    • has

      public boolean has(String key)

      Checks whether the setting is defined.

      A setting is defined when it is set at any point using any of the setter methods or while loading from the configuration.

      Parameters:
      key - name of the setting
      Returns:
      true if defined, false otherwise
    • remove

      public void remove(String key)

      Removes a setting.

      If the setting is not set, this will not do anything.

      Parameters:
      key - name of the attribute
    • checkDefault

      public void checkDefault(String key, double defaultBase, double defaultScale)

      Checks to make sure the settings have a required scaling value.

      If the scaling setting is not set, the scaling setting will be created with the provided values.

      If the attribute already exists, this will do nothing.

      Parameters:
      key - key of the setting to check
      defaultBase - default base value
      defaultScale - default scale value
    • save

      public void save(studio.magemonkey.codex.mccore.config.parse.DataSection config)

      Saves settings to a configuration section.

      If the config section is null, this does not do anything.

      Parameters:
      config - configuration section to save to
    • load

      public void load(studio.magemonkey.codex.mccore.config.parse.DataSection config)

      Loads attributes from a configuration section

      If the section is null or has no keys, this will not do anything.

      Keys that do not point to valid sections for the base/scale values will not be loaded.

      Sections without a base or without a scale value will load what's present and default the missing one to 0.

      Parameters:
      config - configuration section to load from
    • dumpToConsole

      public void dumpToConsole()
      Dumps the settings to the console for debugging purposes