ifmapper 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- def copy(b)
32
- @name = b.name
33
- @objects = b.objects
34
- @tasks = b.tasks
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/Page'
4
+ require 'IFMapper/Section'
5
5
 
6
- class FXPage < Page
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 = FXPageDialogBox.new(map)
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 FXPageDialogBox < FXDialogBox
3
+ class FXSectionDialogBox < FXDialogBox
4
4
 
5
5
  def copy_to()
6
- @page.name = @name.text
6
+ @section.name = @name.text
7
7
  @map.update_title
8
8
  end
9
9
 
10
- def copy_from(page)
11
- @name.text = page.name.to_s
12
- @page = page
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, "Page Information", decor, 40, 40, 0, 0 )
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)
@@ -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 = -1.0/6 * p[0][0] + 0.5 * p[1][0] - 0.5 * p[2][0] + 1.0/6 * p[3][0]
13
- bx = 0.5 * p[0][0] - p[1][0] + 0.5 * p[2][0]
14
- cx = -0.5 * p[0][0] + 0.5 * p[2][0]
15
- dx = 1.0/6 * p[0][0] + 4.0/6 * p[1][0] + 1.0/6 * p[2][0]
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 = -1.0/6 * p[0][1] + 0.5 * p[1][1] - 0.5 * p[2][1] + 1.0/6 * p[3][1]
18
- by = 0.5 * p[0][1] - p[1][1] + 0.5 * p[2][1]
19
- cy = -0.5 * p[0][1] + 0.5 * p[2][1]
20
- dy = 1.0/6 * p[0][1] + 4.0/6 * p[1][1] + 1.0/6 * p[2][1]
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
@@ -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.page = 0
57
- @last_page = 0
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 page for first 'map' keyword
234
+ # dont' add a section for first 'map' keyword
230
235
  if @ignore_first_section
231
236
  @ignore_first_section = false
232
- @map.pages[0].name = section
237
+ @map.sections[0].name = section
233
238
  next
234
239
  end
235
240
  if @resolve_tags
236
- @map.page = @last_page + 1
237
- @last_page = @map.page
241
+ @map.section = @last_section + 1
242
+ @last_section = @map.section
238
243
  else
239
- @map.new_page
240
- @map.pages[-1].name = section
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 page...
408
- # so we check we are in the right page.
409
- @map.pages.each_with_index { |p, idx|
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.page = idx
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
- page = @map.pages[@map.page]
437
- page.rooms.each { |r|
441
+ section = @map.sections[@map.section]
442
+ section.rooms.each { |r|
438
443
  if r.x == @x and r.y == @y
439
- err = "Page #{@map.page+1} already has location #{r} at #{@x}, #{@y}.\n"
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 page... so we check for that here
479
- @map.pages.each_with_index { |p, idx|
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.page = idx
486
+ @map.section = idx
482
487
  break
483
488
  end
484
489
  }
485
- if not @map.pages[@map.page].rooms.include?(roomB)
486
- raise MapError, "Linking #{roomA} and #{roomB} which are in different pages"
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 pages
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.pages.each { |page|
545
- next if page.rooms.empty?
549
+ @map.sections.each { |section|
550
+ next if section.rooms.empty?
546
551
 
547
- sizes = page.min_max_rooms
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 page. With that info and @map.weight/height, we can
562
- # start shifting all nodes in the page so that they will fit.
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.pages.each { |p|
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('IMF Imported Map'))
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.page = 0
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
@@ -1,108 +1,107 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'IFMapper/Room'
4
- require 'IFMapper/Page'
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 :page
12
- attr_accessor :pages
11
+ attr_reader :section
12
+ attr_accessor :sections
13
13
 
14
14
  attr_accessor :width
15
15
  attr_accessor :height
16
16
 
17
- def page=(x)
17
+ def section=(x)
18
18
  x = 0 if x < 0
19
- x = @pages.size - 1 if x >= @pages.size
20
- @page = x
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 = v.shift
28
- @creator = v.shift
29
- @date = v.shift
30
- @page = v.shift
31
- @pages = v.shift
32
- @width = v.shift
33
- @height = v.shift
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, @page, @pages, @width, @height ]
40
+ [ @name, @creator, @date, @section, @sections, @width, @height ]
41
41
  end
42
42
 
43
43
  def initialize(name)
44
- @page = 0
44
+ @section = 0
45
45
  @name = name
46
46
  @creator = ''
47
47
 
48
- # if printing sideways
49
- @width = 20
50
- @height = 20
48
+ @width = 8
49
+ @height = 11
51
50
 
52
- # Add at least one page
53
- @pages = []
54
- new_page
51
+ # Add at least one section
52
+ @sections = []
53
+ new_section
55
54
  end
56
55
 
57
56
  def copy(b)
58
- @page = b.page
59
- @pages = b.pages
60
- @name = b.name
61
- @creator = b.creator
62
- @width = b.width
63
- @height = b.height
64
- @date = b.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
- @pages[@page].delete_connection(c)
67
+ @sections[@section].delete_connection(c)
69
68
  end
70
69
 
71
70
  def delete_connection_at( idx )
72
- @pages[@page].delete_connection_at(idx)
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
- @pages[@page].new_connection(roomA, exitA, roomB, exitB)
76
+ @sections[@section].new_connection(roomA, exitA, roomB, exitB)
78
77
  end
79
78
 
80
79
 
81
80
  def delete_room_at(idx)
82
- @pages[@page].delete_room_at(idx)
81
+ @sections[@section].delete_room_at(idx)
83
82
  end
84
83
 
85
84
  def delete_room(r)
86
- @pages[@page].delete_room(r)
85
+ @sections[@section].delete_room(r)
87
86
  end
88
87
 
89
88
  def new_room( x, y )
90
- @pages[@page].new_room(x, y)
89
+ @sections[@section].new_room(x, y)
91
90
  end
92
91
 
93
- def new_page
94
- @pages.push( Page.new )
95
- @page = @pages.size - 1
92
+ def new_section
93
+ @sections.push( Section.new )
94
+ @section = @sections.size - 1
96
95
  end
97
96
 
98
- def _check_page
99
- @page = @pages.size - 1 if @page >= @pages.size
100
- new_page if @pages.size == 0
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 delete_page_at(idx)
104
- @pages.delete_at(idx)
105
- _check_page
102
+ def delete_section_at(idx)
103
+ @sections.delete_at(idx)
104
+ _check_section
106
105
  end
107
106
 
108
107
  end