Class: Core::Song

Inherits:
Object show all
Defined in:
lib/song.rb

Overview

cache system borks inheritance, so we need to wrap a Gosu::Song instance

Constant Summary collapse

@@cache =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Song

Returns a new instance of Song.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/song.rb', line 7

def initialize(file)
  @file = file
  if @@cache[file]
    @song = @@cache[file]
    return
  end
  begin
    @song = Gosu::Song.new(Core.window, "#{Core::LIBRARY_PATH}/music/#{file}.mp3")
    @@cache.store(file, @song)
  rescue RuntimeError
    puts("ERROR: Failed to open music #{file}")
    return
  end
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/song.rb', line 5

def file
  @file
end

Instance Method Details

#pauseObject



27
28
29
# File 'lib/song.rb', line 27

def pause
  @song.pause
end

#play(loop = true) ⇒ Object



36
37
38
39
# File 'lib/song.rb', line 36

def play(loop=true)
  @song.volume = Core.config[:volume]+1.0 # FIXME no effect?
  @song.play(loop)
end

#songObject



21
22
23
# File 'lib/song.rb', line 21

def song
  return @song
end

#stopObject



24
25
26
# File 'lib/song.rb', line 24

def stop
  @song.stop
end

#volumeObject



30
31
32
# File 'lib/song.rb', line 30

def volume
  return @song.volume
end

#volume=(vol) ⇒ Object



33
34
35
# File 'lib/song.rb', line 33

def volume=(vol)
  @song.volume = vol
end