Class: GamePlay::Options::Helper

Inherits:
Object
  • Object
show all
Defined in:
scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Helper

Create a new option

Parameters:

  • args (Array)

    options arguments



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

#descriptionString

Option description

Returns:



75
76
77
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 75

def description
  @description
end

#getterSymbol (readonly)

Option getter (on $options)

Returns:

  • (Symbol)


78
79
80
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 78

def getter
  @getter
end

#nameString

Option name

Returns:



72
73
74
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 72

def name
  @name
end

#setterSymbol (readonly)

Option setter (on $options)

Returns:

  • (Symbol)


81
82
83
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 81

def setter
  @setter
end

#typeSymbol (readonly)

Option type

Returns:

  • (Symbol)


63
64
65
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 63

def type
  @type
end

#valuesArray (readonly)

Option values

Returns:

  • (Array)


66
67
68
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 66

def values
  @values
end

#values_textArray<String>, String

Option value text(s)

Returns:



69
70
71
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/00011 Options_Helper.rb', line 69

def values_text
  @values_text
end

Instance Method Details

#current_valueObject

Retreive the current value

Returns:



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_valueObject

Retreive the next value

Returns:



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_valueObject

Retreive the prev value

Returns:



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

Parameters:



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