Sha256: f9e9dd3f872bd18a9f49c6d9bfdd34acf1b28e5f6c5b0308373df173332361e4

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

module GameMachine
  class Grid

    class << self

      def config
        if @config
          return @config
        else
          @config = java.util.concurrent.ConcurrentHashMap.new
        end
      end

      def update_frequency_for(name)
        config.fetch(name)[:update_frequency]
      end

      def load_from_config
        ['default','local_chat','aoe'].each do |name|
           value = Application.config.grids.send(name.to_sym)
          grid_size,cell_size,update_frequency = value.split(',')
          config[name] = {
            :grid_size => grid_size.to_i,
            :cell_size => cell_size.to_i,
            :update_frequency => update_frequency.to_i
          }
          find_or_create(name)
        end
      end

      def reset_grids
        JavaLib::Grid.reset_grids
      end

      def default_grid
        find_or_create('default')
      end

      def find_or_create(name)
        grid_config = config.fetch(name)
        JavaLib::Grid.find_or_create(name,grid_config.fetch(:grid_size),
                                   grid_config.fetch(:cell_size))
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
game_machine-1.0.4 lib/game_machine/grid.rb
game_machine-1.0.2 lib/game_machine/grid.rb