ifmapper 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.txt +26 -0
- data/IFMapper.gemspec +1 -1
- data/icons/room_e.gif +0 -0
- data/icons/room_e.xpm +39 -0
- data/icons/room_n.gif +0 -0
- data/icons/room_n.xpm +40 -0
- data/icons/room_ne.gif +0 -0
- data/icons/room_ne.xpm +80 -0
- data/icons/room_nw.gif +0 -0
- data/icons/room_nw.xpm +80 -0
- data/icons/room_s.gif +0 -0
- data/icons/room_s.xpm +40 -0
- data/icons/room_se.gif +0 -0
- data/icons/room_se.xpm +80 -0
- data/icons/room_sw.gif +0 -0
- data/icons/room_sw.xpm +80 -0
- data/icons/room_w.gif +0 -0
- data/icons/room_w.xpm +39 -0
- data/lib/IFMapper/AStar.rb +243 -0
- data/lib/IFMapper/FXConnection.rb +101 -72
- data/lib/IFMapper/FXMap.rb +155 -230
- data/lib/IFMapper/FXMapColorBox.rb +92 -0
- data/lib/IFMapper/FXMapDialogBox.rb +83 -7
- data/lib/IFMapper/FXMapperSettings.rb +1 -0
- data/lib/IFMapper/FXMapperWindow.rb +82 -48
- data/lib/IFMapper/FXRoom.rb +43 -17
- data/lib/IFMapper/{FXPage.rb → FXSection.rb} +3 -3
- data/lib/IFMapper/{FXPageDialogBox.rb → FXSectionDialogBox.rb} +6 -6
- data/lib/IFMapper/FXSpline.rb +10 -14
- data/lib/IFMapper/IFMReader.rb +39 -31
- data/lib/IFMapper/Map.rb +42 -43
- data/lib/IFMapper/MapPrinting.rb +161 -0
- data/lib/IFMapper/PDFMapExporter.rb +128 -51
- data/lib/IFMapper/Room.rb +11 -1
- data/lib/IFMapper/{Page.rb → Section.rb} +65 -42
- metadata +34 -15
data/lib/IFMapper/FXRoom.rb
CHANGED
@@ -18,23 +18,26 @@ class FXRoom < Room
|
|
18
18
|
super(x, y, *opts)
|
19
19
|
end
|
20
20
|
|
21
|
+
#
|
22
|
+
# Set a new x position for the room. Value is in grid units.
|
23
|
+
#
|
21
24
|
def x=(v)
|
22
25
|
@x = v
|
23
26
|
@xx = v * WW + WS_2
|
24
27
|
end
|
25
28
|
|
29
|
+
#
|
30
|
+
# Set a new y position for the room. Value is in grid units.
|
31
|
+
#
|
26
32
|
def y=(v)
|
27
33
|
@y = v
|
28
34
|
@yy = v * HH + HS_2
|
29
35
|
end
|
30
36
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@darkness = b.darkness
|
36
|
-
end
|
37
|
-
|
37
|
+
#
|
38
|
+
# Set selection. If floating Room Properties window is open, copy
|
39
|
+
# the room data over to it.
|
40
|
+
#
|
38
41
|
def selected=(value)
|
39
42
|
if value and @@win
|
40
43
|
@@win.copy_from(self)
|
@@ -42,6 +45,9 @@ class FXRoom < Room
|
|
42
45
|
@selected = value
|
43
46
|
end
|
44
47
|
|
48
|
+
#
|
49
|
+
# Open a modal requester to change properties
|
50
|
+
#
|
45
51
|
def modal_properties(map)
|
46
52
|
shown = @@win and @@win.shown?
|
47
53
|
if shown
|
@@ -119,14 +125,33 @@ class FXRoom < Room
|
|
119
125
|
return [x * zoom, y * zoom]
|
120
126
|
end
|
121
127
|
|
128
|
+
|
129
|
+
#
|
130
|
+
# Main draw function for room
|
131
|
+
#
|
132
|
+
def draw(dc, zoom, idx, opt, data)
|
133
|
+
draw_box(dc, zoom, idx, opt)
|
134
|
+
dc.font = data['font']
|
135
|
+
x, y = draw_name(dc, zoom)
|
136
|
+
dc.font = data['objfont']
|
137
|
+
draw_objects(dc, zoom, x, y)
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
protected
|
122
142
|
|
143
|
+
#
|
144
|
+
# Draw the room index number
|
145
|
+
#
|
123
146
|
def draw_index(dc, zoom, idx)
|
124
147
|
x = (@xx + W - 20 ) * zoom
|
125
148
|
y = (@yy + HH - HS - 5 ) * zoom
|
126
149
|
dc.drawText(x, y, (idx + 1).to_s)
|
127
150
|
end
|
128
151
|
|
129
|
-
|
152
|
+
#
|
153
|
+
# Draw the 'room' and 'index' boxes
|
154
|
+
#
|
130
155
|
def draw_box(dc, zoom, idx, opt)
|
131
156
|
if @selected
|
132
157
|
dc.foreground = 'yellow'
|
@@ -169,6 +194,9 @@ class FXRoom < Room
|
|
169
194
|
end
|
170
195
|
end
|
171
196
|
|
197
|
+
#
|
198
|
+
# Draw text line wrapping after certain length (in chars)
|
199
|
+
#
|
172
200
|
def draw_text_wrap(dc, x, y, zoom, maxLen, text)
|
173
201
|
if text.size > maxLen
|
174
202
|
str = text
|
@@ -191,12 +219,19 @@ class FXRoom < Room
|
|
191
219
|
return [x, y]
|
192
220
|
end
|
193
221
|
|
222
|
+
#
|
223
|
+
# Draw name of room
|
224
|
+
#
|
194
225
|
def draw_name(dc, zoom)
|
195
226
|
x = (@xx + 5) * zoom
|
196
227
|
y = (@yy + 15) * zoom
|
197
228
|
return draw_text_wrap( dc, x, y, zoom, 15, @name )
|
198
229
|
end
|
199
230
|
|
231
|
+
|
232
|
+
#
|
233
|
+
# Draw the objects as a comma separated list
|
234
|
+
#
|
200
235
|
def draw_objects(dc, zoom, x, y)
|
201
236
|
return if @objects == ''
|
202
237
|
fh = dc.font.getFontHeight
|
@@ -206,13 +241,4 @@ class FXRoom < Room
|
|
206
241
|
return draw_text_wrap( dc, x, y, zoom, 23, objs )
|
207
242
|
end
|
208
243
|
|
209
|
-
|
210
|
-
def draw(dc, zoom, idx, opt, data)
|
211
|
-
draw_box(dc, zoom, idx, opt)
|
212
|
-
dc.font = data['font']
|
213
|
-
x, y = draw_name(dc, zoom)
|
214
|
-
dc.font = data['objfont']
|
215
|
-
draw_objects(dc, zoom, x, y)
|
216
|
-
end
|
217
|
-
|
218
244
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
|
2
2
|
require 'IFMapper/FXConnection'
|
3
3
|
require 'IFMapper/FXRoom'
|
4
|
-
require 'IFMapper/
|
4
|
+
require 'IFMapper/Section'
|
5
5
|
|
6
|
-
class
|
6
|
+
class FXSection < Section
|
7
7
|
def new_connection( roomA, exitA, roomB, exitB = nil )
|
8
8
|
c = FXConnection.new( roomA, roomB )
|
9
9
|
return _new_connection(c, roomA, exitA, roomB, exitB)
|
@@ -16,7 +16,7 @@ class FXPage < Page
|
|
16
16
|
|
17
17
|
def properties(map)
|
18
18
|
if not @win
|
19
|
-
@win =
|
19
|
+
@win = FXSectionDialogBox.new(map)
|
20
20
|
end
|
21
21
|
@win.copy_from(self)
|
22
22
|
@win.show
|
@@ -1,21 +1,21 @@
|
|
1
1
|
|
2
2
|
|
3
|
-
class
|
3
|
+
class FXSectionDialogBox < FXDialogBox
|
4
4
|
|
5
5
|
def copy_to()
|
6
|
-
@
|
6
|
+
@section.name = @name.text
|
7
7
|
@map.update_title
|
8
8
|
end
|
9
9
|
|
10
|
-
def copy_from(
|
11
|
-
@name.text =
|
12
|
-
@
|
10
|
+
def copy_from(section)
|
11
|
+
@name.text = section.name.to_s
|
12
|
+
@section = section
|
13
13
|
end
|
14
14
|
|
15
15
|
def initialize(map)
|
16
16
|
decor = DECOR_TITLE|DECOR_BORDER|DECOR_CLOSE
|
17
17
|
|
18
|
-
super( map.window, "
|
18
|
+
super( map.window, "Section Information", decor, 40, 40, 0, 0 )
|
19
19
|
mainFrame = FXVerticalFrame.new(self,
|
20
20
|
FRAME_SUNKEN|FRAME_THICK|
|
21
21
|
LAYOUT_FILL_X|LAYOUT_FILL_Y)
|
data/lib/IFMapper/FXSpline.rb
CHANGED
@@ -1,23 +1,19 @@
|
|
1
1
|
|
2
2
|
|
3
|
-
class FXPoint
|
4
|
-
def [](idx)
|
5
|
-
return x if idx == 0
|
6
|
-
return y if idx == 1
|
7
|
-
end
|
8
|
-
end
|
9
3
|
|
10
4
|
class FXSpline
|
5
|
+
OS = 1.0 / 6.0
|
6
|
+
FS = 4.0 / 6.0
|
11
7
|
def self.bspline_solve( r, p, num )
|
12
|
-
ax = -
|
13
|
-
bx = 0.5
|
14
|
-
cx = -0.5
|
15
|
-
dx =
|
8
|
+
ax = -OS * p[0][0] + 0.5 * p[1][0] - 0.5 * p[2][0] + OS * p[3][0]
|
9
|
+
bx = 0.5 * p[0][0] - p[1][0] + 0.5 * p[2][0]
|
10
|
+
cx = -0.5 * p[0][0] + 0.5 * p[2][0]
|
11
|
+
dx = OS * p[0][0] + FS * p[1][0] + OS * p[2][0]
|
16
12
|
|
17
|
-
ay = -
|
18
|
-
by = 0.5
|
19
|
-
cy = -0.5
|
20
|
-
dy =
|
13
|
+
ay = -OS * p[0][1] + 0.5 * p[1][1] - 0.5 * p[2][1] + OS * p[3][1]
|
14
|
+
by = 0.5 * p[0][1] - p[1][1] + 0.5 * p[2][1]
|
15
|
+
cy = -0.5 * p[0][1] + 0.5 * p[2][1]
|
16
|
+
dy = OS * p[0][1] + FS * p[1][1] + OS * p[2][1]
|
21
17
|
|
22
18
|
t = 0.0
|
23
19
|
tinc = 1.0 / num
|
data/lib/IFMapper/IFMReader.rb
CHANGED
@@ -53,8 +53,13 @@ class IFMReader
|
|
53
53
|
# We start map at 1, 1
|
54
54
|
@x, @y = [0, 0]
|
55
55
|
@room = @item = @task = nil
|
56
|
-
@map.
|
57
|
-
|
56
|
+
@map.section = 0
|
57
|
+
|
58
|
+
if @map.kind_of?(FXMap)
|
59
|
+
@map.window.hide
|
60
|
+
end
|
61
|
+
|
62
|
+
@last_section = 0
|
58
63
|
@ignore_first_section = true
|
59
64
|
@room_idx = 0
|
60
65
|
line_number = 0
|
@@ -226,18 +231,18 @@ class IFMReader
|
|
226
231
|
# current position.
|
227
232
|
@room = nil
|
228
233
|
@x = @y = 1
|
229
|
-
# dont' add a
|
234
|
+
# dont' add a section for first 'map' keyword
|
230
235
|
if @ignore_first_section
|
231
236
|
@ignore_first_section = false
|
232
|
-
@map.
|
237
|
+
@map.sections[0].name = section
|
233
238
|
next
|
234
239
|
end
|
235
240
|
if @resolve_tags
|
236
|
-
@map.
|
237
|
-
@
|
241
|
+
@map.section = @last_section + 1
|
242
|
+
@last_section = @map.section
|
238
243
|
else
|
239
|
-
@map.
|
240
|
-
@map.
|
244
|
+
@map.new_section
|
245
|
+
@map.sections[-1].name = section
|
241
246
|
end
|
242
247
|
when 'title'
|
243
248
|
@map.name = get_string
|
@@ -404,11 +409,11 @@ class IFMReader
|
|
404
409
|
# If from keyword present, move from that room on.
|
405
410
|
if from
|
406
411
|
roomA = from
|
407
|
-
# 'from' can also connect stuff not in current
|
408
|
-
# so we check we are in the right
|
409
|
-
@map.
|
412
|
+
# 'from' can also connect stuff not in current section...
|
413
|
+
# so we check we are in the right section.
|
414
|
+
@map.sections.each_with_index { |p, idx|
|
410
415
|
if p.rooms.include?(roomA)
|
411
|
-
@map.
|
416
|
+
@map.section = idx
|
412
417
|
break
|
413
418
|
end
|
414
419
|
}
|
@@ -433,10 +438,10 @@ class IFMReader
|
|
433
438
|
@room_idx += 1
|
434
439
|
else
|
435
440
|
# Verify there's no room in that location yet
|
436
|
-
|
437
|
-
|
441
|
+
section = @map.sections[@map.section]
|
442
|
+
section.rooms.each { |r|
|
438
443
|
if r.x == @x and r.y == @y
|
439
|
-
err = "
|
444
|
+
err = "Section #{@map.section+1} already has location #{r} at #{@x}, #{@y}.\n"
|
440
445
|
err << "Cannot create '#{roomname}'"
|
441
446
|
raise MapError, err
|
442
447
|
end
|
@@ -475,15 +480,15 @@ class IFMReader
|
|
475
480
|
end
|
476
481
|
|
477
482
|
# 'from' and 'link' keywords can also connect stuff not in
|
478
|
-
# current
|
479
|
-
@map.
|
483
|
+
# current section... so we check for that here
|
484
|
+
@map.sections.each_with_index { |p, idx|
|
480
485
|
if p.rooms.include?(roomA)
|
481
|
-
@map.
|
486
|
+
@map.section = idx
|
482
487
|
break
|
483
488
|
end
|
484
489
|
}
|
485
|
-
if not @map.
|
486
|
-
raise MapError, "Linking #{roomA} and #{roomB} which are in different
|
490
|
+
if not @map.sections[@map.section].rooms.include?(roomB)
|
491
|
+
raise MapError, "Linking #{roomA} and #{roomB} which are in different sections"
|
487
492
|
end
|
488
493
|
|
489
494
|
begin
|
@@ -531,7 +536,7 @@ class IFMReader
|
|
531
536
|
end
|
532
537
|
|
533
538
|
#
|
534
|
-
# Okay, check all min/max locations in all
|
539
|
+
# Okay, check all min/max locations in all sections
|
535
540
|
# and then do the following:
|
536
541
|
# a) Adjust map's width/height
|
537
542
|
# b) Shift all rooms so that no rooms are in negative locations
|
@@ -541,10 +546,10 @@ class IFMReader
|
|
541
546
|
@map.width = @map.height = 1
|
542
547
|
minXY = []
|
543
548
|
maxXY = []
|
544
|
-
@map.
|
545
|
-
next if
|
549
|
+
@map.sections.each { |section|
|
550
|
+
next if section.rooms.empty?
|
546
551
|
|
547
|
-
sizes =
|
552
|
+
sizes = section.min_max_rooms
|
548
553
|
minXY.push sizes[0]
|
549
554
|
maxXY.push sizes[1]
|
550
555
|
|
@@ -558,10 +563,10 @@ class IFMReader
|
|
558
563
|
|
559
564
|
|
560
565
|
# Okay, minXY[]/maxXY[] contains all the minXY/maxXY positions of
|
561
|
-
# each
|
562
|
-
# start shifting all nodes in the
|
566
|
+
# each section. With that info and @map.weight/height, we can
|
567
|
+
# start shifting all nodes in the section so that they will fit.
|
563
568
|
idx = 0
|
564
|
-
@map.
|
569
|
+
@map.sections.each { |p|
|
565
570
|
next if p.rooms.size == 0
|
566
571
|
x = y = 0
|
567
572
|
x = 1 - minXY[idx][0] if minXY[idx][0] < 1
|
@@ -579,7 +584,7 @@ class IFMReader
|
|
579
584
|
@map.create_pathmap if @map.kind_of?(FXMap)
|
580
585
|
end
|
581
586
|
|
582
|
-
def initialize(file, map = Map.new('
|
587
|
+
def initialize(file, map = Map.new('IFM Imported Map'))
|
583
588
|
@tags = {}
|
584
589
|
@map = map
|
585
590
|
@rooms = []
|
@@ -594,10 +599,13 @@ class IFMReader
|
|
594
599
|
parse(f)
|
595
600
|
}
|
596
601
|
# puts '--------------- second pass done'
|
597
|
-
@map.
|
598
|
-
@map.filename = file.sub(/\.ifm$/i, '.map')
|
599
|
-
@map.navigation = true
|
602
|
+
@map.section = 0
|
600
603
|
adjust_map
|
604
|
+
if @map.kind_of?(FXMap)
|
605
|
+
@map.filename = file.sub(/\.ifm$/i, '.map')
|
606
|
+
@map.navigation = true
|
607
|
+
@map.window.show
|
608
|
+
end
|
601
609
|
@tags = {} # save some memory by clearing the tag list
|
602
610
|
@rooms = nil # and room list
|
603
611
|
end
|
data/lib/IFMapper/Map.rb
CHANGED
@@ -1,108 +1,107 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'IFMapper/Room'
|
4
|
-
require 'IFMapper/
|
4
|
+
require 'IFMapper/Section'
|
5
5
|
|
6
6
|
class Map
|
7
7
|
attr_accessor :name
|
8
8
|
attr_accessor :creator
|
9
9
|
attr_accessor :date
|
10
10
|
|
11
|
-
attr_reader :
|
12
|
-
attr_accessor :
|
11
|
+
attr_reader :section
|
12
|
+
attr_accessor :sections
|
13
13
|
|
14
14
|
attr_accessor :width
|
15
15
|
attr_accessor :height
|
16
16
|
|
17
|
-
def
|
17
|
+
def section=(x)
|
18
18
|
x = 0 if x < 0
|
19
|
-
x = @
|
20
|
-
@
|
19
|
+
x = @sections.size - 1 if x >= @sections.size
|
20
|
+
@section = x
|
21
21
|
end
|
22
22
|
|
23
23
|
#
|
24
24
|
# Used for loading class with Marshal
|
25
25
|
#
|
26
26
|
def marshal_load(v)
|
27
|
-
@name
|
28
|
-
@creator
|
29
|
-
@date
|
30
|
-
@
|
31
|
-
@
|
32
|
-
@width
|
33
|
-
@height
|
27
|
+
@name = v.shift
|
28
|
+
@creator = v.shift
|
29
|
+
@date = v.shift
|
30
|
+
@section = v.shift
|
31
|
+
@sections = v.shift
|
32
|
+
@width = v.shift
|
33
|
+
@height = v.shift
|
34
34
|
end
|
35
35
|
|
36
36
|
#
|
37
37
|
# Used for saving class with Marshal
|
38
38
|
#
|
39
39
|
def marshal_dump
|
40
|
-
[ @name, @creator, @date, @
|
40
|
+
[ @name, @creator, @date, @section, @sections, @width, @height ]
|
41
41
|
end
|
42
42
|
|
43
43
|
def initialize(name)
|
44
|
-
@
|
44
|
+
@section = 0
|
45
45
|
@name = name
|
46
46
|
@creator = ''
|
47
47
|
|
48
|
-
|
49
|
-
@
|
50
|
-
@height = 20
|
48
|
+
@width = 8
|
49
|
+
@height = 11
|
51
50
|
|
52
|
-
# Add at least one
|
53
|
-
@
|
54
|
-
|
51
|
+
# Add at least one section
|
52
|
+
@sections = []
|
53
|
+
new_section
|
55
54
|
end
|
56
55
|
|
57
56
|
def copy(b)
|
58
|
-
@
|
59
|
-
@
|
60
|
-
@name
|
61
|
-
@creator
|
62
|
-
@width
|
63
|
-
@height
|
64
|
-
@date
|
57
|
+
@section = b.section
|
58
|
+
@sections = b.sections
|
59
|
+
@name = b.name
|
60
|
+
@creator = b.creator
|
61
|
+
@width = b.width
|
62
|
+
@height = b.height
|
63
|
+
@date = b.date
|
65
64
|
end
|
66
65
|
|
67
66
|
def delete_connection(c)
|
68
|
-
@
|
67
|
+
@sections[@section].delete_connection(c)
|
69
68
|
end
|
70
69
|
|
71
70
|
def delete_connection_at( idx )
|
72
|
-
@
|
71
|
+
@sections[@section].delete_connection_at(idx)
|
73
72
|
end
|
74
73
|
|
75
74
|
|
76
75
|
def new_connection( roomA, exitA, roomB, exitB = nil )
|
77
|
-
@
|
76
|
+
@sections[@section].new_connection(roomA, exitA, roomB, exitB)
|
78
77
|
end
|
79
78
|
|
80
79
|
|
81
80
|
def delete_room_at(idx)
|
82
|
-
@
|
81
|
+
@sections[@section].delete_room_at(idx)
|
83
82
|
end
|
84
83
|
|
85
84
|
def delete_room(r)
|
86
|
-
@
|
85
|
+
@sections[@section].delete_room(r)
|
87
86
|
end
|
88
87
|
|
89
88
|
def new_room( x, y )
|
90
|
-
@
|
89
|
+
@sections[@section].new_room(x, y)
|
91
90
|
end
|
92
91
|
|
93
|
-
def
|
94
|
-
@
|
95
|
-
@
|
92
|
+
def new_section
|
93
|
+
@sections.push( Section.new )
|
94
|
+
@section = @sections.size - 1
|
96
95
|
end
|
97
96
|
|
98
|
-
def
|
99
|
-
@
|
100
|
-
|
97
|
+
def _check_section
|
98
|
+
@section = @sections.size - 1 if @section >= @sections.size
|
99
|
+
new_section if @sections.size == 0
|
101
100
|
end
|
102
101
|
|
103
|
-
def
|
104
|
-
@
|
105
|
-
|
102
|
+
def delete_section_at(idx)
|
103
|
+
@sections.delete_at(idx)
|
104
|
+
_check_section
|
106
105
|
end
|
107
106
|
|
108
107
|
end
|