7
7
8
8
from ev_argtype import EvArgType
9
9
from ev_macro import EvMacroType
10
- from msbt import ForceGrmID , GroupTagID , LabelData , MsgEventID , StyleInfo , TagData , TagPatternID , WordData , WordDataPatternID
10
+ import msbt
11
11
if __name__ is not None and "." in __name__ :
12
12
from .evParser import evParser
13
13
else :
23
23
MAX_FLAG = 4000
24
24
MAX_SYS_FLAG = 1000
25
25
26
+ MACRO_NAME_CMD_TABLE = {
27
+ EvCmdType ._POKE_TYPE_NAME : msbt .TagID .PokeType ,
28
+ EvCmdType ._NUMBER_NAME : msbt .TagID .Number
29
+ }
30
+
26
31
@dataclass
27
32
class EvArg :
28
33
argType : int
@@ -156,11 +161,10 @@ def parseText(self, origText):
156
161
if origText .endswith ('\\ r' ):
157
162
origText = origText [:- 2 ]
158
163
text = origText
159
- splitters = ['\\ n' , '\\ r' , '\\ f' , '% ' ]
164
+ splitters = ['\\ n' , '\\ r' , '\\ f' , '{' , '} ' ]
160
165
items = {}
161
166
indicators = {}
162
167
lastIndex = 0
163
- tagOpen = False
164
168
while True :
165
169
indices = {}
166
170
for splitter in splitters :
@@ -177,13 +181,10 @@ def parseText(self, origText):
177
181
indicator = Indicator .NewLine
178
182
if splitter == '\\ f' :
179
183
indicator = Indicator .ScrollLine
180
- if splitter == '%' :
181
- if tagOpen :
182
- indicator = Indicator .TagEnd
183
- tagOpen = False
184
- else :
185
- indicator = Indicator .TagStart
186
- tagOpen = True
184
+ if splitter == '}' :
185
+ indicator = Indicator .TagEnd
186
+ if splitter == '{' :
187
+ indicator = Indicator .TagStart
187
188
indicators [text .index (splitter )+ lastIndex ] = indicator
188
189
items [text .index (splitter )+ lastIndex ] = text [:text .index (splitter )]
189
190
lastIndex = text .index (splitter )+ lastIndex
@@ -202,7 +203,7 @@ def parseText(self, origText):
202
203
"indicators" : indicators
203
204
}
204
205
205
- def genLabelData (self , labelName , text ):
206
+ def genLabelData (self , labelName , text , tags ):
206
207
TAG_COMMANDS = {
207
208
"PLAYER" ,
208
209
"RIVAL" ,
@@ -224,8 +225,8 @@ def genLabelData(self, labelName, text):
224
225
# ACCE_NAME
225
226
# IMC_BG_NAME
226
227
}
227
- styleInfo = StyleInfo .default ()
228
- attributeValueArray = LabelData .defaultAttributeValueArray ()
228
+ styleInfo = msbt . StyleInfo .default ()
229
+ attributeValueArray = msbt . LabelData .defaultAttributeValueArray ()
229
230
tagDataArray = []
230
231
wordDataArray = []
231
232
@@ -236,36 +237,36 @@ def genLabelData(self, labelName, text):
236
237
item : str = items [pos ]
237
238
indicator = indicators [pos ]
238
239
if indicator == Indicator .NewLine :
239
- wordDataArray .append (WordData (
240
- WordDataPatternID .Event ,
241
- MsgEventID .NewLine ,
240
+ wordDataArray .append (msbt . WordData (
241
+ msbt . WordDataPatternID .Event ,
242
+ msbt . MsgEventID .NewLine ,
242
243
- 1 ,
243
244
0.0 ,
244
245
item ,
245
246
calculateStrWidth (item )
246
247
))
247
248
if indicator == Indicator .ScrollLine :
248
- wordDataArray .append (WordData (
249
- WordDataPatternID .Event ,
250
- MsgEventID .ScrollLine ,
249
+ wordDataArray .append (msbt . WordData (
250
+ msbt . WordDataPatternID .Event ,
251
+ msbt . MsgEventID .ScrollLine ,
251
252
- 1 ,
252
253
0.0 ,
253
254
item ,
254
255
calculateStrWidth (item )
255
256
))
256
257
if indicator == Indicator .ScrollPage :
257
- wordDataArray .append (WordData (
258
- WordDataPatternID .Event ,
259
- MsgEventID .ScrollPage ,
258
+ wordDataArray .append (msbt . WordData (
259
+ msbt . WordDataPatternID .Event ,
260
+ msbt . MsgEventID .ScrollPage ,
260
261
- 1 ,
261
262
0.0 ,
262
263
item ,
263
264
calculateStrWidth (item )
264
265
))
265
266
if indicator == Indicator .TagStart :
266
- wordDataArray .append (WordData (
267
- WordDataPatternID .Str ,
268
- MsgEventID .NONE ,
267
+ wordDataArray .append (msbt . WordData (
268
+ msbt . WordDataPatternID .Str ,
269
+ msbt . MsgEventID .NONE ,
269
270
- 1 ,
270
271
0.0 ,
271
272
item ,
@@ -280,35 +281,38 @@ def genLabelData(self, labelName, text):
280
281
# This tag index seems to be the index into the
281
282
# tagData array whereas the other tagIndex is the
282
283
#
283
- wordDataArray .append (WordData (
284
- WordDataPatternID .WordTag ,
285
- MsgEventID .NONE ,
284
+ wordDataArray .append (msbt . WordData (
285
+ msbt . WordDataPatternID .WordTag ,
286
+ msbt . MsgEventID .NONE ,
286
287
len (tagDataArray ),
287
288
0.0 ,
288
289
"" ,
289
290
- 1.0
290
291
))
291
- tagDataArray .append (TagData (
292
+ tagID = msbt .TagID .Default
293
+ if tagIndex in tags :
294
+ tagID = tags [tagIndex ]
295
+ tagDataArray .append (msbt .TagData (
292
296
tagIndex ,
293
- GroupTagID .Name ,
294
- tagIndex , #?
295
- TagPatternID .Word ,
297
+ msbt . GroupTagID .Name ,
298
+ tagID ,
299
+ msbt . TagPatternID .Word ,
296
300
0 ,
297
301
0 ,
298
302
[],
299
- ForceGrmID .NONE
303
+ msbt . ForceGrmID .NONE
300
304
))
301
305
if indicator == Indicator .End :
302
- wordDataArray .append (WordData (
303
- WordDataPatternID .Str ,
304
- MsgEventID .End ,
306
+ wordDataArray .append (msbt . WordData (
307
+ msbt . WordDataPatternID .Str ,
308
+ msbt . MsgEventID .End ,
305
309
- 1 ,
306
310
0.0 ,
307
311
item ,
308
312
calculateStrWidth (item )
309
313
))
310
314
311
- return LabelData (
315
+ return msbt . LabelData (
312
316
0 ,
313
317
0 ,
314
318
labelName .data ,
@@ -318,7 +322,7 @@ def genLabelData(self, labelName, text):
318
322
wordDataArray
319
323
)
320
324
321
- def processTextMacro (self , cmdType , macro , commands , strTbl ):
325
+ def processTextMacro (self , cmdType , macro , commands , strTbl , tags ):
322
326
# TODO: Add a list of valid msg files
323
327
try :
324
328
msgFile : EvArg = macro .args [0 ]
@@ -347,7 +351,7 @@ def processTextMacro(self, cmdType, macro, commands, strTbl):
347
351
# if strVal in self.msg_keys:
348
352
# raise RuntimeError("EvMacro: {}. Label `{}` is already used at {}:{}:{}".format(macro.cmdType.name, strVal, self.fileName, text.line, text.column))
349
353
macroCommands = []
350
- labelData = self .genLabelData (label , text )
354
+ labelData = self .genLabelData (label , text , tags )
351
355
352
356
if strVal not in strTbl :
353
357
strTbl .append (strVal )
@@ -363,7 +367,7 @@ def processTextMacro(self, cmdType, macro, commands, strTbl):
363
367
commands .extend (macroCommands )
364
368
return len (macroCommands )
365
369
366
- def process (self , macro , commands , strTbl ):
370
+ def process (self , macro , commands , strTbl , tags ):
367
371
if macro .cmdType == EvMacroType .Invalid :
368
372
raise RuntimeError ("Invalid EvCmd or EvMacro: {} at {}:{}:{}" .format (macro , self .fileName , macro .line , macro .column ))
369
373
textMacroMap = {
@@ -375,7 +379,7 @@ def process(self, macro, commands, strTbl):
375
379
376
380
if macro .cmdType in textMacroMap :
377
381
evCmdType = textMacroMap [macro .cmdType ]
378
- return self .processTextMacro (evCmdType , macro , commands , strTbl )
382
+ return self .processTextMacro (evCmdType , macro , commands , strTbl , tags )
379
383
380
384
raise RuntimeError ("Invalid EvMacro: {} at {}:{}:{}" .format (macro , self .fileName , macro .line , macro .column ))
381
385
@@ -389,6 +393,7 @@ def __init__(self, fileName):
389
393
self .strTbl = []
390
394
self .currCmdIdx = - 1
391
395
self .writer = EndianBinaryWriter ()
396
+ self .tags = {}
392
397
393
398
def enterLbl (self , ctx : evParser .LblContext ):
394
399
lbl = ctx .getChild (0 ).getChild (0 )
@@ -401,12 +406,13 @@ def enterLbl(self, ctx: evParser.LblContext):
401
406
self .currentLabel = lblName
402
407
self .scripts [self .currentLabel ] = []
403
408
self .currCmdIdx = - 1
409
+ self .tags = {}
404
410
405
411
# Enter a parse tree produced by evParser#instruction.
406
412
def enterInstruction (self , ctx :evParser .InstructionContext ):
407
413
name = str (ctx .getChild (0 ).getChild (0 ))
408
414
if self .macro .isValid ():
409
- self .currCmdIdx += self .macroAssembler .process (self .macro , self .scripts [self .currentLabel ], self .strTbl )
415
+ self .currCmdIdx += self .macroAssembler .process (self .macro , self .scripts [self .currentLabel ], self .strTbl , self . tags )
410
416
self .macro = EvMacro (EvMacroType .Invalid , [], ctx .start .line , ctx .start .column )
411
417
412
418
if hasattr (EvMacroType , name ):
@@ -435,7 +441,11 @@ def enterNumber(self, ctx: evParser.NumberContext):
435
441
EvArg (EvArgType .Value , argVal , ctx .start .line , ctx .start .column )
436
442
)
437
443
else :
438
- self .scripts [self .currentLabel ][self .currCmdIdx ].args .append (
444
+ evCmd = self .scripts [self .currentLabel ][self .currCmdIdx ]
445
+ if evCmd .cmdType in MACRO_NAME_CMD_TABLE :
446
+ tagIndex = argVal
447
+ self .tags [tagIndex ] = MACRO_NAME_CMD_TABLE [evCmd .cmdType ]
448
+ evCmd .args .append (
439
449
EvArg (EvArgType .Value , argVal , ctx .start .line , ctx .start .column )
440
450
)
441
451
0 commit comments