Commits

Anonymous committed f4c5161

Lots of changes for KFest 2012

Comments (0)

Files changed (3)

     # Finish up.
     self.pieces.append(stmtsText[s:i])
   
+  def matchPieces(self, regex, flags = re.IGNORECASE):
+    return [p for p in self.pieces if re.match(regex, p.strip(), flags)]
+
   def isCall(self):
-    return [p for p in self.pieces if p.upper().startswith("CALL")]
+    return self.matchPieces("CALL")
   
   def isRem(self):
-    return [p for p in self.pieces if p.upper().startswith("REM")]
+    return self.matchPieces("REM")
+    
+  def isBlank(self):  
+    return not self.matchPieces(".")
+
+  def mustBeNumbered(self):
   
-  def isNoOp(self):
-    if [p for p in self.pieces if p.strip() != "" and not re.match("REM|NEW", p, re.I)]:
-      return False
+    # Blank lines never need numbers, and neither does "NEW"
+    if self.isBlank(): return False
+    if self.matchPieces("NEW"): return False
+    
+    # Anything besides REM needs a number
+    if [p for p in self.pieces if not re.match("^$|REM", p.strip(), re.I)]:
+      return True
+    
+    # Any lower-case or non-monitor chars? Don't treat as needing line preservation.
+    if self.matchPieces(".*[^A-Z0-9:\-+<.]", 0): return True
+      
     # This is a blank line or REM statement. Preserve numbers for REMs right
     # after a call in case they're Lammer data.
-    if self.prevIsCall and [p for p in self.pieces if p.strip() != ""]:
-      return False
-    return True
+    return not self.prevIsCall
     
   def __str__(self):
     return self.indent + str(self.lineNum) + "".join(self.pieces)
 def flushBlock(block, startLine, endLine, out):
   """ Auto-number a block of lines with the given start and end constraints. """
   
-  numLinesNeeded = len([l for l in block if l.lineNum or not l.isNoOp()])
+  numLinesNeeded = len([l for l in block if l.mustBeNumbered()])
   if numLinesNeeded == 0:
     out.extend(block)
     return
     #print "  Number line '%s': %d" % (str(line.lineNum) + " " + "".join(line.pieces), cur)
     if line.lineNum:
       cur = line.lineNum + incr
-    elif not line.isNoOp():
+    elif line.mustBeNumbered():
       
       assert cur != endLine
       assert cur not in allLines
       allLines.add(cur)
       line.lineNum = cur
+
+      # If necessary, add a space between line num and statement(s)
+      if line.pieces[0].strip() != "":
+        line.pieces.insert(0, " ");
+    
       cur += incr
       
     # Translate "+123" marks to real line numbers
                   re.sub("\+\d+", lambda m: undoLineMark(line.lineNum, m.group(0)), m.group(3))
       newPieces.append(piece)
       
-    # If necessary, add a space between line num and statement(s)
-    if newPieces[0].strip() != "":
-      newPieces.insert(0, " ");
-    
     # Moving on
     line.pieces = newPieces      
       
 def main():
 
   # Read in the file.
-  origLines = [line.rstrip() for line in open(sys.argv[1], "r")]
+  origLines = [re.sub("\n$", "", line) for line in open(sys.argv[1], "r")]
   
   # Parse each line
   lines = []
 7 REM JIEHHMFL@LHMBI@MHMDB@MHMEK@MHMEL@MHMEM@MHMEN@MHMEO@MJ@@@JIHIHECLJI@OHECMJIG@HECNJIA@HECOJIHJHEDBJI@OHEDCDLBLONMHAHJIDLHMOH@CJBA@JIACHMOI@CHNOJ@CKHJ@@AKAGIHELNLHKAGIHELOJB@@J@@DKALNLIKBM@E@LHKALNO@DKLIB@O@OGKALNO@FDLICKO@F@@IH@N@@@M@P
 8 REM @FLIKJO@DKHFMGLIJJM@DEHEMGN@@@M@BJJEK@E@BHJ@@AKFD@IFNKJEMGO@@FIFFIIFFKIFFMHHA@NOJFANIJLHKALNJJLHKALNHELOHFLNKALNM@JFF@JEJOBDKADHDJDJDJDJBI@O@HOHAHFII@FID@BH@IH@IM@@@BLHNHE@ILKHFHE@NIJIJ@IM@@@BNHJIIIIM@@@BKJHFANJENKHED@JENLHEDADLG@OO0
 9 REM #$$$$$$$$$$$$$$$$$$$$$$$$$$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.................................................................................................................................................................................
-10 GOSUB 3000
+10 GOSUB 3800
+15 GOSUB 3000
 20 LV = 1
 50 GOSUB 3100
 60 POKE KS,0
     3210 GOSUB 3250: RETURN
 
 3250 REM SUB GENERAL LEVEL BORDERS
-    3210 COLOR= 4: HLIN OX,39 - OX AT H * 2: HLIN OX,39 - OX AT H * 2 + 1
-    3215 COLOR= 5: FOR I = OX TO 38 - OX STEP 2: PLOT I,H * 2: PLOT I + 1,H * 2 + 1: NEXT
-    3220 RETURN
+    3260 COLOR= 4: HLIN OX,39 - OX AT H * 2: HLIN OX,39 - OX AT H * 2 + 1
+    3270 COLOR= 5: FOR I = OX TO 38 - OX STEP 2: PLOT I,H * 2: PLOT I + 1,H * 2 + 1: NEXT
+    3280 RETURN
 
 3300 REM SUB LEVEL UP!
     3310 RESTORE
     3320 FOR I = 1 TO LV: READ A$: NEXT
     3330 VTAB 24: HTAB 20 - LEN(A$) / 2: INVERSE : PRINT A$;: NORMAL
     3340 GOSUB 3600
+    3345 FOR I = 1 TO 1000: NEXT
     3350 LV = LV + 1: GOSUB 3100
     3352 IF LV = 11 THEN 3500
     3355 GOSUB 3250
     3710 IF M > 2 THEN RETURN
     3720 RD = RG - 1:RC = 2: GOTO 300
     3730 RETURN
+    
+3800 REM SUB HELP SCREEN
+    3805 HOME
+    3810 PRINT "WELCOME TO STRUCTRIS!"
+    3815 PRINT "BY MARTIN HAYE, INTRO'D KFEST 2010"
+    3820 PRINT: PRINT
+    3825 PRINT "(FANCY OPENING SCREEN GOES HERE)"
+    3830 PRINT: PRINT
+    3835 PRINT "KEYS:"
+    3840 PRINT "  I: UP"
+    3845 PRINT "  J: LEFT"
+    3850 PRINT "  K: RIGHT (ALTERNATE: L)"
+    3855 PRINT "  M: DOWN"
+    3860 PRINT
+    3865 PRINT "BUILD UP THE TETRIS BLOCKS. YOU CANNOT"
+    3870 PRINT "ROTATE THEM. EVIL PROGRAMMER LAUNCHES"
+    3875 PRINT "BLOCKS WHERE YOU ARE TO TRAP YOU. DON'T"
+    3880 PRINT "GET TRAPPED. FINISHED ROWS FALL AWAY."
+    3885 PRINT
+    3890 PRINT "CLEAR ENOUGH ROWS: NEXT LEVEL! HARDER!"
+    3895 PRINT: PRINT
+    3900 PRINT "HIT A KEY TO BEGIN THE TORTURE."
+    3910 CALL -756
+    3920 RETURN

Structris.dsk

Binary file modified.