Class: WolfRpg::Map::Event

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

Defined Under Namespace

Classes: Page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(coder) ⇒ Event

Returns a new instance of Event.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/wolfrpg/map.rb', line 93

def initialize(coder)
  coder.verify(MAGIC_NUMBER1)
  @id = coder.read_int
  @name = coder.read_string
  @x = coder.read_int
  @y = coder.read_int
  @pages = Array.new(coder.read_int)
  coder.verify(MAGIC_NUMBER2)

  # Read pages
  page_id = 0
  while (indicator = coder.read_byte) == 0x79
    page = Page.new(coder, page_id)
    @pages[page_id] = page
    page_id += 1
  end
  if indicator != 0x70
    raise "unexpected event page indicator: #{indicator.to_s(16)}"
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



87
88
89
# File 'lib/wolfrpg/map.rb', line 87

def id
  @id
end

#nameObject

Returns the value of attribute name.



88
89
90
# File 'lib/wolfrpg/map.rb', line 88

def name
  @name
end

#pagesObject

Returns the value of attribute pages.



91
92
93
# File 'lib/wolfrpg/map.rb', line 91

def pages
  @pages
end

#xObject

Returns the value of attribute x.



89
90
91
# File 'lib/wolfrpg/map.rb', line 89

def x
  @x
end

#yObject

Returns the value of attribute y.



90
91
92
# File 'lib/wolfrpg/map.rb', line 90

def y
  @y
end

Instance Method Details

#dump(coder) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/wolfrpg/map.rb', line 114

def dump(coder)
  coder.write(MAGIC_NUMBER1)
  coder.write_int(@id)
  coder.write_string(@name)
  coder.write_int(@x)
  coder.write_int(@y)
  coder.write_int(@pages.size)
  coder.write(MAGIC_NUMBER2)

  # Write pages
  @pages.each do |page|
    coder.write_byte(0x79)
    page.dump(coder)
  end
  coder.write_byte(0x70)
end