class Entityjs::Config

Public Class Methods

assets_folder() click to toggle source
# File lib/entityjs/config.rb, line 15
def self.assets_folder
  return 'assets'
end
build_folder() click to toggle source
# File lib/entityjs/config.rb, line 31
def self.build_folder
  return 'build'
end
file_name() click to toggle source
# File lib/entityjs/config.rb, line 7
def self.file_name
  'game.json'
end
images_folder() click to toggle source
# File lib/entityjs/config.rb, line 39
def self.images_folder
  self.assets_folder+'/images'
end
instance() click to toggle source
# File lib/entityjs/config.rb, line 43
def self.instance
  if @instance.nil?
    @instance = Config.new
  end
  
  return @instance
end
new() click to toggle source
# File lib/entityjs/config.rb, line 64
def initialize
  self.reload
end
preprocess(data, ops={}) click to toggle source
# File lib/entityjs/config.rb, line 11
def self.preprocess(data, ops={})
  self.instance.preprocess(data, ops)
end
scripts_folder() click to toggle source
# File lib/entityjs/config.rb, line 27
def self.scripts_folder
  return 'scripts'
end
sounds_folder() click to toggle source
# File lib/entityjs/config.rb, line 35
def self.sounds_folder
  self.assets_folder+'/sounds'
end
styles_folder() click to toggle source
# File lib/entityjs/config.rb, line 19
def self.styles_folder
  return 'styles'
end
tests_folder() click to toggle source
# File lib/entityjs/config.rb, line 23
def self.tests_folder
  'tests'
end

Public Instance Methods

assets_ignore() click to toggle source
# File lib/entityjs/config.rb, line 100
def assets_ignore
  return split_attr('assets-ignore')
end
build_assets_path() click to toggle source
# File lib/entityjs/config.rb, line 176
def build_assets_path
  return get_attr('build-assets-path', Config.assets_folder)
end
build_entity_ignore() click to toggle source
# File lib/entityjs/config.rb, line 124
def build_entity_ignore
  return split_attr('build-entity-ignore')
end
build_erase() click to toggle source

erases found lines on compiling NOT implemented

# File lib/entityjs/config.rb, line 114
def build_erase
  return split_attr('build-erase')
end
build_foot() click to toggle source
# File lib/entityjs/config.rb, line 164
def build_foot
  return get_attr('build-foot', '')
end
build_head() click to toggle source
# File lib/entityjs/config.rb, line 160
def build_head
  return get_attr('build-head', '')
end
build_ignore_play() click to toggle source
# File lib/entityjs/config.rb, line 168
def build_ignore_play
  return get_attr('build-ignore-play', nil)
end
build_name() click to toggle source
# File lib/entityjs/config.rb, line 128
def build_name
  return get_attr('build-name', self.title_slug+'.min')
end
build_path() click to toggle source
# File lib/entityjs/config.rb, line 172
def build_path
  return get_attr('build-path', Config.build_folder)
end
build_scripts_ignore() click to toggle source
# File lib/entityjs/config.rb, line 88
def build_scripts_ignore
  return split_attr('build-scripts-ignore')
end
build_scripts_name() click to toggle source
# 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() click to toggle source
# File lib/entityjs/config.rb, line 140
def build_styles_ignore
  return split_attr('build-styles-ignore')
end
build_styles_name() click to toggle source
# 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() click to toggle source
# File lib/entityjs/config.rb, line 180
def build_styles_path
  return get_attr('build-styles-path', Config.styles_folder)
end
build_vars() click to toggle source

overwrites config vars during compiling NOT implemented

# File lib/entityjs/config.rb, line 120
def build_vars

end
canvas_container() click to toggle source
# File lib/entityjs/config.rb, line 80
def canvas_container
  get_attr('canvas-container', 'canvas-container')
end
canvas_id() click to toggle source
# File lib/entityjs/config.rb, line 76
def canvas_id
  get_attr('canvas-id', 'game-canvas')
end
entity_ignore() click to toggle source
# File lib/entityjs/config.rb, line 108
def entity_ignore
  return split_attr('entity-ignore')
end
height() click to toggle source
# File lib/entityjs/config.rb, line 72
def height
  get_attr('height', 400)
end
license() click to toggle source
# 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={}) click to toggle source

replaces config variables in js/html strings with whats defined in config.json

say if the contents inside config.json were:
{"title":"My 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
});
# 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() click to toggle source
# 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() click to toggle source
# File lib/entityjs/config.rb, line 84
def scripts_ignore
  return split_attr('scripts-ignore')
end
scripts_order() click to toggle source
# File lib/entityjs/config.rb, line 96
def scripts_order
  return split_attr('scripts-order')
end
styles_ignore() click to toggle source
# File lib/entityjs/config.rb, line 156
def styles_ignore
  return split_attr('styles-ignore')
end
tests_entity_ignore() click to toggle source
# File lib/entityjs/config.rb, line 144
def tests_entity_ignore
  return split_attr('tests-entity-ignore')
end
tests_ignore() click to toggle source
# File lib/entityjs/config.rb, line 104
def tests_ignore
  return split_attr('tests-ignore')
end
tests_scripts_ignore() click to toggle source
# File lib/entityjs/config.rb, line 92
def tests_scripts_ignore
  return split_attr('tests-scripts-ignore')
end
title() click to toggle source
# File lib/entityjs/config.rb, line 148
def title
  return get_attr('title', 'game')
end
title_slug() click to toggle source
# File lib/entityjs/config.rb, line 152
def title_slug
  return title.downcase.gsub(' ', '-')
end
width() click to toggle source
# File lib/entityjs/config.rb, line 68
def width
  get_attr('width', 500)
end

Protected Instance Methods

get_attr(at, default=nil) click to toggle source

returns the wanted attr from data else returns the default

# File lib/entityjs/config.rb, line 237
def get_attr(at, default=nil)
  if @data.nil?
    return default
  end
  
  return @data[at] || default
end
split_attr(at) click to toggle source

returns the wanted attr in an array form

# File lib/entityjs/config.rb, line 246
def split_attr(at)
  if @data.nil?
    return []
  end
  
  y = @data[at]
  if !y.nil?
    if y.is_a? Array
      return y
    else
      return y.split(" ")
    end
  end
  return []
end