Class: Entityjs::Config
- Inherits:
-
Object
- Object
- Entityjs::Config
- Defined in:
- lib/entityjs/config.rb
Class Method Summary collapse
- .assets_folder ⇒ Object
- .build_folder ⇒ Object
- .file_name ⇒ Object
- .images_folder ⇒ Object
- .instance ⇒ Object
- .preprocess(data, ops = {}) ⇒ Object
- .scripts_folder ⇒ Object
- .sounds_folder ⇒ Object
- .styles_folder ⇒ Object
- .tests_folder ⇒ Object
Instance Method Summary collapse
- #assets_ignore ⇒ Object
- #build_assets_path ⇒ Object
- #build_entity_ignore ⇒ Object
-
#build_erase ⇒ Object
erases found lines on compiling NOT implemented.
- #build_foot ⇒ Object
- #build_head ⇒ Object
- #build_ignore_play ⇒ Object
- #build_name ⇒ Object
- #build_path ⇒ Object
- #build_scripts_ignore ⇒ Object
- #build_scripts_name ⇒ Object
- #build_styles_ignore ⇒ Object
- #build_styles_name ⇒ Object
- #build_styles_path ⇒ Object
-
#build_vars ⇒ Object
overwrites config vars during compiling NOT implemented.
- #canvas_container ⇒ Object
- #canvas_id ⇒ Object
- #entity_ignore ⇒ Object
- #height ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #license ⇒ Object
-
#preprocess(contents, ops = {}) ⇒ Object
replaces config variables in js/html strings with whats defined in config.json say if the contents inside config.json were: Game” All js and html files with the word RE_TITLE will be replaced with My Game example, inside init.js: re.ready(function(){ re.title = “RE_TITLE”; //this will be replaced re.RE_TITLE //this will be replaced with My Game });.
- #reload ⇒ Object
- #scripts_ignore ⇒ Object
- #scripts_order ⇒ Object
- #styles_ignore ⇒ Object
- #tests_entity_ignore ⇒ Object
- #tests_ignore ⇒ Object
- #tests_scripts_ignore ⇒ Object
- #title ⇒ Object
- #title_slug ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
64 65 66 |
# File 'lib/entityjs/config.rb', line 64 def initialize self.reload end |
Class Method Details
.assets_folder ⇒ Object
15 16 17 |
# File 'lib/entityjs/config.rb', line 15 def self.assets_folder return 'assets' end |
.build_folder ⇒ Object
31 32 33 |
# File 'lib/entityjs/config.rb', line 31 def self.build_folder return 'build' end |
.file_name ⇒ Object
7 8 9 |
# File 'lib/entityjs/config.rb', line 7 def self.file_name 'game.json' end |
.images_folder ⇒ Object
39 40 41 |
# File 'lib/entityjs/config.rb', line 39 def self.images_folder self.assets_folder+'/images' end |
.instance ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/entityjs/config.rb', line 43 def self.instance if @instance.nil? @instance = Config.new end return @instance end |
.preprocess(data, ops = {}) ⇒ Object
11 12 13 |
# File 'lib/entityjs/config.rb', line 11 def self.preprocess(data, ops={}) self.instance.preprocess(data, ops) end |
.scripts_folder ⇒ Object
27 28 29 |
# File 'lib/entityjs/config.rb', line 27 def self.scripts_folder return 'scripts' end |
.sounds_folder ⇒ Object
35 36 37 |
# File 'lib/entityjs/config.rb', line 35 def self.sounds_folder self.assets_folder+'/sounds' end |
.styles_folder ⇒ Object
19 20 21 |
# File 'lib/entityjs/config.rb', line 19 def self.styles_folder return 'styles' end |
.tests_folder ⇒ Object
23 24 25 |
# File 'lib/entityjs/config.rb', line 23 def self.tests_folder 'tests' end |
Instance Method Details
#assets_ignore ⇒ Object
100 101 102 |
# File 'lib/entityjs/config.rb', line 100 def assets_ignore return split_attr('assets-ignore') end |
#build_assets_path ⇒ Object
176 177 178 |
# File 'lib/entityjs/config.rb', line 176 def build_assets_path return get_attr('build-assets-path', Config.assets_folder) end |
#build_entity_ignore ⇒ Object
124 125 126 |
# File 'lib/entityjs/config.rb', line 124 def build_entity_ignore return split_attr('build-entity-ignore') end |
#build_erase ⇒ Object
erases found lines on compiling NOT implemented
114 115 116 |
# File 'lib/entityjs/config.rb', line 114 def build_erase return split_attr('build-erase') end |
#build_foot ⇒ Object
164 165 166 |
# File 'lib/entityjs/config.rb', line 164 def build_foot return get_attr('build-foot', '') end |
#build_head ⇒ Object
160 161 162 |
# File 'lib/entityjs/config.rb', line 160 def build_head return get_attr('build-head', '') end |
#build_ignore_play ⇒ Object
168 169 170 |
# File 'lib/entityjs/config.rb', line 168 def build_ignore_play return get_attr('build-ignore-play', nil) end |
#build_name ⇒ Object
128 129 130 |
# File 'lib/entityjs/config.rb', line 128 def build_name return get_attr('build-name', self.title_slug+'.min') end |
#build_path ⇒ Object
172 173 174 |
# File 'lib/entityjs/config.rb', line 172 def build_path return get_attr('build-path', Config.build_folder) end |
#build_scripts_ignore ⇒ Object
88 89 90 |
# File 'lib/entityjs/config.rb', line 88 def build_scripts_ignore return split_attr('build-scripts-ignore') end |
#build_scripts_name ⇒ Object
132 133 134 |
# File 'lib/entityjs/config.rb', line 132 def build_scripts_name return get_attr('build-scripts-name', self.build_name+'.js') end |
#build_styles_ignore ⇒ Object
140 141 142 |
# File 'lib/entityjs/config.rb', line 140 def build_styles_ignore return split_attr('build-styles-ignore') end |
#build_styles_name ⇒ Object
136 137 138 |
# File 'lib/entityjs/config.rb', line 136 def build_styles_name return get_attr('build-styles-name', self.build_name+'.css') end |
#build_styles_path ⇒ Object
180 181 182 |
# File 'lib/entityjs/config.rb', line 180 def build_styles_path return get_attr('build-styles-path', Config.styles_folder) end |
#build_vars ⇒ Object
overwrites config vars during compiling NOT implemented
120 121 122 |
# File 'lib/entityjs/config.rb', line 120 def build_vars end |
#canvas_container ⇒ Object
80 81 82 |
# File 'lib/entityjs/config.rb', line 80 def canvas_container get_attr('canvas-container', 'canvas-container') end |
#canvas_id ⇒ Object
76 77 78 |
# File 'lib/entityjs/config.rb', line 76 def canvas_id get_attr('canvas-id', 'game-canvas') end |
#entity_ignore ⇒ Object
108 109 110 |
# File 'lib/entityjs/config.rb', line 108 def entity_ignore return split_attr('entity-ignore') end |
#height ⇒ Object
72 73 74 |
# File 'lib/entityjs/config.rb', line 72 def height get_attr('height', 400) end |
#license ⇒ Object
184 185 186 187 188 189 190 |
# File 'lib/entityjs/config.rb', line 184 def license contents = IO.read(Entityjs::root+'/license.txt') contents = contents.sub(/\$VERSION/, Entityjs::VERSION) return contents+"\n" end |
#preprocess(contents, ops = {}) ⇒ Object
replaces config variables in js/html strings with whats defined in config.json say if the contents inside config.json were: Game” All js and html files with the word RE_TITLE will be replaced with My Game example, inside init.js: re.ready(function()
re.title = "RE_TITLE"; //this will be replaced
re.RE_TITLE //this will be replaced with My Game
);
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/entityjs/config.rb', line 201 def preprocess(contents, ops={}) #reload config for changes self.reload attrs = @data || {} #setup default attrs attrs['canvas-id'] = self.canvas_id attrs['width'] = self.width attrs['height'] = self.height attrs['title'] = self.title attrs['canvas-container'] = self.canvas_container attrs.each do |k,v| val = k.upcase if val == 'JS' || val == 'CSS' puts "Warning cannot use JS or CSS as config key. Rename it to something else!" end contents = contents.gsub("RE_#{val}", v.to_s) end #build erase #set width, height and canvas id #contents = contents.sub("RE_WIDTH", Config.instance.width.to_s) #contents = contents.sub("RE_HEIGHT", Config.instance.height.to_s) #contents = contents.sub("RE_CANVAS_ID", Config.instance.canvas_id) return contents end |
#reload ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/entityjs/config.rb', line 51 def reload if File.exists?('config.yml') puts "Warning: config.yml will be deprecated soon. Rename to #{Config.file_name}" @data = YAML::load(IO.read('config.yml')) elsif File.exists?(Config.file_name) data = IO.read(Config.file_name) @data = JSON::parse(data) end end |
#scripts_ignore ⇒ Object
84 85 86 |
# File 'lib/entityjs/config.rb', line 84 def scripts_ignore return split_attr('scripts-ignore') end |
#scripts_order ⇒ Object
96 97 98 |
# File 'lib/entityjs/config.rb', line 96 def scripts_order return split_attr('scripts-order') end |
#styles_ignore ⇒ Object
156 157 158 |
# File 'lib/entityjs/config.rb', line 156 def styles_ignore return split_attr('styles-ignore') end |
#tests_entity_ignore ⇒ Object
144 145 146 |
# File 'lib/entityjs/config.rb', line 144 def tests_entity_ignore return split_attr('tests-entity-ignore') end |
#tests_ignore ⇒ Object
104 105 106 |
# File 'lib/entityjs/config.rb', line 104 def tests_ignore return split_attr('tests-ignore') end |
#tests_scripts_ignore ⇒ Object
92 93 94 |
# File 'lib/entityjs/config.rb', line 92 def tests_scripts_ignore return split_attr('tests-scripts-ignore') end |
#title ⇒ Object
148 149 150 |
# File 'lib/entityjs/config.rb', line 148 def title return get_attr('title', 'game') end |
#title_slug ⇒ Object
152 153 154 |
# File 'lib/entityjs/config.rb', line 152 def title_slug return title.downcase.gsub(' ', '-') end |
#width ⇒ Object
68 69 70 |
# File 'lib/entityjs/config.rb', line 68 def width get_attr('width', 500) end |