Class: Shattered::Resources
- 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
-
#resource_paths ⇒ Object
readonly
Instance Methods.
Instance Method Summary collapse
- #add_resource_paths(*paths) ⇒ Object
- #destroy_paths ⇒ Object
-
#each_directory_in_path(path, &block) ⇒ Object
This is deprecated in favor of Dir.each_in_path.
-
#each_file_in_path(path, &block) ⇒ Object
This is deprecated in favor of File.each_in_path.
-
#find_file(filename) ⇒ Object
find a particular file in the resource paths.
-
#find_files_by_extensions(*extensions) ⇒ Object
This is useful for any extension wanting to load resource files:.
-
#initialize ⇒ Resources
constructor
A new instance of Resources.
-
#setup ⇒ Object
Called once all resource groups have been added.
Constructor Details
#initialize ⇒ Resources
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_paths ⇒ Object (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 25 |
# 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 unless 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_paths ⇒ Object
36 37 38 |
# File 'lib/shattered_view/resources.rb', line 36 def destroy_paths @resource_paths = [] end |
#each_directory_in_path(path, &block) ⇒ Object
This is deprecated in favor of Dir.each_in_path
54 55 56 |
# File 'lib/shattered_view/resources.rb', line 54 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
49 50 51 |
# File 'lib/shattered_view/resources.rb', line 49 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
59 60 61 |
# File 'lib/shattered_view/resources.rb', line 59 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")
44 45 46 |
# File 'lib/shattered_view/resources.rb', line 44 def find_files_by_extensions(*extensions) File.find_by_extensions(@resource_paths,*extensions) end |