2
2
# -*- coding: utf-8 -*-
3
3
4
4
import os
5
- import sys
6
5
import argparse
7
6
8
7
import sc2reader
9
8
from sc2reader import utils
10
9
from sc2reader .exceptions import ReadError
11
10
11
+
12
12
def printReplay (filepath , arguments ):
13
- ''' Prints summary information about SC2 replay file'''
13
+ """ Prints summary information about SC2 replay file """
14
14
try :
15
15
replay = sc2reader .load_replay (filepath , debug = True )
16
16
17
17
if arguments .map :
18
18
print " Map: {0}" .format (replay .map_name )
19
19
if arguments .length :
20
- print " Length: {0}" .format (replay .length )
20
+ print " Length: {0} minutes " .format (replay .game_length )
21
21
if arguments .date :
22
- print " Date: {0}" .format (replay .date )
22
+ print " Date: {0}" .format (replay .start_time )
23
23
if arguments .teams :
24
24
lineups = [team .lineup for team in replay .teams ]
25
25
print " Teams: {0}" .format ("v" .join (lineups ))
26
26
for team in replay .teams :
27
- print " Team {0}\t {1} ({2})" .format (team .number ,team .players [0 ].name ,team .players [0 ].pick_race [0 ])
27
+ print " Team {0}\t {1} ({2})" .format (team .number , team .players [0 ].name , team .players [0 ].pick_race [0 ])
28
28
for player in team .players [1 :]:
29
- print " \t {0} ({1})" .format (player .name ,player .pick_race [0 ])
29
+ print " \t {0} ({1})" .format (player .name , player .pick_race [0 ])
30
30
if arguments .messages :
31
31
print " Messages:"
32
32
for message in replay .messages :
@@ -44,7 +44,7 @@ def printReplay(filepath, arguments):
44
44
print "\t Previous Event: {0}" .format (prev .name )
45
45
print "\t \t " + prev .bytes .encode ('hex' )
46
46
print "\t Following Bytes:"
47
- print "\t \t " + e .buffer .read_range (e .location ,e .location + 30 ).encode ('hex' )
47
+ print "\t \t " + e .buffer .read_range (e .location , e .location + 30 ).encode ('hex' )
48
48
print "Error with '{0}': " .format (filepath )
49
49
print e
50
50
except TypeError as e :
@@ -56,38 +56,61 @@ def printReplay(filepath, arguments):
56
56
print e
57
57
58
58
59
-
60
59
def printGameSummary (filepath , arguments ):
61
60
summary = sc2reader .load_game_summary (filepath )
62
- print "{0} minute {1} game played on {2}" .format (summary .game_length , summary .real_type , summary .map_name )
63
- for p in summary .players :
64
- print ("== {0} - {1}/{2} ==" .format (p .play_race , p .region , p .bnetid if not p .is_ai else "AI" ))
65
- for order in summary .build_orders [p .pid ]:
66
- print (" {0:0>2}:{1:0>2} {2:<35} {3:0>2}/{4}" .format (order .time / 60 ,
67
- order .time % 60 ,
68
- order .order ,
69
- order .supply ,
70
- order .total_supply ))
61
+
62
+ if arguments .map :
63
+ print " Map: {0}" .format (summary .map_name )
64
+ if arguments .length :
65
+ print " Length: {0} minutes" .format (summary .game_length )
66
+ if arguments .date :
67
+ print " Date: {0}" .format (summary .start_time )
68
+ if arguments .teams :
69
+ lineups = [team .lineup for team in summary .teams ]
70
+ print " Teams: {0}" .format ("v" .join (lineups ))
71
+ for team in summary .teams :
72
+ print " Team {0}\t {1}" .format (team .number , team .players [0 ])
73
+ for player in team .players [1 :]:
74
+ print " \t {0}" .format (player )
75
+ if arguments .builds :
76
+ for player in summary .players :
77
+ print ("\n == {0} ==\n " .format (player ))
78
+ for order in summary .build_orders [player .pid ]:
79
+ msg = " {0:0>2}:{1:0>2} {2:<35} {3:0>2}/{4}"
80
+ print (msg .format (order .time / 60 , order .time % 60 , order .order , order .supply , order .total_supply ))
71
81
print
72
82
83
+
73
84
def main ():
74
- parser = argparse .ArgumentParser (description = 'Prints basic information from SC2 replay files or directories.' )
75
- parser .add_argument ('paths' , metavar = 'filename' , type = str , nargs = '+' ,
76
- help = "Paths to one or more SC2Replay files or directories" )
77
- parser .add_argument ('--date' , action = "store_true" , default = True ,
78
- help = "Print game date" )
79
- parser .add_argument ('--length' , action = "store_true" , default = False ,
80
- help = "Print game duration mm:ss in game time (not real time)" )
81
- parser .add_argument ('--map' , action = "store_true" , default = True ,
82
- help = "Print map name" )
83
- parser .add_argument ('--messages' , action = "store_true" , default = False ,
84
- help = "Print in-game player chat messages" )
85
- parser .add_argument ('--teams' , action = "store_true" , default = True ,
86
- help = "Print teams, their players, and the race matchup" )
87
- parser .add_argument ('--version' , action = "store_true" , default = True ,
88
- help = "Print the release string as seen in game" )
85
+ parser = argparse .ArgumentParser (
86
+ description = """Prints basic information from Starcraft II replay and
87
+ game summary files or directories.""" )
89
88
parser .add_argument ('--recursive' , action = "store_true" , default = True ,
90
- help = "Recursively read through directories of replays" )
89
+ help = "Recursively read through directories of Starcraft II files [default on]" )
90
+
91
+ required = parser .add_argument_group ('Required Arguments' )
92
+ required .add_argument ('paths' , metavar = 'filename' , type = str , nargs = '+' ,
93
+ help = "Paths to one or more Starcraft II files or directories" )
94
+
95
+ shared_args = parser .add_argument_group ('Shared Arguments' )
96
+ shared_args .add_argument ('--date' , action = "store_true" , default = True ,
97
+ help = "Print game date [default on]" )
98
+ shared_args .add_argument ('--length' , action = "store_true" , default = False ,
99
+ help = "Print game duration mm:ss in game time (not real time) [default off]" )
100
+ shared_args .add_argument ('--map' , action = "store_true" , default = True ,
101
+ help = "Print map name [default on]" )
102
+ shared_args .add_argument ('--teams' , action = "store_true" , default = True ,
103
+ help = "Print teams, their players, and the race matchup [default on]" )
104
+
105
+ replay_args = parser .add_argument_group ('Replay Options' )
106
+ replay_args .add_argument ('--messages' , action = "store_true" , default = False ,
107
+ help = "Print in-game player chat messages [default off]" )
108
+ replay_args .add_argument ('--version' , action = "store_true" , default = True ,
109
+ help = "Print the release string as seen in game [default on]" )
110
+
111
+ s2gs_args = parser .add_argument_group ('Game Summary Options' )
112
+ s2gs_args .add_argument ('--builds' , action = "store_true" , default = False ,
113
+ help = "Print player build orders (first 64 items) [default off]" )
91
114
92
115
arguments = parser .parse_args ()
93
116
for path in arguments .paths :
0 commit comments