-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameAutomateConfig.py
106 lines (86 loc) · 3.16 KB
/
GameAutomateConfig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
class GameAutomateConfig:
@classmethod
def loadConfig(cls, config):
# Check required keys exist. Create object if all exist.
requiredKeys = [
'GAME_PACKAGE',
'RUNNABLE_ACTITVITY',
'SCREENS',
'GAME_USER_FILES',
'COORDINATE_FILES',
'SCREEN_FILES',
'SCRIPT_FILES',
'COORDINATES',
'APK_LOCATION',
'SCRIPTS',
'GAME_PROJECT_PATH']
for k in requiredKeys:
if k not in config.keys():
return None
return cls(config)
def __init__(self, config):
self.GAME_PACKAGE = config['GAME_PACKAGE']
self.RUNNABLE_ACTITVITY = config['RUNNABLE_ACTITVITY']
self.SCREENS = config['SCREENS']
self.GAME_USER_FILES = config['GAME_USER_FILES']
self.COORDINATES = config['COORDINATES']
self.APK_LOCATION = config['APK_LOCATION']
self.SCRIPTS = config['SCRIPTS']
self.GAME_PROJECT_PATH = config['GAME_PROJECT_PATH']
self.SCRIPT_FILES = config['SCRIPT_FILES']
self.COORDINATE_FILES = config['COORDINATE_FILES']
self.SCREEN_FILES = config['SCREEN_FILES']
def addCoordinate(self, dictionary):
if dictionary.get('id', None) and dictionary.get('position', None):
self.COORDINATES.append(dictionary)
return True
return False
def addScreen(self, dictionary):
if dictionary.get('id', None) and dictionary.get('rect', None):
self.SCREENS.append(dictionary)
return True
return False
def addScriptAction(self, dictionary):
if dictionary.get('action', None):
self.SCRIPTS.append(dictionary)
return True
return False
def getGamePackage(self):
return self.GAME_PACKAGE
def getRunnableActivity(self):
return self.RUNNABLE_ACTITVITY
def getStartActivity(self):
return "%s/%s" % (self.GAME_PACKAGE, self.RUNNABLE_ACTITVITY)
def getScreenById(self, sid):
try:
return filter(lambda x: x.get('id', '') == sid, self.SCREENS)[0]
except:
return None
def getScriptFilesPath(self):
return self.SCRIPT_FILES
def getCoordinateFilesPath(self):
return self.COORDINATE_FILES
def getScreenFilesPath(self):
return self.SCREEN_FILES
def getUserFilesPath(self):
return self.GAME_USER_FILES
def getCoordinateById(self, cid):
try:
return filter(lambda x: x.get('id', '') == cid, self.COORDINATES)[0]
except:
return None
def getAPKLocation(self):
return self.APK_LOCATION
def getProjectPath(self):
return self.GAME_PROJECT_PATH
def getFileFullPath(self, name):
return "%s/%s" % (self.GAME_PROJECT_PATH, name)
def getScripts(self):
return self.SCRIPTS
def getScriptStepIndexByCheckpoint(self, name):
for idx, s in enumerate(self.SCRIPTS):
if (s.get('action', '') == 'checkpoint' and s.get('id', '') == name):
return idx
return None
def getScriptLength(self):
return len(self.SCRIPTS)