Class: H3m::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/h3m/map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Map

Returns a new instance of Map.



16
17
18
19
# File 'lib/h3m/map.rb', line 16

def initialize(path)
  @path = path
  @gzip_file = File.new(path)
end

Instance Attribute Details

#pathObject (readonly)

Map representation

Example:

>> map = H3m::Map.new("some-map-file.h3m")
>> map.version
=> :SoD


14
15
16
# File 'lib/h3m/map.rb', line 14

def path
  @path
end

Instance Method Details

#descriptionObject



52
53
54
# File 'lib/h3m/map.rb', line 52

def description
  record.map_desc
end

#difficultyObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/h3m/map.rb', line 56

def difficulty
  @difficulty ||= case record.map_difficulty
    when 0 then :easy
    when 1 then :normal
    when 2 then :hard
    when 3 then :expert
    when 4 then :impossible
    else
      raise MapError, "unknown map difficulty"
  end
end

#fileObject



21
22
23
# File 'lib/h3m/map.rb', line 21

def file
  @file ||= Zlib::GzipReader.new(@gzip_file)
end

#has_subterranean?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/h3m/map.rb', line 68

def has_subterranean?
  record.map_has_subterranean != 0
end

#nameObject



48
49
50
# File 'lib/h3m/map.rb', line 48

def name
  record.map_name
end

#recordObject



72
73
74
# File 'lib/h3m/map.rb', line 72

def record
  @record ||= H3m::MapRecord.read(file)
end

#sizeObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/h3m/map.rb', line 37

def size
  @size ||= case record.map_size
    when 36  then :S
    when 72  then :M
    when 108 then :L
    when 144 then :XL
    else
      raise MapError, "unknown map size"
  end
end

#versionSymbol

Get extension

Returns:

  • (Symbol)

    :SoD, :AB or :RoE



27
28
29
30
31
32
33
34
35
# File 'lib/h3m/map.rb', line 27

def version
  @version ||= case record.heroes_version
    when 0x0E then :RoE
    when 0x15 then :AB
    when 0x1C then :SoD
    else
      raise MapError, "unknown map version"
  end
end