Class: Section
- Inherits:
-
Object
- Object
- Section
- Defined in:
- lib/IFMapper/Section.rb
Direct Known Subclasses
Defined Under Namespace
Classes: ConnectionError
Instance Attribute Summary collapse
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#connections ⇒ Object
Returns the value of attribute connections.
-
#name ⇒ Object
Returns the value of attribute name.
-
#rooms ⇒ Object
Returns the value of attribute rooms.
Instance Method Summary collapse
-
#delete_connection(c) ⇒ Object
Delete a connection from section.
-
#delete_connection_at(idx) ⇒ Object
Delete a connection at a certain index location.
-
#delete_room(r) ⇒ Object
Delete a room and all of its connections.
-
#delete_room_at(idx) ⇒ Object
Delete a room at a certain index.
-
#delete_room_only(r) ⇒ Object
Delete a room, leaving its connections intact.
-
#free?(x, y) ⇒ Boolean
Return true or false if map is free at location x,y.
-
#initialize ⇒ Section
constructor
A new instance of Section.
- #marshal_dump ⇒ Object
- #marshal_load(v) ⇒ Object
-
#min_max_rooms ⇒ Object
Return the min and max coordinates of all rooms in page.
-
#new_connection(roomA, exitA, roomB, exitB = nil) ⇒ Object
Create a new connection among two rooms thru their exits.
-
#new_room(x, y) ⇒ Object
Create a new room (note: FXSection overrides this creating an FXRoom instead).
-
#rooms_width_height ⇒ Object
Return the number of rooms in width and height for this page.
-
#shift(x, y, dx, dy) ⇒ Object
Shift rooms in dx and dy direction from x,y position on.
Constructor Details
#initialize ⇒ Section
Returns a new instance of Section.
176 177 178 179 180 181 |
# File 'lib/IFMapper/Section.rb', line 176 def initialize() @rooms = [] @connections = [] @name = '' @comments = '' end |
Instance Attribute Details
#comments ⇒ Object
Returns the value of attribute comments.
10 11 12 |
# File 'lib/IFMapper/Section.rb', line 10 def comments @comments end |
#connections ⇒ Object
Returns the value of attribute connections.
8 9 10 |
# File 'lib/IFMapper/Section.rb', line 8 def connections @connections end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/IFMapper/Section.rb', line 9 def name @name end |
#rooms ⇒ Object
Returns the value of attribute rooms.
7 8 9 |
# File 'lib/IFMapper/Section.rb', line 7 def rooms @rooms end |
Instance Method Details
#delete_connection(c) ⇒ Object
Delete a connection from section
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/IFMapper/Section.rb', line 86 def delete_connection(c) a = c.roomA if a e = a.exits.index(c) a[e] = nil if e end b = c.roomB if b e = b.exits.rindex(c) b[e] = nil if e end @connections.delete(c) end |
#delete_connection_at(idx) ⇒ Object
Delete a connection at a certain index location
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/IFMapper/Section.rb', line 103 def delete_connection_at( idx ) c = @connections[idx] a = c.roomA if a e = a.exits.index(c) a[e] = nil if e end b = c.roomB if b e = b.exits.rindex(c) b[e] = nil if e end @connections.delete_at(idx) end |
#delete_room(r) ⇒ Object
Delete a room and all of its connections
159 160 161 162 163 164 165 |
# File 'lib/IFMapper/Section.rb', line 159 def delete_room(r) r.exits.each { |e| next if not e delete_connection(e) } delete_room_only(r) end |
#delete_room_at(idx) ⇒ Object
Delete a room at a certain index
140 141 142 143 144 145 146 147 |
# File 'lib/IFMapper/Section.rb', line 140 def delete_room_at(idx) r = @rooms[idx] r.exits.each { |e| next if not e delete_connection(e) } @rooms.delete_at(idx) end |
#delete_room_only(r) ⇒ Object
Delete a room, leaving its connections intact
152 153 154 |
# File 'lib/IFMapper/Section.rb', line 152 def delete_room_only(r) @rooms.delete(r) end |
#free?(x, y) ⇒ Boolean
Return true or false if map is free at location x,y
56 57 58 59 60 61 |
# File 'lib/IFMapper/Section.rb', line 56 def free?(x,y) @rooms.each { |r| return false if r.x == x and r.y == y } return true end |
#marshal_dump ⇒ Object
21 22 23 |
# File 'lib/IFMapper/Section.rb', line 21 def marshal_dump return [ @rooms, @connections, @name, @comments ] end |
#marshal_load(v) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/IFMapper/Section.rb', line 14 def marshal_load(v) @rooms = v[0] @connections = v[1] @name = v[2] @comments = v[3] end |
#min_max_rooms ⇒ Object
Return the min and max coordinates of all rooms in page
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/IFMapper/Section.rb', line 39 def min_max_rooms return [[0, 0],[0, 0]] if @rooms.empty? minXY = [ @rooms[0].x, @rooms[0].y ] maxXY = minXY.dup @rooms.each { |r| minXY[0] = r.x if r.x < minXY[0] minXY[1] = r.y if r.y < minXY[1] maxXY[0] = r.x if r.x > maxXY[0] maxXY[1] = r.y if r.y > maxXY[1] } return [ minXY, maxXY ] end |
#new_connection(roomA, exitA, roomB, exitB = nil) ⇒ Object
Create a new connection among two rooms thru their exits
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/IFMapper/Section.rb', line 122 def new_connection( roomA, exitA, roomB, exitB = nil ) # Verify rooms exist in section (ie. don't allow links across # sections) if not @rooms.include?(roomA) raise ConnectionError, "Room '#{roomA}' not in section #{self}" end if roomB and not @rooms.include?(roomB) raise ConnectionError, "Room '#{roomB}' not in section #{self}" end c = Connection.new( roomA, roomB ) _new_connection( c, roomA, exitA, roomB, exitB ) end |
#new_room(x, y) ⇒ Object
Create a new room (note: FXSection overrides this creating an FXRoom instead).
171 172 173 174 |
# File 'lib/IFMapper/Section.rb', line 171 def new_room( x, y ) r = Room.new( x, y, 'New Location' ) return _new_room(r, x, y) end |
#rooms_width_height ⇒ Object
Return the number of rooms in width and height for this page
28 29 30 31 32 33 34 |
# File 'lib/IFMapper/Section.rb', line 28 def rooms_width_height minXY, maxXY = min_max_rooms return [ maxXY[0] - minXY[0] + 1, maxXY[1] - minXY[1] + 1 ] end |
#shift(x, y, dx, dy) ⇒ Object
Shift rooms in dx and dy direction from x,y position on.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/IFMapper/Section.rb', line 66 def shift(x, y, dx, dy) @rooms.each { |r| ox = oy = 0 if (dx < 0 and r.x <= x) or (dx > 0 and r.x >= x) ox = dx end if (dy < 0 and r.y <= y) or (dy > 0 and r.y >= y) oy = dy end r.x += ox r.y += oy } end |