Class Settings
Represents a set of settings that store configurable data for an object.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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 purposesdouble
Calculates a value for a scaling setting at a given level.double
Calculates a value for a scaling setting at a given level.double
Gets the base value of an attributeboolean
Retrieves a boolean value from the settings.boolean
Retrieves a boolean value from the settings.double
Retrieves a double value from the settings.double
Retrieves a double value from the settings.float
Retrieves a float value from the settings.float
Retrieves a float value from the settings.int
Retrieves an integer value from the settings.int
Retrieves an integer value from the settings.Retrieves a generic attribute.double
Gets the scale value of an attributeRetrieves a string value from the settings.Retrieves a string value from the settings.getStringList
(String key) Retrieves a string list from the settingsboolean
Checks whether the setting is defined.void
load
(studio.magemonkey.codex.mccore.config.parse.DataSection config) Loads attributes from a configuration sectionvoid
Removes a setting.void
save
(studio.magemonkey.codex.mccore.config.parse.DataSection config) Saves settings to a configuration section.void
Defines a new scaling settingvoid
Sets the value for a setting.void
Sets the base value of a scaling settingvoid
Sets the bonus value of a scaling setting
-
Constructor Details
-
Settings
public Settings() -
Settings
-
-
Method Details
-
set
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 keyvalue
- setting value
-
set
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 namebase
- base valuescale
- value scale
-
setBase
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 namevalue
- new base value
-
setScale
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 namevalue
- new scale value
-
getDouble
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
Retrieves a double value from the settings. If the setting is not set, this will instead return 0.- Parameters:
key
- setting keydefaultValue
- the default value in case not set- Returns:
- double setting value
-
getFloat
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
Retrieves a float value from the settings. If the setting is not set, this will instead return 0.- Parameters:
key
- setting keydefaultValue
- the default value in case not set- Returns:
- float setting value
-
getInt
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
Retrieves an integer value from the settings. If the setting is not set, this will instead return the default value.- Parameters:
key
- setting keydefaultValue
- the default value in case not set- Returns:
- integer setting value
-
getBool
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
Retrieves a boolean value from the settings. If the setting is not set, this will instead return false.- Parameters:
key
- setting keydefaultValue
- the default value in case not set- Returns:
- boolean setting value
-
getString
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
Retrieves a string value from the settings. If the setting is not set, this will instead return the default value.- Parameters:
key
- setting keydefaultValue
- the default value in case not set- Returns:
- String setting value
-
getStringList
Retrieves a string list from the settings- Parameters:
key
- settings key- Returns:
- string list or empty list if not found
-
getAttr
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 namelevel
- level of scaling- Returns:
- scaled setting value
-
getAttr
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 namelevel
- level of scalingdefaultValue
- the default value in case not set- Returns:
- scaled setting value
-
getBase
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
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
Retrieves a generic attribute.
If the attribute is not set, this will return 0 instead.
- Parameters:
key
- attribute namelevel
- level of scaling- Returns:
- attribute value or 0 if not found
-
has
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
Removes a setting.
If the setting is not set, this will not do anything.
- Parameters:
key
- name of the attribute
-
checkDefault
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 checkdefaultBase
- default base valuedefaultScale
- 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
-