Class: RAGE::ResourcesManager
- Inherits:
-
Object
- Object
- RAGE::ResourcesManager
- Includes:
- Singleton
- Defined in:
- lib/rage/resource.rb
Overview
Singleton class managing all RAGE resources. Resources should be loaded here instead as opposed to creating them manually so as to mantain a central management repository during game execution.
Instance Attribute Summary collapse
-
#resources ⇒ Object
Hash of ids -> resources we are managing.
Instance Method Summary collapse
-
#initialize ⇒ ResourcesManager
constructor
A new instance of ResourcesManager.
-
#load_resource(args = {}) ⇒ Object
Load resource from specified args and add to manager.
Constructor Details
#initialize ⇒ ResourcesManager
Returns a new instance of ResourcesManager.
19 20 21 |
# File 'lib/rage/resource.rb', line 19 def initialize @resources = {} end |
Instance Attribute Details
#resources ⇒ Object
Hash of ids -> resources we are managing
17 18 19 |
# File 'lib/rage/resource.rb', line 17 def resources @resources end |
Instance Method Details
#load_resource(args = {}) ⇒ Object
Load resource from specified args and add to manager. Args may include
-
:type type of resource to load
-
:id unique identifier to give resource
-
:uri uri of resource if appropriate
-
:color resource color if appropriate
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rage/resource.rb', line 28 def load_resource(args = {}) type = args[:type] id = args[:id] resource = nil if type == :mesh uri = args[:uri] data = Loader.load uri resource = Mesh.new(data) elsif type == :text text = args[:text] resource = Text.new(:text => text) elsif type == :color color = args[:color] resource = Color.new(:rgb => color) # elsif other resource types end @resources[id] = resource return resource end |