Class: ShatteredView::Resources

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/shattered_view/resources.rb

Overview

Resource Handler is the ruby binding around Ogre’s resource handler It provides all types of shortcuts for finding files and adding new paths.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResources

Returns a new instance of Resources.



11
12
13
# File 'lib/shattered_view/resources.rb', line 11

def initialize
  @resource_paths=[]
end

Instance Attribute Details

#resource_pathsObject (readonly)

Instance Methods



10
11
12
# File 'lib/shattered_view/resources.rb', line 10

def resource_paths
  @resource_paths
end

Instance Method Details

#add_resource_paths(*paths) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/shattered_view/resources.rb', line 15

def add_resource_paths(*paths)
  paths.each do |path|
  	next if path.nil?
    path = SHATTERED_ROOT + "/"+path
    @resource_paths << path
    each_directory_in_path(path) do |sub_path|  
    	Ogre::ResourceGroupManager.instance.add_resource_location(sub_path, "FileSystem", "General")
    end
  end
end

#destroy_pathsObject



35
36
37
# File 'lib/shattered_view/resources.rb', line 35

def destroy_paths
  @resource_paths = []
end

#each_directory_in_path(path, &block) ⇒ Object

This is deprecated in favor of Dir.each_in_path



53
54
55
# File 'lib/shattered_view/resources.rb', line 53

def each_directory_in_path(path,&block)
  Dir.each_in_path(path, &block)
end

#each_file_in_path(path, &block) ⇒ Object

This is deprecated in favor of File.each_in_path



48
49
50
# File 'lib/shattered_view/resources.rb', line 48

def each_file_in_path(path, &block)
  File.each_in_path(path, &block)
end

#find_file(filename) ⇒ Object

find a particular file in the resource paths



58
59
60
# File 'lib/shattered_view/resources.rb', line 58

def find_file(filename)
  File.find(@resource_paths, filename)
end

#find_files_by_extensions(*extensions) ⇒ Object

This is useful for any extension wanting to load resource files:

Usage:

Resources.instance.find_files_by_extensions("ogg","mp3","wav")


43
44
45
# File 'lib/shattered_view/resources.rb', line 43

def find_files_by_extensions(*extensions)
  File.find_by_extensions(@resource_paths,*extensions)
end

#setupObject

Called once all resource groups have been added



27
28
29
30
31
32
33
# File 'lib/shattered_view/resources.rb', line 27

def setup
 	begin
	Ogre::ResourceGroupManager::instance.initialise_all_resource_groups
	rescue StandardError => bang
		puts "WARNING #{bang.message}"
end
end