Class: Shattered::Resources

Inherits:
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
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_pathsObject



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

#setupObject

Called once all resource groups have been added



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

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