Class: GamePlay::Options::Helper
- Defined in:
- scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb
Instance Attribute Summary collapse
-
#description ⇒ String
Option description.
-
#getter ⇒ Symbol
readonly
Option getter (on $options).
-
#name ⇒ String
Option name.
-
#setter ⇒ Symbol
readonly
Option setter (on $options).
-
#type ⇒ Symbol
readonly
Option type.
-
#values ⇒ Array
readonly
Option values.
-
#values_text ⇒ Array<String>, String
Option value text(s).
Instance Method Summary collapse
-
#current_value ⇒ Object
Retreive the current value.
-
#initialize(*args) ⇒ Helper
constructor
Create a new option.
-
#next_value ⇒ Object
Retreive the next value.
-
#prev_value ⇒ Object
Retreive the prev value.
-
#update_value(new_value)
Update the option value.
Constructor Details
#initialize(*args) ⇒ Helper
Create a new option
84 85 86 87 88 89 90 91 92 |
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 84 def initialize(*args) @type = args[0] @values = args[1] @values_text = args[2] @name = args[3] @description = args[4] @getter = args[5] @setter = args[6] end |
Instance Attribute Details
#description ⇒ String
Option description
75 76 77 |
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 75 def description @description end |
#getter ⇒ Symbol (readonly)
Option getter (on $options)
78 79 80 |
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 78 def getter @getter end |
#name ⇒ String
Option name
72 73 74 |
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 72 def name @name end |
#setter ⇒ Symbol (readonly)
Option setter (on $options)
81 82 83 |
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 81 def setter @setter end |
#type ⇒ Symbol (readonly)
Option type
63 64 65 |
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 63 def type @type end |
#values ⇒ Array (readonly)
Option values
66 67 68 |
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 66 def values @values end |
Instance Method Details
#current_value ⇒ Object
Retreive the current value
96 97 98 99 100 101 102 103 104 |
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 96 def current_value value = $options.send(getter) if @type == :slider value = value.clamp(@values[:min], @values[:max]) return value - (value % @values[:increment]) end value_index = @values.index(value) return @values[value_index || 0] end |
#next_value ⇒ Object
Retreive the next value
108 109 110 111 112 113 114 115 |
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 108 def next_value value = $options.send(getter) return (value + @values[:increment]).clamp(@values[:min], @values[:max]) if @type == :slider value_index = @values.index(value) new_value = @values[(value_index || 0) + 1] new_value = @values.first if new_value.nil? return new_value end |
#prev_value ⇒ Object
Retreive the prev value
119 120 121 122 123 124 125 126 127 |
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 119 def prev_value value = $options.send(getter) return (value - @values[:increment]).clamp(@values[:min], @values[:max]) if @type == :slider value_index = @values.index(value) return @values.last if value_index == 0 new_value = @values[(value_index || 0) - 1] new_value = @values.first if new_value.nil? return new_value end |
#update_value(new_value)
Update the option value
131 132 133 134 135 136 137 |
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 131 def update_value(new_value) if @type != :slider value_index = @values.index(new_value) new_value = @values[value_index || 0] end $options.send(setter, new_value) end |