BadScript 2
Loading...
Searching...
No Matches
BadScript2.Settings.BadEditableSetting< T, TValue > Class Template Reference

Implements an Editable Setting. More...

Public Member Functions

 BadEditableSetting (string name, TValue? defaultValue=default)
 Creates a new Editable Setting.
 
BadSettingsGet ()
 Returns the settings object of the Editable Setting.
 
TValue? GetValue ()
 Returns the value of the Editable Setting.
 
void Set (TValue? value)
 Sets the value of the Editable Setting.
 

Private Attributes

readonly? TValue m_DefaultValue
 The Default Value of the Setting.
 
readonly string m_Name
 The Name of the Setting.
 
BadSettingsm_SettingsObj
 The Settings Object.
 

Detailed Description

Implements an Editable Setting.

Template Parameters
TThe Type that has the setting
TValueThe Type of the value of the setting
Type Constraints
T :BadSettingsProvider<T> 
T :new() 

Definition at line 15 of file BadEditableSetting.cs.

Constructor & Destructor Documentation

◆ BadEditableSetting()

BadScript2.Settings.BadEditableSetting< T, TValue >.BadEditableSetting ( string  name,
TValue?  defaultValue = default 
)

Creates a new Editable Setting.

Parameters
nameThe Name of the Setting
defaultValueThe Default Value of the Setting

Definition at line 37 of file BadEditableSetting.cs.

38 {
39 m_Name = name;
40 m_DefaultValue = defaultValue;
41 }
readonly? TValue m_DefaultValue
The Default Value of the Setting.
readonly string m_Name
The Name of the Setting.

Member Function Documentation

◆ Get()

Returns the settings object of the Editable Setting.

Returns
The settings object of the Editable Setting

Definition at line 47 of file BadEditableSetting.cs.

48 {
49 if (m_SettingsObj != null ||
50 BadSettingsProvider<T>.Instance.Settings == null)
51 {
52 return m_SettingsObj;
53 }
54
55 if (BadSettingsProvider<T>.Instance.Settings.HasProperty(m_Name))
56 {
57 m_SettingsObj = BadSettingsProvider<T>.Instance.Settings?.GetProperty(m_Name);
58 }
59 else
60 {
62 new BadSettings(m_DefaultValue == null ? JValue.CreateNull() : JToken.FromObject(m_DefaultValue), string.Empty);
63 BadSettingsProvider<T>.Instance.Settings.SetProperty(m_Name, m_SettingsObj);
64 }
65
66 return m_SettingsObj;
67 }
BadSettings? m_SettingsObj
The Settings Object.
void SetProperty(string propertyName, BadSettings value, bool invokeOnChange=true)
Sets the Property with the given Name.
BadSettings GetProperty(string propertyName)
Returns the Property with the given Name.

◆ GetValue()

TValue? BadScript2.Settings.BadEditableSetting< T, TValue >.GetValue ( )

Returns the value of the Editable Setting.

Returns
The value of the Editable Setting

Definition at line 73 of file BadEditableSetting.cs.

74 {
75 BadSettings? setting = Get();
76
77 if (setting == null)
78 {
79 return m_DefaultValue;
80 }
81
82 TValue? value = setting.GetValue<TValue>();
83
84 return value ?? m_DefaultValue;
85 }
BadSettings? Get()
Returns the settings object of the Editable Setting.

◆ Set()

void BadScript2.Settings.BadEditableSetting< T, TValue >.Set ( TValue?  value)

Sets the value of the Editable Setting.

Parameters
valueThe value to set
Exceptions
BadRuntimeExceptionIf the Settings Object is null

Definition at line 92 of file BadEditableSetting.cs.

93 {
94 BadSettings? settings = Get();
95
96 if (settings == null)
97 {
98 throw new BadRuntimeException($"Settings Object for {typeof(T).Name}.{m_Name} is null");
99 }
100
101 settings.SetValue(value == null ? JValue.CreateNull() : JToken.FromObject(value));
102 }

Member Data Documentation

◆ m_DefaultValue

readonly? TValue BadScript2.Settings.BadEditableSetting< T, TValue >.m_DefaultValue
private

The Default Value of the Setting.

Definition at line 20 of file BadEditableSetting.cs.

◆ m_Name

readonly string BadScript2.Settings.BadEditableSetting< T, TValue >.m_Name
private

The Name of the Setting.

Definition at line 25 of file BadEditableSetting.cs.

◆ m_SettingsObj

BadSettings? BadScript2.Settings.BadEditableSetting< T, TValue >.m_SettingsObj
private

The Settings Object.

Definition at line 30 of file BadEditableSetting.cs.


The documentation for this class was generated from the following file: