ifmapper 1.0.0 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.txt +648 -627
- data/IFMapper.gemspec +29 -28
- data/IFMapper.rbw +31 -31
- data/TODO.txt +8 -7
- data/bin/IFMapper +31 -31
- data/docs/en/index.html +0 -0
- data/docs/en/start.html +3 -2
- data/docs/en/start.html~ +516 -0
- data/docs/es/index.html +0 -0
- data/docs/es/start.html +13 -14
- data/docs/es/start.html~ +1280 -0
- data/docs/images/IFMapper_main.gif +0 -0
- data/docs/images/automap.gif +0 -0
- data/docs/images/complex_connection.gif +0 -0
- data/docs/images/connection.gif +0 -0
- data/docs/images/connection_menu.gif +0 -0
- data/docs/images/room_description.gif +0 -0
- data/docs/images/room_small.gif +0 -0
- data/icons/copy.png +0 -0
- data/icons/cut.png +0 -0
- data/icons/filenew.png +0 -0
- data/icons/fileopen.png +0 -0
- data/icons/filesave.png +0 -0
- data/icons/filesaveas.png +0 -0
- data/icons/help.png +0 -0
- data/icons/kill.png +0 -0
- data/icons/nextpage.png +0 -0
- data/icons/paste.png +0 -0
- data/icons/prevpage.png +0 -0
- data/icons/printicon.png +0 -0
- data/icons/redo.png +0 -0
- data/icons/room_e.gif +0 -0
- data/icons/room_e.xpm +0 -0
- data/icons/room_n.gif +0 -0
- data/icons/room_n.xpm +0 -0
- data/icons/room_ne.gif +0 -0
- data/icons/room_ne.xpm +0 -0
- data/icons/room_nw.gif +0 -0
- data/icons/room_nw.xpm +0 -0
- data/icons/room_s.gif +0 -0
- data/icons/room_s.xpm +0 -0
- data/icons/room_se.gif +0 -0
- data/icons/room_se.xpm +0 -0
- data/icons/room_sw.gif +0 -0
- data/icons/room_sw.xpm +0 -0
- data/icons/room_w.gif +0 -0
- data/icons/room_w.xpm +0 -0
- data/icons/saveas.png +0 -0
- data/icons/undo.png +0 -0
- data/icons/winapp.png +0 -0
- data/icons/zoom.png +0 -0
- data/lib/IFMapper/AStar.rb +250 -250
- data/lib/IFMapper/Connection.rb +202 -202
- data/lib/IFMapper/FXAboutDialogBox.rb +32 -32
- data/lib/IFMapper/FXConnection.rb +364 -364
- data/lib/IFMapper/FXConnectionDialogBox.rb +124 -124
- data/lib/IFMapper/FXDCPostscript.rb +404 -404
- data/lib/IFMapper/FXDCPrint.rb +15 -15
- data/lib/IFMapper/FXItemList.rb +108 -0
- data/lib/IFMapper/FXMap.rb +2147 -2116
- data/lib/IFMapper/FXMapColorBox.rb +88 -88
- data/lib/IFMapper/FXMapDialogBox.rb +127 -127
- data/lib/IFMapper/FXMapFileDialog.rb +34 -34
- data/lib/IFMapper/FXMapperSettings.rb +206 -205
- data/lib/IFMapper/FXMapperWindow.rb +1592 -1571
- data/lib/IFMapper/FXPDFMapExporterOptionsDialogBox.rb +46 -0
- data/lib/IFMapper/FXRoom.rb +263 -263
- data/lib/IFMapper/FXRoomDialogBox.rb +159 -159
- data/lib/IFMapper/FXRoomList.rb +95 -95
- data/lib/IFMapper/FXSearchDialogBox.rb +51 -51
- data/lib/IFMapper/FXSection.rb +33 -33
- data/lib/IFMapper/FXSectionDialogBox.rb +38 -38
- data/lib/IFMapper/FXSpline.rb +52 -52
- data/lib/IFMapper/FXWarningBox.rb +51 -50
- data/lib/IFMapper/GUEReader.rb +445 -445
- data/lib/IFMapper/IFMReader.rb +584 -584
- data/lib/IFMapper/IFMWriter.rb +245 -227
- data/lib/IFMapper/Inform7Writer.rb +579 -573
- data/lib/IFMapper/InformReader.rb +478 -478
- data/lib/IFMapper/InformWriter.rb +364 -359
- data/lib/IFMapper/Map.rb +202 -200
- data/lib/IFMapper/MapPrinting.rb +162 -162
- data/lib/IFMapper/MapReader.rb +900 -900
- data/lib/IFMapper/PDFMapExporter.rb +526 -483
- data/lib/IFMapper/Room.rb +153 -151
- data/lib/IFMapper/Section.rb +234 -234
- data/lib/IFMapper/TADSReader.rb +474 -471
- data/lib/IFMapper/TADSWriter.rb +375 -370
- data/lib/IFMapper/TranscriptDialogBox.rb +0 -0
- data/lib/IFMapper/TranscriptReader.rb +1361 -1359
- data/lib/IFMapper/locales/en/Messages.rb +446 -435
- data/lib/IFMapper/locales/es/Messages.rb +451 -440
- data/lib/IFMapper/locales/es/Messages_iso-8859-1.rb +455 -440
- data/lib/IFMapper/locales/es/runme.sh +3 -3
- data/maps/A New Life.map b/data/maps/A New → Life.map +0 -0
- data/maps/AMFV.map +0 -0
- data/maps/AllRoads.map +0 -0
- data/maps/Aotearoa.map +0 -0
- data/maps/Bronze.map +0 -0
- data/maps/Bureaucracy.ifm +0 -0
- data/maps/Bureaucracy.map +0 -0
- data/maps/CityOfSecrets.map +0 -0
- data/maps/DDIV.map +0 -0
- data/maps/Following_A_Star.map +0 -0
- data/maps/Heated.map +0 -0
- data/maps/Heroine.map +0 -0
- data/maps/History Repeating.map b/data/maps/History → Repeating.map +0 -0
- data/maps/Hollywood_Hijinx.ifm +0 -0
- data/maps/Janitor.map +0 -0
- data/maps/Jigsaw.ifm +0 -0
- data/maps/Jigsaw.map +0 -0
- data/maps/LGOP.ifm +0 -0
- data/maps/Mercy.ifm +0 -0
- data/maps/Ninjas_Fate.map +0 -0
- data/maps/Pen_and_Paint.map +0 -0
- data/maps/Planetfall.ifm +0 -0
- data/maps/Planetfall.map +0 -0
- data/maps/Plundered_Hearts.ifm +0 -0
- data/maps/QuietEvening.map +0 -0
- data/maps/Ralph.ifm +0 -0
- data/maps/Reliques_of_Tolti_Alph.map +0 -0
- data/maps/Revolution.map +0 -0
- data/maps/Robots_of_Dawn.ifm +0 -0
- data/maps/SavoirFare.map +0 -0
- data/maps/Seastalker.ifm +0 -0
- data/maps/Seastalker.map +0 -0
- data/maps/Sherlock.ifm +0 -0
- data/maps/SoFar.ifm +0 -0
- data/maps/Starcross.ifm +0 -0
- data/maps/Suspended.ifm +0 -0
- data/maps/Tangle.map +0 -0
- data/maps/The_Lost_Sheep.map +0 -0
- data/maps/Unforgotten.map +0 -0
- data/maps/Warbler's Nest.map +0 -0
- data/maps/Warbler's_Nest.map +0 -0
- data/maps/Westminster_Abbey.map +0 -0
- data/maps/WinterWonderland.map +0 -0
- data/maps/Wishbringer.ifm +0 -0
- data/maps/Wishbringer2.ifm +0 -0
- data/maps/Zork1.ifm +0 -0
- data/maps/Zork2.ifm +0 -0
- data/maps/Zork3.ifm +0 -0
- data/maps/Zork_Zero.ifm +0 -0
- data/maps/anchor.ifm +0 -0
- data/maps/anchor.map +0 -0
- data/maps/atrox.ifm +0 -0
- data/maps/awaken.ifm +0 -0
- data/maps/babel.ifm +0 -0
- data/maps/balances.map +0 -0
- data/maps/ballerina.map +0 -0
- data/maps/bear.map +0 -0
- data/maps/bluechairs.map +0 -0
- data/maps/break_in.map +0 -0
- data/maps/bse.ifm +0 -0
- data/maps/building.map +0 -0
- data/maps/change.ifm +0 -0
- data/maps/christminster.map +0 -0
- data/maps/curses.ifm +0 -0
- data/maps/curves.ifm +0 -0
- data/maps/deadline.map +0 -0
- data/maps/delusions.map +0 -0
- data/maps/devours.map +0 -0
- data/maps/distress.map +0 -0
- data/maps/djinni.map +0 -0
- data/maps/dreamhold.map +0 -0
- data/maps/drift3.map +0 -0
- data/maps/eas.map +0 -0
- data/maps/eas2.map +0 -0
- data/maps/eas3.map +0 -0
- data/maps/edifice.ifm +0 -0
- data/maps/fallacy.map +0 -0
- data/maps/frozen.ifm +0 -0
- data/maps/gamlet.map +0 -0
- data/maps/glow.ifm +0 -0
- data/maps/guilty_bastards.map +0 -0
- data/maps/heist.map +0 -0
- data/maps/heroes.map +0 -0
- data/maps/inhumane.map +0 -0
- data/maps/kaged.map +0 -0
- data/maps/library.ifm +0 -0
- data/maps/lurkinghorror.map +0 -0
- data/maps/metamorphoses.map +0 -0
- data/maps/mindelec.ifm +0 -0
- data/maps/minster.ifm +0 -0
- data/maps/mite.map +0 -0
- data/maps/moonmist.map +0 -0
- data/maps/muldoon_legacy.map +0 -0
- data/maps/muse.ifm +0 -0
- data/maps/paperchase.ifm +0 -0
- data/maps/party.map +0 -0
- data/maps/pawn.map +0 -0
- data/maps/photograph.map +0 -0
- data/maps/pkgirl.map +0 -0
- data/maps/pytho.map +0 -0
- data/maps/risorgimento.map +0 -0
- data/maps/sherbet.map +0 -0
- data/maps/simple.map +0 -0
- data/maps/slouch.map +0 -0
- data/maps/space_st.ifm +0 -0
- data/maps/splashdown.map +0 -0
- data/maps/spring.map +0 -0
- data/maps/squarecircle.map +0 -0
- data/maps/stationfall.ifm +0 -0
- data/maps/theatre.ifm +0 -0
- data/maps/toonesia.ifm +0 -0
- data/maps/tortoise.ifm +0 -0
- data/maps/trinity.map +0 -0
- data/maps/vespers.map +0 -0
- data/maps/vgame.ifm +0 -0
- data/maps/wasp.map +0 -0
- data/maps/weather.ifm +0 -0
- data/maps/windhall.ifm +0 -0
- data/maps/worlds.map +0 -0
- data/maps/xtcontest.map +0 -0
- data/maps/zdungeon.map +0 -0
- data/maps/zebulon.ifm +0 -0
- data/maps/zerosum.map +0 -0
- metadata +226 -183
data/lib/IFMapper/TADSReader.rb
CHANGED
@@ -1,471 +1,474 @@
|
|
1
|
-
|
2
|
-
require 'IFMapper/MapReader'
|
3
|
-
|
4
|
-
|
5
|
-
# Take a quoted TADS string and return a valid ASCII one, replacing
|
6
|
-
# TADS's special characters.
|
7
|
-
module TADSUnquote
|
8
|
-
def unquote(text)
|
9
|
-
return '' unless text
|
10
|
-
text.gsub!(/\\'/, "'") # restore quotes
|
11
|
-
text.gsub!(/\\"/, '"') # restore quotes
|
12
|
-
text.gsub!(/<<.*>>/, '') # remove embedded functions
|
13
|
-
text.gsub!(/<\/?q>/, '"') # Change quotes
|
14
|
-
return text
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
#
|
20
|
-
# Class that allows creating a map from an TADS source file.
|
21
|
-
#
|
22
|
-
class TADSReader < MapReader
|
23
|
-
|
24
|
-
# TADS 3 directional properties need to be spelled fully
|
25
|
-
DIRECTIONS = {
|
26
|
-
'north' => 0,
|
27
|
-
'northeast' => 1,
|
28
|
-
'east' => 2,
|
29
|
-
'southeast' => 3,
|
30
|
-
'south' => 4,
|
31
|
-
'southwest' => 5,
|
32
|
-
'west' => 6,
|
33
|
-
'northwest' => 7,
|
34
|
-
'up' => 8,
|
35
|
-
'down' => 9,
|
36
|
-
'in' => 10,
|
37
|
-
'out' => 11
|
38
|
-
}
|
39
|
-
|
40
|
-
FUNCTION = /^\[ (\w+);/
|
41
|
-
|
42
|
-
GO_OBJ = /\b(#{DIRECTIONS.keys.join('|').gsub(/_to/, '_obj')})\s*:/i
|
43
|
-
|
44
|
-
# SINGLE QUOTED STRING
|
45
|
-
SQ = '((?:\\\\\'|[^\'])+)'
|
46
|
-
|
47
|
-
# DOUBLE QUOTED STRING
|
48
|
-
DQ = '((?:\\\"|[^"])+)'
|
49
|
-
|
50
|
-
# Equal sign (TADS supports C or Pascal-like =)
|
51
|
-
EQ = '\s*(?:=|\:=)\s*'
|
52
|
-
|
53
|
-
|
54
|
-
DIR_EQ = "(#{DIRECTIONS.keys.join('|')})#{EQ}"
|
55
|
-
DIR_TO = /(?:^|\s+)#{DIR_EQ}/
|
56
|
-
DIR = /(?:^|\s+)#{DIR_EQ}(\w+)/
|
57
|
-
DIR_OPEN = /(?:^|\s+)#{DIR_EQ}\(\s*[\d\w]+\.isOpen\s*\?\s*([\d\w]+)/
|
58
|
-
DIR_INSELF = /(?:^|\s+)#{DIR_EQ}\(\s*[\d\w]+\.isIn\(\s*self\s*\)\s*\?\s*([\d\w]+)/
|
59
|
-
DIR_MSG = /(?:^|\s+)(#{DIRECTIONS.keys.join('|')})\s*\:\s*TravelMessage\s*\{\s*\->\s*(\w+)/
|
60
|
-
|
61
|
-
ENTER_DIR = /(?:^|\s+)(#{DIRECTIONS.keys.join('|')})\s*:\s*.*<<replaceAction\(Enter\s*,\s*(\w+)/i
|
62
|
-
|
63
|
-
OBJLOCATION = /(?:^|\s+)(?:(?:destination|location)#{EQ}(\w+)|@(\w+)|locationList#{EQ}\[([\w\s,]+)\])/
|
64
|
-
OBJNAME = /(?:^|\s+)name#{EQ}(?:'#{SQ}'|\(\s*described\s*\?\s*'#{SQ}')/
|
65
|
-
CONNECTOR = /(?:^|\s+)room\d+\s*#{EQ}\s*(\w+)/
|
66
|
-
ROOMNAME = /(?:^|\s+)roomName#{EQ}'#{SQ}'/
|
67
|
-
DESCRIPTION = /(?:^|\s+)desc#{EQ}(?:\s*$|\s+"#{DQ}?("?))/
|
68
|
-
|
69
|
-
|
70
|
-
# TADS3 template definitions are like:
|
71
|
-
# [+] [TAG:] Classes ['adjective nouns'] 'Name' @location
|
72
|
-
PLUS = '\s*([\+]+\s*)?'
|
73
|
-
TAG = '(?:([\w\d]+)\s*:)?\s*'
|
74
|
-
CLS = '([\w\s\-\>,]+)'
|
75
|
-
NOMS = "(?:\'#{SQ}\')?"
|
76
|
-
NAME = "(?:\s+\'#{SQ}\')?"
|
77
|
-
LOC = '\s+(?:@([\d\w]+))?'
|
78
|
-
|
79
|
-
CLASS = /^class\s+(\w+)\s*:\s*([\w,\s]+)/i
|
80
|
-
DOOR = /(?:^|\s+)door_to(?:\s+([^,;]*)|$)/i
|
81
|
-
INCLUDE = /^#include\s+[<"]([^">]+)[">]/
|
82
|
-
|
83
|
-
STD_LIB = [
|
84
|
-
'adv3.h',
|
85
|
-
'en_us.h',
|
86
|
-
'bignum.h',
|
87
|
-
'array.h',
|
88
|
-
'tok.h',
|
89
|
-
'bytearr.h',
|
90
|
-
'charset.h',
|
91
|
-
'dict.h',
|
92
|
-
'reflect.h',
|
93
|
-
'gramprod.h',
|
94
|
-
'systype.h',
|
95
|
-
'tads.h',
|
96
|
-
'tadsgen.h',
|
97
|
-
'tadsio.h',
|
98
|
-
't3.h',
|
99
|
-
'vector.h',
|
100
|
-
'file.h',
|
101
|
-
't3test.h',
|
102
|
-
'strcomp.h',
|
103
|
-
]
|
104
|
-
|
105
|
-
|
106
|
-
attr_reader :map
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
include TADSUnquote
|
111
|
-
|
112
|
-
class TADSRoom < MapRoom
|
113
|
-
include TADSUnquote
|
114
|
-
end
|
115
|
-
|
116
|
-
class TADSObject < MapObject
|
117
|
-
include TADSUnquote
|
118
|
-
end
|
119
|
-
|
120
|
-
|
121
|
-
def new_room
|
122
|
-
super(TADSRoom)
|
123
|
-
end
|
124
|
-
|
125
|
-
def new_obj(loc = nil)
|
126
|
-
super(loc, TADSObject)
|
127
|
-
end
|
128
|
-
|
129
|
-
#
|
130
|
-
# Main parsing loop. We basically parse the file twice to
|
131
|
-
# solve dependencies. Yes, this is inefficient, but the alternative
|
132
|
-
# was to build a full parser that understands forward dependencies.
|
133
|
-
#
|
134
|
-
def parse(file)
|
135
|
-
# We start map at 0, 0
|
136
|
-
@x, @y = [0, 0]
|
137
|
-
@room = nil
|
138
|
-
|
139
|
-
if @map.kind_of?(FXMap)
|
140
|
-
@map.options['Edit on Creation'] = false
|
141
|
-
@map.window.hide
|
142
|
-
end
|
143
|
-
@map.section = 0
|
144
|
-
|
145
|
-
@
|
146
|
-
@
|
147
|
-
@
|
148
|
-
@
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
# Remove
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
rescue => e
|
174
|
-
message = "#{e}
|
175
|
-
raise message
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
@
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
@
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
@
|
300
|
-
@
|
301
|
-
|
302
|
-
@
|
303
|
-
@
|
304
|
-
|
305
|
-
@
|
306
|
-
|
307
|
-
|
308
|
-
@
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
@
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
@
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
@
|
334
|
-
|
335
|
-
@
|
336
|
-
@
|
337
|
-
|
338
|
-
|
339
|
-
@
|
340
|
-
|
341
|
-
|
342
|
-
@
|
343
|
-
|
344
|
-
if @
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
#
|
358
|
-
#
|
359
|
-
#
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
@include_dirs << p
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
}
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
1
|
+
|
2
|
+
require 'IFMapper/MapReader'
|
3
|
+
|
4
|
+
|
5
|
+
# Take a quoted TADS string and return a valid ASCII one, replacing
|
6
|
+
# TADS's special characters.
|
7
|
+
module TADSUnquote
|
8
|
+
def unquote(text)
|
9
|
+
return '' unless text
|
10
|
+
text.gsub!(/\\'/, "'") # restore quotes
|
11
|
+
text.gsub!(/\\"/, '"') # restore quotes
|
12
|
+
text.gsub!(/<<.*>>/, '') # remove embedded functions
|
13
|
+
text.gsub!(/<\/?q>/, '"') # Change quotes
|
14
|
+
return text
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
#
|
20
|
+
# Class that allows creating a map from an TADS source file.
|
21
|
+
#
|
22
|
+
class TADSReader < MapReader
|
23
|
+
|
24
|
+
# TADS 3 directional properties need to be spelled fully
|
25
|
+
DIRECTIONS = {
|
26
|
+
'north' => 0,
|
27
|
+
'northeast' => 1,
|
28
|
+
'east' => 2,
|
29
|
+
'southeast' => 3,
|
30
|
+
'south' => 4,
|
31
|
+
'southwest' => 5,
|
32
|
+
'west' => 6,
|
33
|
+
'northwest' => 7,
|
34
|
+
'up' => 8,
|
35
|
+
'down' => 9,
|
36
|
+
'in' => 10,
|
37
|
+
'out' => 11
|
38
|
+
}
|
39
|
+
|
40
|
+
FUNCTION = /^\[ (\w+);/
|
41
|
+
|
42
|
+
GO_OBJ = /\b(#{DIRECTIONS.keys.join('|').gsub(/_to/, '_obj')})\s*:/i
|
43
|
+
|
44
|
+
# SINGLE QUOTED STRING
|
45
|
+
SQ = '((?:\\\\\'|[^\'])+)'
|
46
|
+
|
47
|
+
# DOUBLE QUOTED STRING
|
48
|
+
DQ = '((?:\\\"|[^"])+)'
|
49
|
+
|
50
|
+
# Equal sign (TADS supports C or Pascal-like =)
|
51
|
+
EQ = '\s*(?:=|\:=)\s*'
|
52
|
+
|
53
|
+
|
54
|
+
DIR_EQ = "(#{DIRECTIONS.keys.join('|')})#{EQ}"
|
55
|
+
DIR_TO = /(?:^|\s+)#{DIR_EQ}/
|
56
|
+
DIR = /(?:^|\s+)#{DIR_EQ}(\w+)/
|
57
|
+
DIR_OPEN = /(?:^|\s+)#{DIR_EQ}\(\s*[\d\w]+\.isOpen\s*\?\s*([\d\w]+)/
|
58
|
+
DIR_INSELF = /(?:^|\s+)#{DIR_EQ}\(\s*[\d\w]+\.isIn\(\s*self\s*\)\s*\?\s*([\d\w]+)/
|
59
|
+
DIR_MSG = /(?:^|\s+)(#{DIRECTIONS.keys.join('|')})\s*\:\s*TravelMessage\s*\{\s*\->\s*(\w+)/
|
60
|
+
|
61
|
+
ENTER_DIR = /(?:^|\s+)(#{DIRECTIONS.keys.join('|')})\s*:\s*.*<<replaceAction\(Enter\s*,\s*(\w+)/i
|
62
|
+
|
63
|
+
OBJLOCATION = /(?:^|\s+)(?:(?:destination|location)#{EQ}(\w+)|@(\w+)|locationList#{EQ}\[([\w\s,]+)\])/
|
64
|
+
OBJNAME = /(?:^|\s+)name#{EQ}(?:'#{SQ}'|\(\s*described\s*\?\s*'#{SQ}')/
|
65
|
+
CONNECTOR = /(?:^|\s+)room\d+\s*#{EQ}\s*(\w+)/
|
66
|
+
ROOMNAME = /(?:^|\s+)roomName#{EQ}'#{SQ}'/
|
67
|
+
DESCRIPTION = /(?:^|\s+)desc#{EQ}(?:\s*$|\s+"#{DQ}?("?))/
|
68
|
+
|
69
|
+
|
70
|
+
# TADS3 template definitions are like:
|
71
|
+
# [+] [TAG:] Classes ['adjective nouns'] 'Name' @location
|
72
|
+
PLUS = '\s*([\+]+\s*)?'
|
73
|
+
TAG = '(?:([\w\d]+)\s*:)?\s*'
|
74
|
+
CLS = '([\w\s\-\>,]+)'
|
75
|
+
NOMS = "(?:\'#{SQ}\')?"
|
76
|
+
NAME = "(?:\s+\'#{SQ}\')?"
|
77
|
+
LOC = '\s+(?:@([\d\w]+))?'
|
78
|
+
|
79
|
+
CLASS = /^class\s+(\w+)\s*:\s*([\w,\s]+)/i
|
80
|
+
DOOR = /(?:^|\s+)door_to(?:\s+([^,;]*)|$)/i
|
81
|
+
INCLUDE = /^#include\s+[<"]([^">]+)[">]/
|
82
|
+
|
83
|
+
STD_LIB = [
|
84
|
+
'adv3.h',
|
85
|
+
'en_us.h',
|
86
|
+
'bignum.h',
|
87
|
+
'array.h',
|
88
|
+
'tok.h',
|
89
|
+
'bytearr.h',
|
90
|
+
'charset.h',
|
91
|
+
'dict.h',
|
92
|
+
'reflect.h',
|
93
|
+
'gramprod.h',
|
94
|
+
'systype.h',
|
95
|
+
'tads.h',
|
96
|
+
'tadsgen.h',
|
97
|
+
'tadsio.h',
|
98
|
+
't3.h',
|
99
|
+
'vector.h',
|
100
|
+
'file.h',
|
101
|
+
't3test.h',
|
102
|
+
'strcomp.h',
|
103
|
+
]
|
104
|
+
|
105
|
+
|
106
|
+
attr_reader :map
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
include TADSUnquote
|
111
|
+
|
112
|
+
class TADSRoom < MapRoom
|
113
|
+
include TADSUnquote
|
114
|
+
end
|
115
|
+
|
116
|
+
class TADSObject < MapObject
|
117
|
+
include TADSUnquote
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
def new_room
|
122
|
+
super(TADSRoom)
|
123
|
+
end
|
124
|
+
|
125
|
+
def new_obj(loc = nil)
|
126
|
+
super(loc, TADSObject)
|
127
|
+
end
|
128
|
+
|
129
|
+
#
|
130
|
+
# Main parsing loop. We basically parse the file twice to
|
131
|
+
# solve dependencies. Yes, this is inefficient, but the alternative
|
132
|
+
# was to build a full parser that understands forward dependencies.
|
133
|
+
#
|
134
|
+
def parse(file)
|
135
|
+
# We start map at 0, 0
|
136
|
+
@x, @y = [0, 0]
|
137
|
+
@room = nil
|
138
|
+
|
139
|
+
if @map.kind_of?(FXMap)
|
140
|
+
@map.options['Edit on Creation'] = false
|
141
|
+
@map.window.hide
|
142
|
+
end
|
143
|
+
@map.section = 0
|
144
|
+
|
145
|
+
@in_desc = false
|
146
|
+
@parsing = nil
|
147
|
+
@last_section = 0
|
148
|
+
@ignore_first_section = true
|
149
|
+
@room_idx = 0
|
150
|
+
@gameid = nil
|
151
|
+
@obj = nil
|
152
|
+
line_number = 0
|
153
|
+
|
154
|
+
debug "...Parse... #{file.path}"
|
155
|
+
while not file.eof?
|
156
|
+
@line = ''
|
157
|
+
while not file.eof? and @line == ''
|
158
|
+
@line << file.readline()
|
159
|
+
@line.sub!( /^\s*\/\/.*$/, '')
|
160
|
+
line_number += 1
|
161
|
+
end
|
162
|
+
# todo: Remove multi-line comments
|
163
|
+
# Remove comments at end of line
|
164
|
+
@line.sub!( /\s+\/\/[^"]*$/, '')
|
165
|
+
# Remove starting spaces (if any)
|
166
|
+
@line.sub! /^\s+/, ''
|
167
|
+
# Replace \n with simple space
|
168
|
+
@line.gsub! /\n/, ' '
|
169
|
+
next if @line == ''
|
170
|
+
full_line = @line.dup
|
171
|
+
begin
|
172
|
+
parse_line
|
173
|
+
rescue ParseError, MapError => e
|
174
|
+
message = "#{e}.\nat #{file.path}, line #{line_number}:\n>>>> #{full_line};\n"
|
175
|
+
raise message
|
176
|
+
rescue => e
|
177
|
+
message = "#{e}\n#{e.backtrace}"
|
178
|
+
raise message
|
179
|
+
end
|
180
|
+
end
|
181
|
+
debug "...End Parse..."
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
def find_file(file)
|
187
|
+
return file if File.exists?(file)
|
188
|
+
@include_dirs.each { |d|
|
189
|
+
[ "#{d}/#{file}",
|
190
|
+
"#{d}/#{file}.h",
|
191
|
+
"#{d}/#{file}.inf", ].each { |full|
|
192
|
+
return full if File.exists?(full)
|
193
|
+
}
|
194
|
+
}
|
195
|
+
return nil
|
196
|
+
end
|
197
|
+
|
198
|
+
def get_parent_classes(clist)
|
199
|
+
ret = []
|
200
|
+
clist.each { |c|
|
201
|
+
c.strip!
|
202
|
+
if @classes[c]
|
203
|
+
ret += get_parent_classes(@classes[c])
|
204
|
+
else
|
205
|
+
ret << c
|
206
|
+
end
|
207
|
+
}
|
208
|
+
return ret
|
209
|
+
end
|
210
|
+
|
211
|
+
#
|
212
|
+
# Parse a line of file
|
213
|
+
#
|
214
|
+
def parse_line
|
215
|
+
if @line =~ INCLUDE
|
216
|
+
name = $1
|
217
|
+
unless STD_LIB.include?(name)
|
218
|
+
file = find_file(name)
|
219
|
+
if file
|
220
|
+
File.open(file, 'r') { |f| parse(f) }
|
221
|
+
else
|
222
|
+
raise ParseError, "Include file '#{name}' not found"
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
if @line =~ CLASS
|
228
|
+
@clas = $1
|
229
|
+
inherits = $2
|
230
|
+
debug "CLASS: #@clas : #{inherits}"
|
231
|
+
@classes[@clas] = inherits.split(/\s*,\s*/)
|
232
|
+
@tag = @name = nil
|
233
|
+
return
|
234
|
+
end
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
#
|
239
|
+
# Handle room description
|
240
|
+
#
|
241
|
+
if @in_desc == 1 then
|
242
|
+
if @line =~ /^\s*"#{DQ}("\s*)?$/
|
243
|
+
# check for possible start description
|
244
|
+
@room.desc << $1
|
245
|
+
if $2
|
246
|
+
@in_desc = nil
|
247
|
+
else
|
248
|
+
@in_desc = 2
|
249
|
+
end
|
250
|
+
return
|
251
|
+
elsif @room.name == @room.tag and @line =~ /^\s*#{NOMS}#{NAME}\s*/
|
252
|
+
name = $1 || $2
|
253
|
+
@room.name = name
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
if @in_desc == 2
|
258
|
+
@line =~ /\s*#{DQ}?("\s*)?/
|
259
|
+
@room.desc << $1 if @room and $1
|
260
|
+
@in_desc = nil if $2
|
261
|
+
return
|
262
|
+
end
|
263
|
+
|
264
|
+
if @gameid and @line =~ /name\s*=\s*'(#{SQ})'/
|
265
|
+
@map.name = $1
|
266
|
+
end
|
267
|
+
|
268
|
+
# TADS3 definition is like:
|
269
|
+
# [+] [TAG:] Classes ['adjective nouns'] 'Name' @location
|
270
|
+
re = /^#{PLUS}#{TAG}#{CLS}#{NOMS}#{NAME}#{LOC}/
|
271
|
+
if @line =~ re
|
272
|
+
|
273
|
+
|
274
|
+
prev = $1
|
275
|
+
@name = [$5, $4]
|
276
|
+
@tag = $2
|
277
|
+
@clas = $3 # can be several classes
|
278
|
+
@in_desc = false
|
279
|
+
|
280
|
+
if @tag
|
281
|
+
if @clas == "GameID"
|
282
|
+
@gameid = true
|
283
|
+
else
|
284
|
+
@gameid = false
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
loc = $6
|
289
|
+
if prev and @room
|
290
|
+
loc = @room.tag
|
291
|
+
end
|
292
|
+
|
293
|
+
## For user classes, flatten inheritance
|
294
|
+
clist = @clas.split(/(?:\s*,\s*|\s)/)
|
295
|
+
flist = get_parent_classes(clist)
|
296
|
+
@clas = flist.join(' ')
|
297
|
+
|
298
|
+
if @clas =~ /\b(Outdoor|Dark)?Room\b/
|
299
|
+
@obj = nil
|
300
|
+
@name = @name[1] || @name[0] || @tag
|
301
|
+
debug "+++ ROOM #@name TAG: #@tag"
|
302
|
+
@tag = @name if not @tag
|
303
|
+
@desc = ''
|
304
|
+
new_room
|
305
|
+
@room.light = false if $1 == 'Dark'
|
306
|
+
@in_desc = 1
|
307
|
+
elsif @clas =~ /\bFakeConnector\b/
|
308
|
+
@functions << @tag
|
309
|
+
elsif @clas =~ /\bRoomConnector\b/
|
310
|
+
debug "+++ CONNECTOR TAG: #@tag"
|
311
|
+
@desc = ''
|
312
|
+
new_door(loc)
|
313
|
+
@obj.connector = true
|
314
|
+
elsif @clas =~ /\b(?:(?:Hidden|Secret)?Door|ThroughPassage|PathPassage|TravelWithMessage|Stairway(?:Up|Down))\b/
|
315
|
+
@desc = ''
|
316
|
+
@name = @name[0] || @name[1]
|
317
|
+
@tag = @name if not @tag
|
318
|
+
debug "+++ DOOR #@tag"
|
319
|
+
if @clas =~ /\s+->\s*(\w+)/
|
320
|
+
# this is the other side of the door... find matching side
|
321
|
+
@obj = @tags[$1]
|
322
|
+
if not @obj
|
323
|
+
new_door(loc)
|
324
|
+
@tags[$1] = @obj
|
325
|
+
else
|
326
|
+
@tags[@tag] = @obj
|
327
|
+
@obj.location << loc if loc
|
328
|
+
end
|
329
|
+
else
|
330
|
+
new_door(loc) if @tag
|
331
|
+
@obj.locked = true if @clas =~ /\bLockable(WithKey)?\b/
|
332
|
+
end
|
333
|
+
@obj.connector = true if @clas !~ /\b(?:Hidden|Secret)?Door\b/
|
334
|
+
elsif @clas =~ /\b(?:Thing|Food|Person)\b/
|
335
|
+
@obj = nil
|
336
|
+
@desc = ''
|
337
|
+
@name = @name[0] || @name[1]
|
338
|
+
@name = '' if @name =~ /\//
|
339
|
+
@tag = @name if not @tag
|
340
|
+
new_obj(loc) if @tag
|
341
|
+
elsif @clas =~ /\bEnterable\b/ and @tag
|
342
|
+
@desc = ''
|
343
|
+
@name = @name[0] || @name[1]
|
344
|
+
@name = '' if @name =~ /\//
|
345
|
+
@tag = @name if not @tag
|
346
|
+
new_obj(loc)
|
347
|
+
if @clas =~ /\s+->\s*(\w+)/
|
348
|
+
@obj.enterable << $1
|
349
|
+
end
|
350
|
+
else
|
351
|
+
if @tag
|
352
|
+
@obj = nil
|
353
|
+
end
|
354
|
+
@name = (@name[0] || @name[1] || @tag)
|
355
|
+
end
|
356
|
+
|
357
|
+
# debug <<"EOF"
|
358
|
+
# Name: #@name
|
359
|
+
# Classes : #@clas
|
360
|
+
# Tag : #@tag
|
361
|
+
# Location: #{loc} #{loc.class}
|
362
|
+
# EOF
|
363
|
+
|
364
|
+
|
365
|
+
end
|
366
|
+
|
367
|
+
if @obj
|
368
|
+
if @obj.name == '' and @line =~ /^\s*#{NOMS}#{NAME}\s*$/
|
369
|
+
name = $2 || $1
|
370
|
+
@obj.name = name
|
371
|
+
end
|
372
|
+
@obj.name = $1 || $2 if @line =~ OBJNAME
|
373
|
+
if @line =~ OBJLOCATION
|
374
|
+
loc = $1 || $2 || $3
|
375
|
+
if loc
|
376
|
+
locs = loc.split(/\s*,\s*/)
|
377
|
+
@obj.location += locs
|
378
|
+
@obj.location.uniq!
|
379
|
+
end
|
380
|
+
end
|
381
|
+
@obj.location << loc if @obj.connector and @line =~ CONNECTOR
|
382
|
+
end
|
383
|
+
|
384
|
+
if @room and @line =~ ROOMNAME
|
385
|
+
@room.name = $1
|
386
|
+
return
|
387
|
+
end
|
388
|
+
|
389
|
+
if @line =~ DESCRIPTION
|
390
|
+
@desc << $1 if @desc and $1
|
391
|
+
@in_desc = 2 if $2 == ''
|
392
|
+
end
|
393
|
+
|
394
|
+
# dirs = @line.scan(DIR_TO) + @line.scan(DIR) + @line.scan(DIR_MSG)
|
395
|
+
if @room
|
396
|
+
dirs = ( @line.scan(DIR) + @line.scan(DIR_MSG) +
|
397
|
+
@line.scan(DIR_OPEN) + @line.scan(DIR_INSELF) +
|
398
|
+
@line.scan(ENTER_DIR) )
|
399
|
+
if dirs.size > 0
|
400
|
+
dirs.each { |d, room|
|
401
|
+
next if not room or room == 'nil' or room =~ /^noTravel/
|
402
|
+
dir = DIRECTIONS[d]
|
403
|
+
@room.exits[dir] = room
|
404
|
+
}
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
end
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
def parse_makefile(file)
|
414
|
+
dir = File.dirname(file)
|
415
|
+
files = []
|
416
|
+
File.foreach(file) { |line|
|
417
|
+
if line =~ /-source\s*([^\s]+)/
|
418
|
+
f = $1
|
419
|
+
if f !~ /^(?:[A-Z]:|\/)/
|
420
|
+
f = dir + '/' + f
|
421
|
+
end
|
422
|
+
files << "#{f}.t"
|
423
|
+
end
|
424
|
+
}
|
425
|
+
|
426
|
+
return files
|
427
|
+
end
|
428
|
+
|
429
|
+
def set_include_dirs
|
430
|
+
# Try to find t3make(.exe) in path.
|
431
|
+
paths = ENV['PATH'].split(SEP)
|
432
|
+
paths.each { |p|
|
433
|
+
next if not File.directory?(p)
|
434
|
+
Dir.foreach(p) { |x|
|
435
|
+
if x =~ /^t3make(.exe)?$/i
|
436
|
+
@include_dirs << p
|
437
|
+
@include_dirs << p + "/include"
|
438
|
+
@include_dirs << p + "/lib"
|
439
|
+
@include_dirs << p + "/contrib"
|
440
|
+
break
|
441
|
+
end
|
442
|
+
}
|
443
|
+
}
|
444
|
+
end
|
445
|
+
|
446
|
+
def read_file(file)
|
447
|
+
if file =~ /.t3m/
|
448
|
+
files = parse_makefile(file)
|
449
|
+
else
|
450
|
+
files = file
|
451
|
+
end
|
452
|
+
|
453
|
+
files.each_with_index { |file, idx|
|
454
|
+
super(file)
|
455
|
+
}
|
456
|
+
end
|
457
|
+
|
458
|
+
def initialize(file, map = Map.new('TADS Map'))
|
459
|
+
debug "Initialize"
|
460
|
+
@classes = { 'Object' => {} }
|
461
|
+
super
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
|
466
|
+
if $0 == __FILE__
|
467
|
+
p "Opening file '#{ARGV[0]}'"
|
468
|
+
BEGIN {
|
469
|
+
$LOAD_PATH << 'C:\Windows\Escritorio\IFMapper\lib'
|
470
|
+
}
|
471
|
+
|
472
|
+
require "IFMapper/Map"
|
473
|
+
TADSReader.new(ARGV[0])
|
474
|
+
end
|