11#!/usr/bin/env python
22# -*- coding: utf-8 -*-
33
4- import sys , os , re
5- # import termios
6- # import fcntl
7-
4+ try :
5+ # Assume that we are on *nix or Mac
6+ import termios
7+ import fcntl
8+ import os
9+ import sys
10+
11+ def getch ():
12+ fd = sys .stdin .fileno ()
13+ oldterm = termios .tcgetattr (fd )
14+ newattr = termios .tcgetattr (fd )
15+ newattr [3 ] = newattr [3 ] & ~ termios .ICANON & ~ termios .ECHO
16+ termios .tcsetattr (fd , termios .TCSANOW , newattr )
17+ oldflags = fcntl .fcntl (fd , fcntl .F_GETFL )
18+ fcntl .fcntl (fd , fcntl .F_SETFL , oldflags | os .O_NONBLOCK )
19+ try :
20+ while 1 :
21+ try :
22+ sys .stdin .read (1 )
23+ break
24+ except IOError :
25+ pass
26+ finally :
27+ termios .tcsetattr (fd , termios .TCSAFLUSH , oldterm )
28+ fcntl .fcntl (fd , fcntl .F_SETFL , oldflags )
29+
30+ except ImportError as e :
31+ try :
32+ # Opps, we might be on windows, try this one
33+ from msvcrt import getch
34+ except ImportError as e :
35+ # We can't make getch happen, just dump events to the screen
36+ getch = lambda : True
37+
38+
39+ import argparse
840import sc2reader
941from sc2reader .events import *
1042
11- def myGetch ():
12- sys .stdin .read (1 )
13-
14- # fd = sys.stdin.fileno()
15- # oldterm = termios.tcgetattr(fd)
16- # newattr = termios.tcgetattr(fd)
17- # newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
18- # termios.tcsetattr(fd, termios.TCSANOW, newattr)
19- # oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
20- # fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
21- # try:
22- # while 1:
23- # try:
24- # c = sys.stdin.read(1)
25- # break
26- # except IOError: pass
27- # finally:
28- # termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
29- # fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
30-
31- def get_args ():
32- import argparse
3343
44+ def main ():
3445 parser = argparse .ArgumentParser (
3546 description = """Step by step replay of game events; shows only the
3647 Initialization, Ability, and Selection events by default. Press any
37- key to advance through the events in sequential order.""" ,
38- epilog = "And that's all folks" )
39-
40- parser .add_argument ('FILE' ,type = str ,
41- help = "The file you would like to replay" )
42- parser .add_argument ('--player' ,default = 0 , type = int ,
43- help = "The number of the player you would like to watch. Defaults to 0 (All)." )
44- parser .add_argument ('--bytes' ,default = False ,action = "store_true" ,
45- help = "Displays the byte code of the event in hex after each event." )
46- parser .add_argument ('--hotkeys' ,default = False ,action = "store_true" ,
47- help = "Shows the hotkey events in the event stream." )
48- parser .add_argument ('--cameras' ,default = False ,action = "store_true" ,
49- help = "Shows the camera events in the event stream." )
48+ key to advance through the events in sequential order."""
49+ )
5050
51- return parser .parse_args ()
51+ parser .add_argument ('FILE' , type = str , help = "The file you would like to replay" )
52+ parser .add_argument ('--player' , default = 0 , type = int , help = "The number of the player you would like to watch. Defaults to 0 (All)." )
53+ parser .add_argument ('--bytes' , default = False , action = "store_true" , help = "Displays the byte code of the event in hex after each event." )
54+ parser .add_argument ('--hotkeys' , default = False , action = "store_true" , help = "Shows the hotkey events in the event stream." )
55+ parser .add_argument ('--cameras' , default = False , action = "store_true" , help = "Shows the camera events in the event stream." )
56+ args = parser .parse_args ()
5257
53- def main ():
54- args = get_args ()
5558 for filename in sc2reader .utils .get_files (args .FILE ):
56- replay = sc2reader .load_replay (filename ,debug = True )
59+ replay = sc2reader .load_replay (filename , debug = True )
5760 print "Release {0}" .format (replay .release_string )
58- print "{0} on {1}" .format (replay .type ,replay .map )
59- for player in replay .players :
60- print player
61+ print "{0} on {1} at {2}" .format (replay .type , replay .map_name , replay .start_time )
62+ print
63+ for team in replay .teams :
64+ print team
65+ for player in team .players :
66+ print " {0}" .format (player )
6167 print "\n --------------------------\n \n "
6268
6369 # Allow picking of the player to 'watch'
@@ -66,39 +72,21 @@ def main():
6672 else :
6773 events = replay .events
6874
75+ # Allow specification of events to `show`
6976 # Loop through the events
70- #data = sc2reader.config.build_data[replay.build]
7177 for event in events :
72- try :
73- pass
74- #event.apply(data)
75- except ValueError as e :
76- if str (e ) == "Using invalid abilitiy matchup." :
77- myGetch ()
78- else :
79- raise e
80-
81- # Use their options to filter the event stream
8278
83- if isinstance (event ,AbilityEvent ) or \
84- isinstance (event ,SelectionEvent ) or \
85- isinstance (event ,PlayerJoinEvent ) or \
86- isinstance (event , PlayerLeaveEvent ) or \
87- isinstance (event ,GameStartEvent ) or \
88- (args .hotkeys and isinstance (event ,HotkeyEvent )) or \
89- (args .cameras and isinstance (event ,CameraEvent )):
90- '''
91- if isinstance(event, SelectionEvent) or isinstance(event, HotkeyEvent):
92- '''
79+ if isinstance (event , AbilityEvent ) or \
80+ isinstance (event , SelectionEvent ) or \
81+ isinstance (event , PlayerLeaveEvent ) or \
82+ isinstance (event , GameStartEvent ) or \
83+ (args .hotkeys and isinstance (event , HotkeyEvent )) or \
84+ (args .cameras and isinstance (event , CameraEvent )):
9385 print event
94- #myGetch ()
86+ getch ()
9587 if args .bytes :
9688 print "\t " + event .bytes .encode ('hex' )
9789
98- if re .search ('UNKNOWN|ERROR' , str (event )):
99- myGetch ()
100-
101-
10290
10391if __name__ == '__main__' :
10492 main ()
0 commit comments