Class: Entityjs::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/entityjs/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

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_folderObject



15
16
17
# File 'lib/entityjs/config.rb', line 15

def self.assets_folder
  return 'assets'
end

.build_folderObject



31
32
33
# File 'lib/entityjs/config.rb', line 31

def self.build_folder
  return 'build'
end

.file_nameObject



7
8
9
# File 'lib/entityjs/config.rb', line 7

def self.file_name
  'game.json'
end

.images_folderObject



39
40
41
# File 'lib/entityjs/config.rb', line 39

def self.images_folder
  self.assets_folder+'/images'
end

.instanceObject



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_folderObject



27
28
29
# File 'lib/entityjs/config.rb', line 27

def self.scripts_folder
  return 'scripts'
end

.sounds_folderObject



35
36
37
# File 'lib/entityjs/config.rb', line 35

def self.sounds_folder
  self.assets_folder+'/sounds'
end

.styles_folderObject



19
20
21
# File 'lib/entityjs/config.rb', line 19

def self.styles_folder
  return 'styles'
end

.tests_folderObject



23
24
25
# File 'lib/entityjs/config.rb', line 23

def self.tests_folder
  'tests'
end

Instance Method Details

#assets_ignoreObject



100
101
102
# File 'lib/entityjs/config.rb', line 100

def assets_ignore
  return split_attr('assets-ignore')
end

#build_assets_pathObject



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_ignoreObject



124
125
126
# File 'lib/entityjs/config.rb', line 124

def build_entity_ignore
  return split_attr('build-entity-ignore')
end

#build_eraseObject

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_footObject



164
165
166
# File 'lib/entityjs/config.rb', line 164

def build_foot
  return get_attr('build-foot', '')
end

#build_headObject



160
161
162
# File 'lib/entityjs/config.rb', line 160

def build_head
  return get_attr('build-head', '')
end

#build_ignore_playObject



168
169
170
# File 'lib/entityjs/config.rb', line 168

def build_ignore_play
  return get_attr('build-ignore-play', nil)
end

#build_nameObject



128
129
130
# File 'lib/entityjs/config.rb', line 128

def build_name
  return get_attr('build-name', self.title_slug+'.min')
end

#build_pathObject



172
173
174
# File 'lib/entityjs/config.rb', line 172

def build_path
  return get_attr('build-path', Config.build_folder)
end

#build_scripts_ignoreObject



88
89
90
# File 'lib/entityjs/config.rb', line 88

def build_scripts_ignore
  return split_attr('build-scripts-ignore')
end

#build_scripts_nameObject



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_ignoreObject



140
141
142
# File 'lib/entityjs/config.rb', line 140

def build_styles_ignore
  return split_attr('build-styles-ignore')
end

#build_styles_nameObject



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_pathObject



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_varsObject

overwrites config vars during compiling NOT implemented



120
121
122
# File 'lib/entityjs/config.rb', line 120

def build_vars

end

#canvas_containerObject



80
81
82
# File 'lib/entityjs/config.rb', line 80

def canvas_container
  get_attr('canvas-container', 'canvas-container')
end

#canvas_idObject



76
77
78
# File 'lib/entityjs/config.rb', line 76

def canvas_id
  get_attr('canvas-id', 'game-canvas')
end

#entity_ignoreObject



108
109
110
# File 'lib/entityjs/config.rb', line 108

def entity_ignore
  return split_attr('entity-ignore')
end

#heightObject



72
73
74
# File 'lib/entityjs/config.rb', line 72

def height
  get_attr('height', 400)
end

#licenseObject



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

#reloadObject



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_ignoreObject



84
85
86
# File 'lib/entityjs/config.rb', line 84

def scripts_ignore
  return split_attr('scripts-ignore')
end

#scripts_orderObject



96
97
98
# File 'lib/entityjs/config.rb', line 96

def scripts_order
  return split_attr('scripts-order')
end

#styles_ignoreObject



156
157
158
# File 'lib/entityjs/config.rb', line 156

def styles_ignore
  return split_attr('styles-ignore')
end

#tests_entity_ignoreObject



144
145
146
# File 'lib/entityjs/config.rb', line 144

def tests_entity_ignore
  return split_attr('tests-entity-ignore')
end

#tests_ignoreObject



104
105
106
# File 'lib/entityjs/config.rb', line 104

def tests_ignore
  return split_attr('tests-ignore')
end

#tests_scripts_ignoreObject



92
93
94
# File 'lib/entityjs/config.rb', line 92

def tests_scripts_ignore
  return split_attr('tests-scripts-ignore')
end

#titleObject



148
149
150
# File 'lib/entityjs/config.rb', line 148

def title
  return get_attr('title', 'game')
end

#title_slugObject



152
153
154
# File 'lib/entityjs/config.rb', line 152

def title_slug
  return title.downcase.gsub(' ', '-')
end

#widthObject



68
69
70
# File 'lib/entityjs/config.rb', line 68

def width
  get_attr('width', 500)
end