config/initializers/rhex_patch.rb
# Read an ascii file and load it into the hexagon grid. The input grid is supposed to be odd flat topped (odd-q) and will be stored into an axial representation.
#
# @param file_path [String] the name of the ascii file to read. For how to create this file, please see : https://github.com/czuger/rhex#reading-a-grid-from-an-ascii-file
Read an ascii file and load it into the hexagon grid. The input grid is supposed to be odd flat topped (odd-q) and will be stored into an axial representation.
Read an ascii file and load it into the hexagon grid . The input grid is supposed to be odd flat topped ( odd - q ) and will be stored into an axial representation .
def read_ascii_file_flat_topped_odd( file_path )
    File.open( file_path ) do |file|
      odd = 0
      base_q = 0
      line_q = 0
      file.each_line do |line|
        elements = line.split
        elements.each_with_index do |element, index|
          q = index*2 + odd
          r = base_q - index
          @hexes[ [ q, r ] ] = AxialHex.new( q, r, data: { color: element.to_sym } )
        end
        odd = ( odd.odd? ? 0 : 1 )
        line_q += 1
        if line_q >= 2
          line_q = 0
          base_q += 1
        end
      end
    end
  end
def read_ascii_file_flat_topped_odd ( file_path ) File . open ( file_path ) do | file | odd = 0 base_q = 0 line_q = 0 file . each_line do | line | elements = line . split elements . each_with_index do | element , index | q = index * 2 + odd r = base_q - index @hexes [ [ q , r ] ] = AxialHex . new ( q , r , data : { color : element . to_sym } ) end odd = ( odd . odd? ? 0 : 1 ) line_q += 1 if line_q >= 2 line_q = 0 base_q += 1 end end end end
Read an ascii file and load it into the hexagon grid.
Read an ascii file and load it into the hexagon grid .
# puts "element = %c, index = %d || q = %d, r = %d" % [element, index, index*2 + odd, base_q - index] # cset( index*2 + odd, base_q - index, color: element.to_sym, border: nil )
file_path
the name of the ascii file to read.
the name of the ascii file to read .