Class: Budgie::Selection

Inherits:
Object
  • Object
show all
Includes:
Index
Defined in:
lib/budgie/selection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Index

#from_index, #to_index

Constructor Details

#initializeSelection

Returns a new instance of Selection.



6
7
8
9
# File 'lib/budgie/selection.rb', line 6

def initialize
  @x = @y = @z = @normal_x = @normal_y = @normal_z = @r = @g = @b = 0
  @selected = false
end

Instance Attribute Details

#bObject

Returns the value of attribute b.



4
5
6
# File 'lib/budgie/selection.rb', line 4

def b
  @b
end

#gObject

Returns the value of attribute g.



4
5
6
# File 'lib/budgie/selection.rb', line 4

def g
  @g
end

#normal_xObject

Returns the value of attribute normal_x.



4
5
6
# File 'lib/budgie/selection.rb', line 4

def normal_x
  @normal_x
end

#normal_yObject

Returns the value of attribute normal_y.



4
5
6
# File 'lib/budgie/selection.rb', line 4

def normal_y
  @normal_y
end

#normal_zObject

Returns the value of attribute normal_z.



4
5
6
# File 'lib/budgie/selection.rb', line 4

def normal_z
  @normal_z
end

#rObject

Returns the value of attribute r.



4
5
6
# File 'lib/budgie/selection.rb', line 4

def r
  @r
end

#selectedObject

Returns the value of attribute selected.



4
5
6
# File 'lib/budgie/selection.rb', line 4

def selected
  @selected
end

#xObject

Returns the value of attribute x.



4
5
6
# File 'lib/budgie/selection.rb', line 4

def x
  @x
end

#yObject

Returns the value of attribute y.



4
5
6
# File 'lib/budgie/selection.rb', line 4

def y
  @y
end

#zObject

Returns the value of attribute z.



4
5
6
# File 'lib/budgie/selection.rb', line 4

def z
  @z
end

Instance Method Details

#from_color(r, g, b) ⇒ Object

Nothing is selected when color is [0, 0, 0] Everything else maps to [x, y, z] indexes of the map



25
26
27
28
29
30
31
32
# File 'lib/budgie/selection.rb', line 25

def from_color(r, g, b)
  @selected = r * g * b != 0
  if @selected
    @x = from_index(r - 1)
    @y = from_index(g - 1)
    @z = from_index(b - 1)
  end
end

#new_xObject



11
12
13
# File 'lib/budgie/selection.rb', line 11

def new_x
  @x + @normal_x
end

#new_yObject



15
16
17
# File 'lib/budgie/selection.rb', line 15

def new_y
  @y + @normal_y
end

#new_zObject



19
20
21
# File 'lib/budgie/selection.rb', line 19

def new_z
  @z + @normal_z
end

#normal_from_color(r, g, b) ⇒ Object

Cube normals can be [-1|0|1, -1|0|1, -1|0|1] Normals are encoded like [1|2|3, 1|2|3, 1|2|3]



36
37
38
39
40
# File 'lib/budgie/selection.rb', line 36

def normal_from_color(r, g, b)
  @normal_x = r - 2
  @normal_y = g - 2
  @normal_z = b - 2
end