Class: Savio::Scene

Inherits:
Object
  • Object
show all
Defined in:
lib/savio/Scene.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, color = 'black') ⇒ Scene

Returns a new instance of Scene.



4
5
6
7
8
# File 'lib/savio/Scene.rb', line 4

def initialize(file, color = 'black')
  @file = file
  @color = color
  show()
end

Instance Attribute Details

#elementsObject

Returns the value of attribute elements.



3
4
5
# File 'lib/savio/Scene.rb', line 3

def elements
  @elements
end

Instance Method Details

#removeObject



48
49
50
51
52
53
# File 'lib/savio/Scene.rb', line 48

def remove()
  @bg.remove
  @elements.each do |e|
    e.kill()
  end
end

#showObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/savio/Scene.rb', line 10

def show()
  @bg = Square.new(x: 0, y: 0, z: 999, size: Window.width+1, color: @color)
  @elements = []
  content = File.read(@file)
  content = content.gsub('[', "").gsub(']', "").gsub('"',"").chomp.split(",")

  (content.count-1).times do |i|
    if (i % 2) == 0
      classType = Object.const_get(content[i].gsub(" ",""))
      hash = content[i+1].gsub(';', ',').gsub('"',"").chomp
      pairs = hash.split(",").to_s.gsub('"',"").chomp
      keypair = pairs.split("=>").to_s.gsub('"',"").chomp
      new = keypair.gsub('{', "").gsub('}', "").gsub('[', "").gsub(']', "").gsub('"',"").gsub(" ","").chomp.split(",")
      build = {}
      (new.count-1).times do |j|
        if (j % 2) == 0
          case Savio.guessType(new[j+1].chomp)
          when "int"
            value = new[j+1].chomp.to_i
          when "float"
            value = new[j+1].chomp.to_f
          when "str"
            value = new[j+1].chomp.to_s
          when "bool"
            value = Savio.makeBool(new[j+1].chomp)
          end
          build[new[j].intern] = value
        end
      end
      puts "SCENE: " + @file.to_s + build.to_s
      @elements.push(classType.new(build))
    end
  end
  @elements.each do |e|
    e.z = 1000
  end
end